working on adding tests for write_budget_markdown
[utils.git] / src / budget_sync / test / test_mock_path.py
diff --git a/src/budget_sync/test/test_mock_path.py b/src/budget_sync/test/test_mock_path.py
new file mode 100644 (file)
index 0000000..6ddcd4c
--- /dev/null
@@ -0,0 +1,33 @@
+from contextlib import contextmanager
+import unittest
+from budget_sync.test.mock_path import MockPath, MockFilesystem, DIR
+
+
+@contextmanager
+def make_filesystem_and_report_if_error(test_case: unittest.TestCase):
+    filesystem = MockFilesystem()
+    try:
+        yield filesystem
+    except Exception as e:
+        if isinstance(e, AssertionError):
+            raise
+        with test_case.subTest(filesystem=filesystem):
+            raise
+
+
+class TestMockPath(unittest.TestCase):
+    # TODO: add more test cases
+
+    def test_mkdir(self):
+        with make_filesystem_and_report_if_error(self) as filesystem:
+            MockPath("/dir/", filesystem).mkdir()
+            self.assertEqual(filesystem.files,
+                             {
+                                 "/": DIR,
+                                 "/dir": DIR,
+                             })
+        # TODO: add more test cases
+
+
+if __name__ == "__main__":
+    unittest.main()