6ddcd4cf474c7a71fb3907a67cb3c1d79807f65d
[utils.git] / src / budget_sync / test / test_mock_path.py
1 from contextlib import contextmanager
2 import unittest
3 from budget_sync.test.mock_path import MockPath, MockFilesystem, DIR
4
5
6 @contextmanager
7 def make_filesystem_and_report_if_error(test_case: unittest.TestCase):
8 filesystem = MockFilesystem()
9 try:
10 yield filesystem
11 except Exception as e:
12 if isinstance(e, AssertionError):
13 raise
14 with test_case.subTest(filesystem=filesystem):
15 raise
16
17
18 class TestMockPath(unittest.TestCase):
19 # TODO: add more test cases
20
21 def test_mkdir(self):
22 with make_filesystem_and_report_if_error(self) as filesystem:
23 MockPath("/dir/", filesystem).mkdir()
24 self.assertEqual(filesystem.files,
25 {
26 "/": DIR,
27 "/dir": DIR,
28 })
29 # TODO: add more test cases
30
31
32 if __name__ == "__main__":
33 unittest.main()