From bb451cf5ab9f3db35c91b79c0f2bbdc27a29a0e1 Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Fri, 6 Jan 2017 21:08:07 +0100 Subject: Improved test coverage --- lesana/collection.py | 6 ++---- .../items/8b69b063b2a64db7b5714294a69255c7.yaml | 5 +++++ tests/test_collection.py | 24 ++++++++++++++++------ 3 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 tests/data/simple/items/8b69b063b2a64db7b5714294a69255c7.yaml diff --git a/lesana/collection.py b/lesana/collection.py index e4898f6..8a4e0cc 100644 --- a/lesana/collection.py +++ b/lesana/collection.py @@ -94,7 +94,7 @@ class Collection(object): self._enquire = None # This selects whether to load all other yaml files with # safe_load or load + RoundTripLoader - self.safe = True + self.safe = False def _index_file(self, fname, cache): with open(os.path.join(self.itemdir, fname)) as fp: @@ -184,9 +184,7 @@ class Collection(object): updated += 1 return updated - def save_entries(self, entries=None): - if not entries: - raise NotImplementedError + def save_entries(self, entries=[]): for e in entries: complete_name = os.path.join( self.itemdir, diff --git a/tests/data/simple/items/8b69b063b2a64db7b5714294a69255c7.yaml b/tests/data/simple/items/8b69b063b2a64db7b5714294a69255c7.yaml new file mode 100644 index 0000000..7a0f5d7 --- /dev/null +++ b/tests/data/simple/items/8b69b063b2a64db7b5714294a69255c7.yaml @@ -0,0 +1,5 @@ +name: 'Mostly empty entry' +description: +position: +quantity: +other: diff --git a/tests/test_collection.py b/tests/test_collection.py index beab6e0..3959399 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -9,7 +9,7 @@ import ruamel.yaml import lesana -class testCollectionLoading(unittest.TestCase): +class testCollection(unittest.TestCase): def tearDown(self): shutil.rmtree(os.path.join(self.collection.basedir, '.lesana')) @@ -20,7 +20,7 @@ class testCollectionLoading(unittest.TestCase): self.collection.update_cache() self.assertIsNotNone(self.collection.stemmer) - def test_simple(self): + def test_load_simple(self): self.collection = lesana.Collection('tests/data/simple') self.assertIsNotNone(self.collection.settings) self.assertEqual( @@ -33,7 +33,7 @@ class testCollectionLoading(unittest.TestCase): self.collection.update_cache() self.assertIsNotNone(self.collection.stemmer) - def test_wrong_language(self): + def test_load_wrong_language(self): # This loads a collection with an invalid value in lang with self.assertLogs(level=logging.WARNING) as cm: self.collection = lesana.Collection('tests/data/wrong') @@ -44,7 +44,7 @@ class testCollectionLoading(unittest.TestCase): self.assertIsNotNone(self.collection.settings) self.assertIsNotNone(self.collection.stemmer) - def test_no_index_for_one_entry(self): + def test_load_no_index_for_one_entry(self): # This loads a collection where some of the entries have no # "index" field with self.assertLogs(level=logging.WARNING): @@ -56,9 +56,9 @@ class testCollectionLoading(unittest.TestCase): self.assertEqual(len(self.collection.settings['fields']), 3) self.assertEqual(len(self.collection.indexed_fields), 1) - def test_unsafe(self): + def test_load_safe(self): self.collection = lesana.Collection('tests/data/simple') - self.collection.safe = False + self.collection.safe = True self.collection.update_cache() def test_full_search(self): @@ -92,6 +92,18 @@ class testCollectionLoading(unittest.TestCase): '11189ee47ddf4796b718a483b379f976' ) self.assertEqual(entry.uid, '11189ee47ddf4796b718a483b379f976') + self.collection.safe = True + entry = self.collection.entry_from_uid( + '11189ee47ddf4796b718a483b379f976' + ) + self.assertEqual(entry.uid, '11189ee47ddf4796b718a483b379f976') + + def test_index_missing_file(self): + self.collection = lesana.Collection('tests/data/simple') + with self.assertLogs(level=logging.WARNING) as cm: + self.collection.update_cache(['non_existing_file']) + self.assertEqual(len(cm.output), 1) + self.assertIn("non_existing_file", cm.output[0]) class testEntries(unittest.TestCase): -- cgit v1.2.3