summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2017-01-06 21:08:07 +0100
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2017-01-06 21:08:07 +0100
commitbb451cf5ab9f3db35c91b79c0f2bbdc27a29a0e1 (patch)
treee51a83a2c67a7e28e9ab8514091b702534d7e5fa
parent0eb031fc93630731f2344deda8123e36c0375235 (diff)
Improved test coverage
-rw-r--r--lesana/collection.py6
-rw-r--r--tests/data/simple/items/8b69b063b2a64db7b5714294a69255c7.yaml5
-rw-r--r--tests/test_collection.py24
3 files changed, 25 insertions, 10 deletions
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):