diff options
author | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2022-08-04 17:11:32 +0200 |
---|---|---|
committer | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2022-08-04 17:11:32 +0200 |
commit | 0c86939154a29d14a2c6e44e472bed016ace4651 (patch) | |
tree | 9d11837d958a767eb8d57db8631744b86a8e9dc0 /tests | |
parent | 6bccaa958248dd80eab6bb4eeb31ddb51a4faf4a (diff) |
Stop using the deprecated ruamel.yaml.safe_load()
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_collection.py | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/tests/test_collection.py b/tests/test_collection.py index 4f9cd75..63f89d2 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -25,6 +25,7 @@ class testEntries(unittest.TestCase): self.collection = lesana.Collection(self.tmpdir.name) self.basepath = self.collection.itemdir self.filenames = [] + self.yaml = ruamel.yaml.YAML(typ='safe', pure=True) def tearDown(self): self.tmpdir.cleanup() @@ -32,13 +33,13 @@ class testEntries(unittest.TestCase): def test_simple(self): fname = '085682ed-6792-499d-a3ab-9aebd683c011.yaml' with open(os.path.join(self.basepath, fname)) as fp: - data = ruamel.yaml.safe_load(fp) + data = self.yaml.load(fp) entry = lesana.Entry(self.collection, data=data, fname=fname) self.assertEqual(entry.idterm, 'Q' + data['eid']) fname = '11189ee47ddf4796b718a483b379f976.yaml' eid = '11189ee47ddf4796b718a483b379f976' with open(os.path.join(self.basepath, fname)) as fp: - data = ruamel.yaml.safe_load(fp) + data = self.yaml.load(fp) entry = lesana.Entry(self.collection, data=data, fname=fname) self.assertEqual(entry.idterm, 'Q' + eid) self.assertEqual(entry.short_id, eid[:8]) @@ -57,7 +58,7 @@ class testEntries(unittest.TestCase): self.assertIn('# other (yaml):', text) self.assertNotIn('# position (string)', text) self.assertNotIn('# # other (yaml)', text) - written = ruamel.yaml.safe_load(text) + written = self.yaml.load(text) self.assertIsInstance(written['quantity'], int) self.assertIsInstance(written['name'], str) @@ -74,7 +75,7 @@ class testEntries(unittest.TestCase): def test_entry_creation_eid_but_no_filename(self): fname = '11189ee47ddf4796b718a483b379f976.yaml' with open(os.path.join(self.basepath, fname)) as fp: - data = ruamel.yaml.safe_load(fp) + data = self.yaml.load(fp) data['eid'] = '11189ee47ddf4796b718a483b379f976' entry = lesana.Entry(self.collection, data=data) self.assertEqual(entry.fname, fname) @@ -82,7 +83,7 @@ class testEntries(unittest.TestCase): def test_entry_creation_no_eid_no_filename(self): fname = '11189ee47ddf4796b718a483b379f976.yaml' with open(os.path.join(self.basepath, fname)) as fp: - data = ruamel.yaml.safe_load(fp) + data = self.yaml.load(fp) entry = lesana.Entry(self.collection, data=data) self.assertIsNotNone(entry.eid) self.assertIsNotNone(entry.fname) @@ -91,14 +92,14 @@ class testEntries(unittest.TestCase): fname = '11189ee47ddf4796b718a483b379f976.yaml' eid = '11189ee47ddf4796b718a483b379f976' with open(os.path.join(self.basepath, fname)) as fp: - data = ruamel.yaml.safe_load(fp) + data = self.yaml.load(fp) entry = lesana.Entry(self.collection, data=data, fname=fname) self.assertEqual(entry.eid, eid) def test_entry_str_filename_and_eid(self): fname = '11189ee47ddf4796b718a483b379f976.yaml' with open(os.path.join(self.basepath, fname)) as fp: - data = ruamel.yaml.safe_load(fp) + data = self.yaml.load(fp) data['eid'] = '11189ee47ddf4796b718a483b379f976' entry = lesana.Entry(self.collection, data=data) self.assertEqual(str(entry), data['eid']) @@ -108,7 +109,7 @@ class testEntries(unittest.TestCase): def test_entry_str_filename_no_eid(self): fname = '11189ee47ddf4796b718a483b379f976.yaml' with open(os.path.join(self.basepath, fname)) as fp: - data = ruamel.yaml.safe_load(fp) + data = self.yaml.load(fp) entry = lesana.Entry(self.collection, data=data) eid = entry.eid self.assertEqual(str(entry), eid) @@ -118,7 +119,7 @@ class testEntries(unittest.TestCase): def test_render_entry(self): fname = '11189ee47ddf4796b718a483b379f976.yaml' with open(os.path.join(self.basepath, fname)) as fp: - data = ruamel.yaml.safe_load(fp) + data = self.yaml.load(fp) entry = lesana.Entry(self.collection, data=data) eid = entry.eid res = entry.render('tests/data/simple/templates/trivial_template.txt') @@ -167,6 +168,7 @@ class testSimpleCollection(unittest.TestCase): dirs_exist_ok=True ) self.collection = lesana.Collection(self.tmpdir.name) + self.yaml = ruamel.yaml.YAML(typ='safe', pure=True) def tearDown(self): self.tmpdir.cleanup() @@ -292,7 +294,7 @@ class testSimpleCollection(unittest.TestCase): entry = self.collection.entry_from_eid( '085682ed6792499da3ab9aebd683c011' ) - data = ruamel.yaml.safe_load(entry.yaml_data) + data = self.yaml.load(entry.yaml_data) self.assertEqual(data['cost'], '1.99') fname = 'tests/data/simple/items/' + \ |