From 0e92b7334720f285528ea5719f72daccefbc2fda Mon Sep 17 00:00:00 2001 From: Andreas Eisenbarth Date: Wed, 12 Oct 2022 16:38:14 +0200 Subject: [PATCH] Add test case for dirs without h5ad --- tests/test_filecrawl.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/test_filecrawl.py b/tests/test_filecrawl.py index f5c88b7..c626a0c 100644 --- a/tests/test_filecrawl.py +++ b/tests/test_filecrawl.py @@ -1,4 +1,5 @@ import unittest +from collections import defaultdict from unittest.mock import MagicMock, patch from cellxgene_gateway.filecrawl import ( @@ -70,3 +71,18 @@ class TestRenderItemTree(unittest.TestCase): " | annotations: new" "", ) + + @patch("os.listdir", side_effect=lambda parent: defaultdict(list, {"tmp": ["foo"], "tmp/foo": ["bar"]})[parent]) + @patch("os.path.exists", return_value=True) + def test_GIVEN_dirs_without_h5ad_THEN_excludes_dirs_in_output(self, listdir, exists): + # Directories: + # - tmp + # - foo + # - bar (no h5ad files) + item_source = FileItemSource("tmp", name="local") + item_tree = item_source.list_items("foo") + rendered = render_item_tree(item_tree, item_source) + self.assertEqual( + rendered, + "
  • foo
  • ", + )