diff options
Diffstat (limited to 'tests/test_collection.py')
-rw-r--r-- | tests/test_collection.py | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/tests/test_collection.py b/tests/test_collection.py index 869828a..84f0a7a 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -54,7 +54,7 @@ class testCollection(unittest.TestCase): self.assertIsNotNone(self.collection.settings) self.assertIsNotNone(self.collection.stemmer) # Fields with no "index" entry are not indexed - self.assertEqual(len(self.collection.settings['fields']), 3) + self.assertEqual(len(self.collection.settings['fields']), 4) self.assertEqual(len(self.collection.indexed_fields), 1) def test_load_safe(self): @@ -80,6 +80,15 @@ class testCollection(unittest.TestCase): for m in matches: self.assertIsInstance(m, lesana.Entry) + def test_search_wildcard(self): + self.collection = lesana.Collection('tests/data/simple') + self.collection.start_search('Ite*') + res = self.collection.get_search_results() + matches = list(res) + self.assertEqual(len(matches), 2) + for m in matches: + self.assertIsInstance(m, lesana.Entry) + def test_search_non_init(self): self.collection = lesana.Collection('tests/data/simple') matches = list(self.collection.get_search_results()) @@ -232,13 +241,46 @@ class testComplexCollection(unittest.TestCase): self.collection.settings['name'], "Fully featured lesana collection" ) - self.assertEqual(len(self.collection.settings['fields']), 4) + self.assertEqual(len(self.collection.settings['fields']), 5) self.assertIsNotNone(self.collection.stemmer) - self.assertEqual(len(self.collection.indexed_fields), 2) + self.assertEqual(len(self.collection.indexed_fields), 4) def test_index(self): self.collection.update_cache() + def test_indexing_list(self): + self.collection.update_cache(['73097121f1874a6ea2f927db7dc4f11e.yaml']) + self.collection.start_search('tags:this') + res = self.collection.get_search_results() + matches = list(res) + self.assertEqual(len(matches), 1) + for m in matches: + self.assertIsInstance(m, lesana.Entry) + + +class testCollectionWithErrors(unittest.TestCase): + @classmethod + def setUpClass(self): + self.collection = lesana.Collection('tests/data/wrong') + + @classmethod + def tearDownClass(self): + shutil.rmtree(os.path.join(self.collection.basedir, '.lesana')) + + def test_init(self): + self.assertIsNotNone(self.collection.settings) + self.assertEqual( + self.collection.settings['name'], + "Lesana collection with certain errors" + ) + self.assertEqual(len(self.collection.settings['fields']), 4) + self.assertIsNotNone(self.collection.stemmer) + self.assertEqual(len(self.collection.indexed_fields), 1) + + def test_index(self): + loaded = self.collection.update_cache() + self.assertEqual(loaded, 0) + class testCollectionCreation(unittest.TestCase): def test_init(self): |