summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2016-12-22 19:43:02 +0100
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2016-12-22 19:43:02 +0100
commite6363dd992be0f2cf5e3395db5c6d652cee62b3f (patch)
treec370969100808275c4218366b364b96fa1aae07c /tests
parentb89aafc8ffa39b9184557bacc4c7548a5bda9b3d (diff)
Add very basic search capabilities
Diffstat (limited to 'tests')
-rw-r--r--tests/data/simple/items/085682ed-6792-499d-a3ab-9aebd683c011.yaml2
-rw-r--r--tests/test_collection.py21
2 files changed, 16 insertions, 7 deletions
diff --git a/tests/data/simple/items/085682ed-6792-499d-a3ab-9aebd683c011.yaml b/tests/data/simple/items/085682ed-6792-499d-a3ab-9aebd683c011.yaml
index 16d6917..082128c 100644
--- a/tests/data/simple/items/085682ed-6792-499d-a3ab-9aebd683c011.yaml
+++ b/tests/data/simple/items/085682ed-6792-499d-a3ab-9aebd683c011.yaml
@@ -1,6 +1,6 @@
name: One Item
description: |
- This is a long block of test
+ This is a long block of text
that spans multiple lines.
position: somewhere
uid: 085682ed6792499da3ab9aebd683c011
diff --git a/tests/test_collection.py b/tests/test_collection.py
index 68c29f3..ccd535f 100644
--- a/tests/test_collection.py
+++ b/tests/test_collection.py
@@ -17,7 +17,6 @@ class testCollectionLoading(unittest.TestCase):
self.assertEqual(self.collection.settings, {})
self.collection.update_cache()
- self.assertIsNotNone(self.collection.cache)
self.assertIsNotNone(self.collection.stemmer)
def test_simple(self):
@@ -28,9 +27,9 @@ class testCollectionLoading(unittest.TestCase):
"Simple lesana collection"
)
self.assertEqual(len(self.collection.settings['fields']), 4)
+ self.assertEqual(len(self.collection.indexed_fields), 2)
self.collection.update_cache()
- self.assertIsNotNone(self.collection.cache)
self.assertIsNotNone(self.collection.stemmer)
def test_wrong_language(self):
@@ -42,7 +41,6 @@ class testCollectionLoading(unittest.TestCase):
# 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):
@@ -50,26 +48,37 @@ class testCollectionLoading(unittest.TestCase):
self.collection.safe = False
self.collection.update_cache()
+ def test_search(self):
+ self.collection = lesana.Collection('tests/data/simple')
+ res = self.collection.search('Item')
+ matches = list(res)
+ self.assertEqual(len(matches), 2)
+ for m in matches:
+ self.assertIsInstance(m, lesana.Entry)
+
+
class testEntries(unittest.TestCase):
def setUp(self):
self.collection = lesana.Collection('tests/data/simple')
self.basepath = 'tests/data/simple/items'
+ def tearDown(self):
+ shutil.rmtree(os.path.join(self.collection.basedir, '.lesana'))
+
+
def test_simple(self):
fname = '085682ed-6792-499d-a3ab-9aebd683c011.yaml'
with open(os.path.join(self.basepath, fname)) as fp:
data = ruamel.yaml.load(fp)
entry = lesana.Entry(self.collection, data=data, fname=fname)
self.assertEqual(entry.idterm, 'Q'+data['uid'])
- self.assertEqual(len(entry.indexed_fields), 2)
fname = '11189ee47ddf4796b718a483b379f976.yaml'
uid = '11189ee47ddf4796b718a483b379f976'
with open(os.path.join(self.basepath, fname)) as fp:
data = ruamel.yaml.load(fp)
entry = lesana.Entry(self.collection, data=data, fname=fname)
self.assertEqual(entry.idterm, 'Q'+uid)
- self.assertEqual(len(entry.indexed_fields), 2)
def test_write_new(self):
new_entry = lesana.Entry(self.collection)
@@ -99,7 +108,7 @@ class testComplexCollection(unittest.TestCase):
)
self.assertEqual(len(self.collection.settings['fields']), 3)
self.assertIsNotNone(self.collection.stemmer)
+ self.assertEqual(len(self.collection.indexed_fields), 2)
def test_index(self):
self.collection.update_cache()
- self.assertIsNotNone(self.collection.cache)