import logging import os.path import shutil import unittest import lesana class testCollectionLoading(unittest.TestCase): def tearDown(self): shutil.rmtree(os.path.join(self.collection.basedir, '.lesana')) def test_empty(self): self.collection = lesana.Collection('tests/data/empty') self.assertEqual(self.collection.settings, {}) self.collection.update_cache() self.assertIsNotNone(self.collection.cache) self.assertIsNotNone(self.collection.stemmer) def test_simple(self): self.collection = lesana.Collection('tests/data/simple') self.assertIsNotNone(self.collection.settings) self.assertEqual(self.collection.settings['name'], "Simple lesana collection") self.assertEqual(len(self.collection.settings['fields']), 3) self.collection.update_cache() self.assertIsNotNone(self.collection.cache) self.assertIsNotNone(self.collection.stemmer) def test_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') self.assertEqual(len(cm.output), 1) self.assertIn("Invalid language", cm.output[0]) # The collection will default to english, but should still work. self.collection.update_cache() self.assertIsNotNone(self.collection.settings) self.assertIsNotNone(self.collection.cache) self.assertIsNotNone(self.collection.stemmer) def test_unsafe(self): self.collection = lesana.Collection('tests/data/simple') self.collection.safe = False self.collection.update_cache()