aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2020-09-16 12:16:57 +0200
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2020-09-16 12:16:57 +0200
commitc7b332764115de5c41a518c64ce902adc3b9b924 (patch)
tree8879cfadef9d644715a651b08a70a5e182551991 /tests
parent872b637d3144ce73c450691e122de1a4648231b6 (diff)
flake8 fixes
Diffstat (limited to 'tests')
-rw-r--r--tests/test_collection.py156
1 files changed, 89 insertions, 67 deletions
diff --git a/tests/test_collection.py b/tests/test_collection.py
index 04ec410..832f421 100644
--- a/tests/test_collection.py
+++ b/tests/test_collection.py
@@ -26,13 +26,13 @@ class testEntries(unittest.TestCase):
with open(os.path.join(self.basepath, fname)) as fp:
data = ruamel.yaml.safe_load(fp)
entry = lesana.Entry(self.collection, data=data, fname=fname)
- self.assertEqual(entry.idterm, 'Q'+data['eid'])
+ self.assertEqual(entry.idterm, 'Q' + data['eid'])
fname = '11189ee47ddf4796b718a483b379f976.yaml'
eid = '11189ee47ddf4796b718a483b379f976'
with open(os.path.join(self.basepath, fname)) as fp:
data = ruamel.yaml.safe_load(fp)
entry = lesana.Entry(self.collection, data=data, fname=fname)
- self.assertEqual(entry.idterm, 'Q'+eid)
+ self.assertEqual(entry.idterm, 'Q' + eid)
self.assertEqual(entry.short_id, eid[:8])
def test_write_new(self):
@@ -51,16 +51,12 @@ class testEntries(unittest.TestCase):
def test_entry_representation(self):
eid = '11189ee47ddf4796b718a483b379f976'
entry = self.collection.entry_from_eid(eid)
- self.assertEqual(
- str(entry),
- eid
- )
+ self.assertEqual(str(entry), eid)
label = '{{ eid }}: {{ name }}'
self.collection.settings['entry_label'] = label
self.assertEqual(
- str(entry),
- '{eid}: {name}'.format(eid=eid, name='Another item')
- )
+ str(entry), '{eid}: {name}'.format(eid=eid, name='Another item')
+ )
def test_entry_creation_eid_but_no_filename(self):
fname = '11189ee47ddf4796b718a483b379f976.yaml'
@@ -149,9 +145,8 @@ class testSimpleCollection(unittest.TestCase):
def test_loaded(self):
self.assertIsNotNone(self.collection.settings)
self.assertEqual(
- self.collection.settings['name'],
- "Simple lesana collection"
- )
+ self.collection.settings['name'], "Simple lesana collection"
+ )
self.assertEqual(len(self.collection.settings['fields']), 7)
self.assertEqual(len(self.collection.indexed_fields), 3)
@@ -204,28 +199,24 @@ class testSimpleCollection(unittest.TestCase):
def test_entry_from_eid(self):
entry = self.collection.entry_from_eid(
'11189ee47ddf4796b718a483b379f976'
- )
+ )
self.assertEqual(entry.eid, '11189ee47ddf4796b718a483b379f976')
self.collection.safe = True
entry = self.collection.entry_from_eid(
'11189ee47ddf4796b718a483b379f976'
- )
+ )
self.assertEqual(entry.eid, '11189ee47ddf4796b718a483b379f976')
def test_entry_from_short_eid(self):
- entries = self.collection.entries_from_short_eid(
- '11189ee4'
- )
+ entries = self.collection.entries_from_short_eid('11189ee4')
self.assertEqual(len(entries), 1)
self.assertEqual(entries[0].eid, '11189ee47ddf4796b718a483b379f976')
entries = self.collection.entries_from_short_eid(
'11189ee47ddf4796b718a483b379f976'
- )
+ )
self.assertEqual(len(entries), 1)
self.assertEqual(entries[0].eid, '11189ee47ddf4796b718a483b379f976')
- entries = self.collection.entries_from_short_eid(
- '12345678'
- )
+ entries = self.collection.entries_from_short_eid('12345678')
self.assertEqual(len(entries), 0)
def test_index_missing_file(self):
@@ -241,24 +232,26 @@ class testSimpleCollection(unittest.TestCase):
def test_render_collection(self):
template = self.collection.get_template(
'tests/data/simple/templates/collection_template.txt'
- )
+ )
res = template.render(entries=self.collection.get_all_documents())
self.assertIn('11189ee4: Another item', res)
def test_update(self):
self.collection.update_field('Item', field="position", value="new_pos")
- with open(os.path.join(
- self.collection.basedir,
- 'items',
- '11189ee47ddf4796b718a483b379f976.yaml'
- )) as fp:
+ with open(
+ os.path.join(
+ self.collection.basedir,
+ 'items',
+ '11189ee47ddf4796b718a483b379f976.yaml',
+ )
+ ) as fp:
self.assertIn("new_pos", fp.read())
pass
self.assertEqual(
self.collection.entry_from_eid(
"11189ee47ddf4796b718a483b379f976"
).data['position'],
- "new_pos"
+ "new_pos",
)
self.assertIsNone(
@@ -281,8 +274,8 @@ class testComplexCollection(unittest.TestCase):
self.assertIsNotNone(self.collection.settings)
self.assertEqual(
self.collection.settings['name'],
- "Fully featured lesana collection"
- )
+ "Fully featured lesana collection",
+ )
self.assertEqual(len(self.collection.settings['fields']), 9)
self.assertIsNotNone(self.collection.stemmer)
self.assertEqual(len(self.collection.indexed_fields), 6)
@@ -302,7 +295,7 @@ class testComplexCollection(unittest.TestCase):
def test_boolean_field(self):
entry = self.collection.entry_from_eid(
'73097121f1874a6ea2f927db7dc4f11e'
- )
+ )
self.assertIsInstance(entry.data['exists'], bool)
def test_empty_data(self):
@@ -348,8 +341,8 @@ class testCollectionWithErrors(unittest.TestCase):
self.assertIsNotNone(self.collection.settings)
self.assertEqual(
self.collection.settings['name'],
- "Lesana collection with certain errors"
- )
+ "Lesana collection with certain errors",
+ )
self.assertEqual(len(self.collection.settings['fields']), 7)
self.assertIsNotNone(self.collection.stemmer)
self.assertEqual(len(self.collection.indexed_fields), 3)
@@ -371,15 +364,23 @@ class testCollectionCreation(unittest.TestCase):
self.assertIsInstance(collection, lesana.Collection)
self.assertTrue(os.path.isdir(os.path.join(self.tmpdir, '.git')))
self.assertTrue(os.path.isdir(os.path.join(self.tmpdir, '.lesana')))
- self.assertTrue(os.path.isfile(os.path.join(self.tmpdir, 'settings.yaml')))
- self.assertTrue(os.path.isfile(os.path.join(self.tmpdir, '.gitignore')))
+ self.assertTrue(
+ os.path.isfile(os.path.join(self.tmpdir, 'settings.yaml'))
+ )
+ self.assertTrue(
+ os.path.isfile(os.path.join(self.tmpdir, '.gitignore'))
+ )
# and then run it twice on the same directory, nothing should break
collection = lesana.Collection.init(self.tmpdir)
self.assertIsInstance(collection, lesana.Collection)
self.assertTrue(os.path.isdir(os.path.join(self.tmpdir, '.git')))
self.assertTrue(os.path.isdir(os.path.join(self.tmpdir, '.lesana')))
- self.assertTrue(os.path.isfile(os.path.join(self.tmpdir, 'settings.yaml')))
- self.assertTrue(os.path.isfile(os.path.join(self.tmpdir, '.gitignore')))
+ self.assertTrue(
+ os.path.isfile(os.path.join(self.tmpdir, 'settings.yaml'))
+ )
+ self.assertTrue(
+ os.path.isfile(os.path.join(self.tmpdir, '.gitignore'))
+ )
created = lesana.Collection(self.tmpdir)
self.assertTrue(created.settings['git'])
@@ -388,36 +389,49 @@ class testCollectionCreation(unittest.TestCase):
pass
def test_init_edit_file(self):
- collection = lesana.Collection.init(self.tmpdir, edit_file=self._do_nothing)
+ collection = lesana.Collection.init(
+ self.tmpdir, edit_file=self._do_nothing
+ )
self.assertIsInstance(collection, lesana.Collection)
self.assertTrue(os.path.isdir(os.path.join(self.tmpdir, '.git')))
self.assertTrue(os.path.isdir(os.path.join(self.tmpdir, '.lesana')))
- self.assertTrue(os.path.isfile(os.path.join(self.tmpdir, 'settings.yaml')))
- self.assertTrue(os.path.isfile(os.path.join(self.tmpdir, '.gitignore')))
+ self.assertTrue(
+ os.path.isfile(os.path.join(self.tmpdir, 'settings.yaml'))
+ )
+ self.assertTrue(
+ os.path.isfile(os.path.join(self.tmpdir, '.gitignore'))
+ )
def test_init_no_git(self):
collection = lesana.Collection.init(self.tmpdir, git_enabled=False)
self.assertIsInstance(collection, lesana.Collection)
self.assertFalse(os.path.isdir(os.path.join(self.tmpdir, '.git')))
self.assertTrue(os.path.isdir(os.path.join(self.tmpdir, '.lesana')))
- self.assertTrue(os.path.isfile(os.path.join(self.tmpdir, 'settings.yaml')))
- self.assertFalse(os.path.isfile(os.path.join(self.tmpdir, '.gitignore')))
+ self.assertTrue(
+ os.path.isfile(os.path.join(self.tmpdir, 'settings.yaml'))
+ )
+ self.assertFalse(
+ os.path.isfile(os.path.join(self.tmpdir, '.gitignore'))
+ )
# and then run it twice on the same directory, nothing should break
collection = lesana.Collection.init(self.tmpdir, git_enabled=False)
self.assertIsInstance(collection, lesana.Collection)
self.assertFalse(os.path.isdir(os.path.join(self.tmpdir, '.git')))
self.assertTrue(os.path.isdir(os.path.join(self.tmpdir, '.lesana')))
- self.assertTrue(os.path.isfile(os.path.join(self.tmpdir, 'settings.yaml')))
- self.assertFalse(os.path.isfile(os.path.join(self.tmpdir, '.gitignore')))
+ self.assertTrue(
+ os.path.isfile(os.path.join(self.tmpdir, 'settings.yaml'))
+ )
+ self.assertFalse(
+ os.path.isfile(os.path.join(self.tmpdir, '.gitignore'))
+ )
created = lesana.Collection(self.tmpdir)
self.assertFalse(created.settings['git'])
def test_deletion(self):
shutil.copy('tests/data/simple/settings.yaml', self.tmpdir)
shutil.copytree(
- 'tests/data/simple/items',
- os.path.join(self.tmpdir, 'items'),
- )
+ 'tests/data/simple/items', os.path.join(self.tmpdir, 'items'),
+ )
collection = lesana.Collection.init(self.tmpdir)
# We start with one item indexed with the term "another"
collection.start_search('another')
@@ -426,11 +440,15 @@ class testCollectionCreation(unittest.TestCase):
# Then delete it
collection.remove_entries(['11189ee47ddf4796b718a483b379f976'])
# An now we should have none
- self.assertFalse(os.path.exists(os.path.join(
- self.tmpdir,
- 'items',
- '11189ee47ddf4796b718a483b379f976.yaml'
- )))
+ self.assertFalse(
+ os.path.exists(
+ os.path.join(
+ self.tmpdir,
+ 'items',
+ '11189ee47ddf4796b718a483b379f976.yaml',
+ )
+ )
+ )
collection.start_search('another')
mset = collection._enquire.get_mset(0, 10)
self.assertEqual(mset.get_matches_estimated(), 0)
@@ -438,9 +456,8 @@ class testCollectionCreation(unittest.TestCase):
def test_partial_eid_deletion(self):
shutil.copy('tests/data/simple/settings.yaml', self.tmpdir)
shutil.copytree(
- 'tests/data/simple/items',
- os.path.join(self.tmpdir, 'items'),
- )
+ 'tests/data/simple/items', os.path.join(self.tmpdir, 'items'),
+ )
collection = lesana.Collection.init(self.tmpdir)
# We start with one item indexed with the term "another"
collection.start_search('another')
@@ -449,11 +466,15 @@ class testCollectionCreation(unittest.TestCase):
# Then delete it, using the short id
collection.remove_entries(['11189ee4'])
# An now we should have none
- self.assertFalse(os.path.exists(os.path.join(
- self.tmpdir,
- 'items',
- '11189ee47ddf4796b718a483b379f976.yaml'
- )))
+ self.assertFalse(
+ os.path.exists(
+ os.path.join(
+ self.tmpdir,
+ 'items',
+ '11189ee47ddf4796b718a483b379f976.yaml',
+ )
+ )
+ )
collection.start_search('another')
mset = collection._enquire.get_mset(0, 10)
self.assertEqual(mset.get_matches_estimated(), 0)
@@ -469,9 +490,8 @@ class testCollectionCreation(unittest.TestCase):
def test_git_adding(self):
shutil.copy('tests/data/simple/settings.yaml', self.tmpdir)
shutil.copytree(
- 'tests/data/simple/items',
- os.path.join(self.tmpdir, 'items'),
- )
+ 'tests/data/simple/items', os.path.join(self.tmpdir, 'items'),
+ )
collection = lesana.Collection.init(self.tmpdir)
fname = '11189ee47ddf4796b718a483b379f976.yaml'
repo = git.Repo(self.tmpdir)
@@ -498,11 +518,13 @@ class testCollectionCreation(unittest.TestCase):
'fields': [
{'name': 'title', 'type': 'string'},
{'name': 'author', 'type': 'string'},
- ],
- },
- )
+ ],
+ },
+ )
self.assertIsInstance(collection, lesana.Collection)
- self.assertTrue(os.path.isfile(os.path.join(self.tmpdir, 'settings.yaml')))
+ self.assertTrue(
+ os.path.isfile(os.path.join(self.tmpdir, 'settings.yaml'))
+ )
self.assertEqual(collection.settings['name'], 'A different name')
self.assertEqual(len(collection.settings['fields']), 2)