From 1dee2ede32b1fcf47640cfc24e26e04e533146c0 Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Wed, 28 Oct 2020 11:52:26 +0100 Subject: Improve round trip loading of yaml files --- tests/test_collection.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'tests/test_collection.py') diff --git a/tests/test_collection.py b/tests/test_collection.py index f7ddf6d..bbc35ba 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -153,12 +153,6 @@ class testSimpleCollection(unittest.TestCase): self.collection.update_cache() self.assertIsNotNone(self.collection.stemmer) - def test_load_safe(self): - # Simply run the code with self.collection.safe = True to check - # that it doesn't break. - self.collection.safe = True - self.collection.update_cache() - def test_full_search(self): self.collection.start_search('Item') res = self.collection.get_all_search_results() @@ -321,6 +315,23 @@ class testComplexCollection(unittest.TestCase): for f in to_test: self.assertIsInstance(self.collection.fields[f[0]], f[1]) + def test_comments_are_preserved(self): + e = self.collection.entry_from_eid('5084bc6e94f24dc6976629282ef30419') + yaml_data = e.yaml_data + self.assertTrue( + yaml_data.startswith("# This entry has a comment at the beginning") + ) + self.assertTrue( + yaml_data.endswith("# and a comment at the end\n") + ) + + def test_data_is_stored_as_written_on_file(self): + e = self.collection.entry_from_eid('5084bc6e94f24dc6976629282ef30419') + fname = 'tests/data/complex/items/' + \ + '5084bc6e94f24dc6976629282ef30419.yaml' + with open(fname, 'r') as fp: + self.assertEqual(e.yaml_data, fp.read()) + class testCollectionWithErrors(unittest.TestCase): def setUp(self): -- cgit v1.2.3