Update tests for struct package

This commit is contained in:
Eric Torres
2019-04-10 18:17:21 -07:00
parent 35167f28c6
commit 94c70b7b2e
3 changed files with 119 additions and 105 deletions

View File

@@ -20,7 +20,36 @@ class TestHierarchyPaths(unittest.TestCase):
def test_returns_correct_path(self, p):
self.assertEqual(Path(p), Hierarchy(p).path)
@given(one_of(iterables(elements=none()), booleans()))
def test_raises_value_error(self, p):
with self.assertRaises(TypeError):
Hierarchy(p)
def test_raises_notimplemented_error(self):
h = Hierarchy("backup")
with self.assertRaises(NotImplementedError):
h.gen_metadata()
class TestHierarchyMetadata(unittest.TestCase):
def setUp(self):
self.patched_json = patch(f"{TESTING_MODULE}.json")
self.patched_path = patch.object(
Hierarchy, "metadata_path", new_callable=PropertyMock, spec_set=Path
)
self.mocked_path = self.patched_path.start()
self.mocked_json = self.patched_json.start()
@unittest.skip("Figure out how to mock file objects")
@given(text())
def test_write_metadata(self, data):
file_obj = StringIO()
self.mocked_path.return_value.open.return_value = file_obj
self.mocked_json.load.return_value = file_obj.getvalue()
h = Hierarchy("backup")
h.write_metadata(data)
read_data = h.read_metadata()
self.assertEqual(data, read_data)
def tearDown(self):
self.patched_json.stop()
self.patched_path.stop()