aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2020-09-16 11:42:18 +0200
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2020-09-16 11:51:51 +0200
commit872b637d3144ce73c450691e122de1a4648231b6 (patch)
treebff4db071325b4e5af4ddba3a3ca935dcb66673d /tests
parent7552f522a8938e7472e105a2efc73c0264a80f7f (diff)
Run tests on a tmpdir copy of the sample collections
Diffstat (limited to 'tests')
-rw-r--r--tests/test_collection.py438
1 files changed, 212 insertions, 226 deletions
diff --git a/tests/test_collection.py b/tests/test_collection.py
index 0d300d2..04ec410 100644
--- a/tests/test_collection.py
+++ b/tests/test_collection.py
@@ -10,19 +10,143 @@ import ruamel.yaml
import lesana
-class testCollection(unittest.TestCase):
+class testEntries(unittest.TestCase):
+ def setUp(self):
+ self.tmpdir = tempfile.mkdtemp()
+ shutil.copytree('tests/data/simple', self.tmpdir, dirs_exist_ok=True)
+ self.collection = lesana.Collection(self.tmpdir)
+ self.basepath = self.collection.itemdir
+ self.filenames = []
+
def tearDown(self):
- shutil.rmtree(os.path.join(self.collection.basedir, '.lesana'))
+ shutil.rmtree(self.tmpdir)
+
+ def test_simple(self):
+ fname = '085682ed-6792-499d-a3ab-9aebd683c011.yaml'
+ 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'])
+ 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.short_id, eid[:8])
+
+ def test_write_new(self):
+ new_entry = lesana.Entry(self.collection)
+ self.collection.save_entries(entries=[new_entry])
+ entry_fname = os.path.join(self.basepath, new_entry.fname)
+ with open(entry_fname) as fp:
+ text = fp.read()
+ self.assertIn('quantity (integer): how many items are there', text)
+ self.assertIn('other (yaml):', text)
+ self.assertNotIn('position (string)', text)
+ written = ruamel.yaml.safe_load(text)
+ self.assertIsInstance(written['quantity'], int)
+ self.assertIsInstance(written['name'], str)
+
+ def test_entry_representation(self):
+ eid = '11189ee47ddf4796b718a483b379f976'
+ entry = self.collection.entry_from_eid(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')
+ )
+
+ def test_entry_creation_eid_but_no_filename(self):
+ fname = '11189ee47ddf4796b718a483b379f976.yaml'
+ with open(os.path.join(self.basepath, fname)) as fp:
+ data = ruamel.yaml.safe_load(fp)
+ data['eid'] = '11189ee47ddf4796b718a483b379f976'
+ entry = lesana.Entry(self.collection, data=data)
+ self.assertEqual(entry.fname, fname)
+
+ def test_entry_creation_no_eid_no_filename(self):
+ fname = '11189ee47ddf4796b718a483b379f976.yaml'
+ with open(os.path.join(self.basepath, fname)) as fp:
+ data = ruamel.yaml.safe_load(fp)
+ entry = lesana.Entry(self.collection, data=data)
+ self.assertIsNotNone(entry.eid)
+ self.assertIsNotNone(entry.fname)
+
+ def test_entry_creation_filename_but_no_eid(self):
+ 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.eid, eid)
- def test_empty(self):
- self.collection = lesana.Collection('tests/data/empty')
+ def test_entry_str_filename_and_eid(self):
+ fname = '11189ee47ddf4796b718a483b379f976.yaml'
+ with open(os.path.join(self.basepath, fname)) as fp:
+ data = ruamel.yaml.safe_load(fp)
+ data['eid'] = '11189ee47ddf4796b718a483b379f976'
+ entry = lesana.Entry(self.collection, data=data)
+ self.assertEqual(str(entry), data['eid'])
+ self.collection.settings['entry_label'] = '{{ eid }}: {{ name }}'
+ self.assertEqual(str(entry), data['eid'] + ': Another item')
+
+ def test_entry_str_filename_no_eid(self):
+ fname = '11189ee47ddf4796b718a483b379f976.yaml'
+ with open(os.path.join(self.basepath, fname)) as fp:
+ data = ruamel.yaml.safe_load(fp)
+ entry = lesana.Entry(self.collection, data=data)
+ eid = entry.eid
+ self.assertEqual(str(entry), eid)
+ self.collection.settings['entry_label'] = '{{ eid }}: {{ name }}'
+ self.assertEqual(str(entry), eid + ': Another item')
+
+ def test_render_entry(self):
+ fname = '11189ee47ddf4796b718a483b379f976.yaml'
+ with open(os.path.join(self.basepath, fname)) as fp:
+ data = ruamel.yaml.safe_load(fp)
+ entry = lesana.Entry(self.collection, data=data)
+ eid = entry.eid
+ res = entry.render('tests/data/simple/templates/trivial_template.txt')
+ self.assertIn(eid, res)
+
+ def test_empty_data(self):
+ entry = lesana.Entry(self.collection)
+ self.assertIn("name: ''", entry.yaml_data)
+ self.assertIn('quantity: 0', entry.yaml_data)
+
+
+class testEmptyCollection(unittest.TestCase):
+ def setUp(self):
+ self.tmpdir = tempfile.mkdtemp()
+ shutil.copytree('tests/data/empty', self.tmpdir, dirs_exist_ok=True)
+ self.collection = lesana.Collection(self.tmpdir)
+
+ def tearDown(self):
+ shutil.rmtree(self.tmpdir)
+
+ def test_loaded(self):
self.assertEqual(self.collection.settings, {})
self.collection.update_cache()
self.assertIsNotNone(self.collection.stemmer)
- def test_load_simple(self):
- self.collection = lesana.Collection('tests/data/simple')
+
+class testSimpleCollection(unittest.TestCase):
+ def setUp(self):
+ self.tmpdir = tempfile.mkdtemp()
+ shutil.copytree('tests/data/simple', self.tmpdir, dirs_exist_ok=True)
+ self.collection = lesana.Collection(self.tmpdir)
+
+ def tearDown(self):
+ shutil.rmtree(self.tmpdir)
+
+ def test_loaded(self):
self.assertIsNotNone(self.collection.settings)
self.assertEqual(
self.collection.settings['name'],
@@ -34,36 +158,13 @@ class testCollection(unittest.TestCase):
self.collection.update_cache()
self.assertIsNotNone(self.collection.stemmer)
- 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')
- 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.stemmer)
-
- 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):
- self.collection = lesana.Collection('tests/data/wrong')
- self.collection.update_cache()
- 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']), 7)
- self.assertEqual(len(self.collection.indexed_fields), 3)
-
def test_load_safe(self):
- self.collection = lesana.Collection('tests/data/simple')
+ # Simply run the code with self.collection.safe = True to check
+ # that it doesn't break.
self.collection.safe = True
self.collection.update_cache()
def test_full_search(self):
- self.collection = lesana.Collection('tests/data/simple')
self.collection.start_search('Item')
res = self.collection.get_all_search_results()
matches = list(res)
@@ -72,7 +173,6 @@ class testCollection(unittest.TestCase):
self.assertIsInstance(m, lesana.Entry)
def test_search(self):
- self.collection = lesana.Collection('tests/data/simple')
self.collection.start_search('Item')
res = self.collection.get_search_results()
matches = list(res)
@@ -81,7 +181,6 @@ class testCollection(unittest.TestCase):
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)
@@ -90,14 +189,12 @@ class testCollection(unittest.TestCase):
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())
self.assertEqual(matches, [])
matches = list(self.collection.get_all_search_results())
self.assertEqual(matches, [])
def test_all_entries(self):
- self.collection = lesana.Collection('tests/data/simple')
res = self.collection.get_all_documents()
matches = list(res)
self.assertEqual(len(matches), 3)
@@ -105,7 +202,6 @@ class testCollection(unittest.TestCase):
self.assertIsInstance(m, lesana.Entry)
def test_entry_from_eid(self):
- self.collection = lesana.Collection('tests/data/simple')
entry = self.collection.entry_from_eid(
'11189ee47ddf4796b718a483b379f976'
)
@@ -117,7 +213,6 @@ class testCollection(unittest.TestCase):
self.assertEqual(entry.eid, '11189ee47ddf4796b718a483b379f976')
def test_entry_from_short_eid(self):
- self.collection = lesana.Collection('tests/data/simple')
entries = self.collection.entries_from_short_eid(
'11189ee4'
)
@@ -134,35 +229,22 @@ class testCollection(unittest.TestCase):
self.assertEqual(len(entries), 0)
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])
def test_get_entry_missing_eid(self):
- self.collection = lesana.Collection('tests/data/simple')
entry = self.collection.entry_from_eid('this is not an eid')
self.assertIsNone(entry)
def test_render_collection(self):
- self.collection = lesana.Collection('tests/data/simple')
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)
-
-class testSimpleCollection(unittest.TestCase):
- def setUp(self):
- self.tmpdir = tempfile.mkdtemp()
- shutil.copytree('tests/data/simple', self.tmpdir, dirs_exist_ok=True)
- self.collection = lesana.Collection(self.tmpdir)
-
- def tearDown(self):
- shutil.rmtree(self.tmpdir)
-
def test_update(self):
self.collection.update_field('Item', field="position", value="new_pos")
with open(os.path.join(
@@ -186,126 +268,14 @@ class testSimpleCollection(unittest.TestCase):
)
-class testEntries(unittest.TestCase):
+class testComplexCollection(unittest.TestCase):
def setUp(self):
- self.collection = lesana.Collection('tests/data/simple')
- self.basepath = 'tests/data/simple/items'
- self.filenames = []
+ self.tmpdir = tempfile.mkdtemp()
+ shutil.copytree('tests/data/complex', self.tmpdir, dirs_exist_ok=True)
+ self.collection = lesana.Collection(self.tmpdir)
def tearDown(self):
- for fname in self.filenames:
- os.remove(fname)
- 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.safe_load(fp)
- entry = lesana.Entry(self.collection, data=data, fname=fname)
- 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.short_id, eid[:8])
-
- def test_write_new(self):
- new_entry = lesana.Entry(self.collection)
- self.collection.save_entries(entries=[new_entry])
- entry_fname = 'tests/data/simple/items/' + new_entry.fname
- self.filenames.append(entry_fname)
- with open(entry_fname) as fp:
- text = fp.read()
- self.assertIn('quantity (integer): how many items are there', text)
- self.assertIn('other (yaml):', text)
- self.assertNotIn('position (string)', text)
- written = ruamel.yaml.safe_load(text)
- self.assertIsInstance(written['quantity'], int)
- self.assertIsInstance(written['name'], str)
-
- def test_entry_representation(self):
- eid = '11189ee47ddf4796b718a483b379f976'
- entry = self.collection.entry_from_eid(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')
- )
-
- def test_entry_creation_eid_but_no_filename(self):
- fname = '11189ee47ddf4796b718a483b379f976.yaml'
- with open(os.path.join(self.basepath, fname)) as fp:
- data = ruamel.yaml.safe_load(fp)
- data['eid'] = '11189ee47ddf4796b718a483b379f976'
- entry = lesana.Entry(self.collection, data=data)
- self.assertEqual(entry.fname, fname)
-
- def test_entry_creation_no_eid_no_filename(self):
- fname = '11189ee47ddf4796b718a483b379f976.yaml'
- with open(os.path.join(self.basepath, fname)) as fp:
- data = ruamel.yaml.safe_load(fp)
- entry = lesana.Entry(self.collection, data=data)
- self.assertIsNotNone(entry.eid)
- self.assertIsNotNone(entry.fname)
-
- def test_entry_creation_filename_but_no_eid(self):
- 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.eid, eid)
-
- def test_entry_str_filename_and_eid(self):
- fname = '11189ee47ddf4796b718a483b379f976.yaml'
- with open(os.path.join(self.basepath, fname)) as fp:
- data = ruamel.yaml.safe_load(fp)
- data['eid'] = '11189ee47ddf4796b718a483b379f976'
- entry = lesana.Entry(self.collection, data=data)
- self.assertEqual(str(entry), data['eid'])
- self.collection.settings['entry_label'] = '{{ eid }}: {{ name }}'
- self.assertEqual(str(entry), data['eid'] + ': Another item')
-
- def test_entry_str_filename_no_eid(self):
- fname = '11189ee47ddf4796b718a483b379f976.yaml'
- with open(os.path.join(self.basepath, fname)) as fp:
- data = ruamel.yaml.safe_load(fp)
- entry = lesana.Entry(self.collection, data=data)
- eid = entry.eid
- self.assertEqual(str(entry), eid)
- self.collection.settings['entry_label'] = '{{ eid }}: {{ name }}'
- self.assertEqual(str(entry), eid + ': Another item')
-
- def test_render_entry(self):
- fname = '11189ee47ddf4796b718a483b379f976.yaml'
- with open(os.path.join(self.basepath, fname)) as fp:
- data = ruamel.yaml.safe_load(fp)
- entry = lesana.Entry(self.collection, data=data)
- eid = entry.eid
- res = entry.render('tests/data/simple/templates/trivial_template.txt')
- self.assertIn(eid, res)
-
- def test_empty_data(self):
- entry = lesana.Entry(self.collection)
- self.assertIn("name: ''", entry.yaml_data)
- self.assertIn('quantity: 0', entry.yaml_data)
-
-
-class testComplexCollection(unittest.TestCase):
- @classmethod
- def setUpClass(self):
- self.collection = lesana.Collection('tests/data/complex')
-
- @classmethod
- def tearDownClass(self):
- shutil.rmtree(os.path.join(self.collection.basedir, '.lesana'))
+ shutil.rmtree(self.tmpdir)
def test_init(self):
self.assertIsNotNone(self.collection.settings)
@@ -344,13 +314,35 @@ class testComplexCollection(unittest.TestCase):
class testCollectionWithErrors(unittest.TestCase):
- @classmethod
- def setUpClass(self):
- self.collection = lesana.Collection('tests/data/wrong')
+ def setUp(self):
+ self.tmpdir = tempfile.mkdtemp()
+ shutil.copytree('tests/data/wrong', self.tmpdir, dirs_exist_ok=True)
+ self.collection = lesana.Collection(self.tmpdir)
- @classmethod
- def tearDownClass(self):
- shutil.rmtree(os.path.join(self.collection.basedir, '.lesana'))
+ def tearDown(self):
+ shutil.rmtree(self.tmpdir)
+
+ def test_load_wrong_language(self):
+ # We reload this collection, with an invalid value in lang, to
+ # check that the log contains a warning.
+ with self.assertLogs(level=logging.WARNING) as cm:
+ self.collection = lesana.Collection(self.tmpdir)
+ 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.stemmer)
+
+ def test_no_index_for_one_field(self):
+ # In the “wrong” collection, some of the entries have no "index"
+ # field.
+ self.collection.update_cache()
+ 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']), 7)
+ self.assertEqual(len(self.collection.indexed_fields), 3)
def test_init(self):
self.assertIsNotNone(self.collection.settings)
@@ -368,66 +360,65 @@ class testCollectionWithErrors(unittest.TestCase):
class testCollectionCreation(unittest.TestCase):
+ def setUp(self):
+ self.tmpdir = tempfile.mkdtemp()
+
+ def tearDown(self):
+ shutil.rmtree(self.tmpdir)
+
def test_init(self):
- tmpdir = tempfile.mkdtemp()
- collection = lesana.Collection.init(tmpdir)
+ collection = lesana.Collection.init(self.tmpdir)
self.assertIsInstance(collection, lesana.Collection)
- self.assertTrue(os.path.isdir(os.path.join(tmpdir, '.git')))
- self.assertTrue(os.path.isdir(os.path.join(tmpdir, '.lesana')))
- self.assertTrue(os.path.isfile(os.path.join(tmpdir, 'settings.yaml')))
- self.assertTrue(os.path.isfile(os.path.join(tmpdir, '.gitignore')))
+ 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')))
# and then run it twice on the same directory, nothing should break
- collection = lesana.Collection.init(tmpdir)
+ collection = lesana.Collection.init(self.tmpdir)
self.assertIsInstance(collection, lesana.Collection)
- self.assertTrue(os.path.isdir(os.path.join(tmpdir, '.git')))
- self.assertTrue(os.path.isdir(os.path.join(tmpdir, '.lesana')))
- self.assertTrue(os.path.isfile(os.path.join(tmpdir, 'settings.yaml')))
- self.assertTrue(os.path.isfile(os.path.join(tmpdir, '.gitignore')))
- created = lesana.Collection(tmpdir)
+ 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')))
+ created = lesana.Collection(self.tmpdir)
self.assertTrue(created.settings['git'])
- shutil.rmtree(tmpdir)
def _do_nothing(*args, **kwargs):
# A function that does nothing instead of editing a file
pass
def test_init_edit_file(self):
- tmpdir = tempfile.mkdtemp()
- collection = lesana.Collection.init(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(tmpdir, '.git')))
- self.assertTrue(os.path.isdir(os.path.join(tmpdir, '.lesana')))
- self.assertTrue(os.path.isfile(os.path.join(tmpdir, 'settings.yaml')))
- self.assertTrue(os.path.isfile(os.path.join(tmpdir, '.gitignore')))
- shutil.rmtree(tmpdir)
+ 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')))
def test_init_no_git(self):
- tmpdir = tempfile.mkdtemp()
- collection = lesana.Collection.init(tmpdir, git_enabled=False)
+ collection = lesana.Collection.init(self.tmpdir, git_enabled=False)
self.assertIsInstance(collection, lesana.Collection)
- self.assertFalse(os.path.isdir(os.path.join(tmpdir, '.git')))
- self.assertTrue(os.path.isdir(os.path.join(tmpdir, '.lesana')))
- self.assertTrue(os.path.isfile(os.path.join(tmpdir, 'settings.yaml')))
- self.assertFalse(os.path.isfile(os.path.join(tmpdir, '.gitignore')))
+ 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')))
# and then run it twice on the same directory, nothing should break
- collection = lesana.Collection.init(tmpdir, git_enabled=False)
+ collection = lesana.Collection.init(self.tmpdir, git_enabled=False)
self.assertIsInstance(collection, lesana.Collection)
- self.assertFalse(os.path.isdir(os.path.join(tmpdir, '.git')))
- self.assertTrue(os.path.isdir(os.path.join(tmpdir, '.lesana')))
- self.assertTrue(os.path.isfile(os.path.join(tmpdir, 'settings.yaml')))
- self.assertFalse(os.path.isfile(os.path.join(tmpdir, '.gitignore')))
- created = lesana.Collection(tmpdir)
+ 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')))
+ created = lesana.Collection(self.tmpdir)
self.assertFalse(created.settings['git'])
- shutil.rmtree(tmpdir)
def test_deletion(self):
- tmpdir = tempfile.mkdtemp()
- shutil.copy('tests/data/simple/settings.yaml', tmpdir)
+ shutil.copy('tests/data/simple/settings.yaml', self.tmpdir)
shutil.copytree(
'tests/data/simple/items',
- os.path.join(tmpdir, 'items'),
+ os.path.join(self.tmpdir, 'items'),
)
- collection = lesana.Collection.init(tmpdir)
+ collection = lesana.Collection.init(self.tmpdir)
# We start with one item indexed with the term "another"
collection.start_search('another')
mset = collection._enquire.get_mset(0, 10)
@@ -436,7 +427,7 @@ class testCollectionCreation(unittest.TestCase):
collection.remove_entries(['11189ee47ddf4796b718a483b379f976'])
# An now we should have none
self.assertFalse(os.path.exists(os.path.join(
- tmpdir,
+ self.tmpdir,
'items',
'11189ee47ddf4796b718a483b379f976.yaml'
)))
@@ -445,13 +436,12 @@ class testCollectionCreation(unittest.TestCase):
self.assertEqual(mset.get_matches_estimated(), 0)
def test_partial_eid_deletion(self):
- tmpdir = tempfile.mkdtemp()
- shutil.copy('tests/data/simple/settings.yaml', tmpdir)
+ shutil.copy('tests/data/simple/settings.yaml', self.tmpdir)
shutil.copytree(
'tests/data/simple/items',
- os.path.join(tmpdir, 'items'),
+ os.path.join(self.tmpdir, 'items'),
)
- collection = lesana.Collection.init(tmpdir)
+ collection = lesana.Collection.init(self.tmpdir)
# We start with one item indexed with the term "another"
collection.start_search('another')
mset = collection._enquire.get_mset(0, 10)
@@ -460,7 +450,7 @@ class testCollectionCreation(unittest.TestCase):
collection.remove_entries(['11189ee4'])
# An now we should have none
self.assertFalse(os.path.exists(os.path.join(
- tmpdir,
+ self.tmpdir,
'items',
'11189ee47ddf4796b718a483b379f976.yaml'
)))
@@ -477,15 +467,14 @@ class testCollectionCreation(unittest.TestCase):
return found
def test_git_adding(self):
- tmpdir = tempfile.mkdtemp()
- shutil.copy('tests/data/simple/settings.yaml', tmpdir)
+ shutil.copy('tests/data/simple/settings.yaml', self.tmpdir)
shutil.copytree(
'tests/data/simple/items',
- os.path.join(tmpdir, 'items'),
+ os.path.join(self.tmpdir, 'items'),
)
- collection = lesana.Collection.init(tmpdir)
+ collection = lesana.Collection.init(self.tmpdir)
fname = '11189ee47ddf4796b718a483b379f976.yaml'
- repo = git.Repo(tmpdir)
+ repo = git.Repo(self.tmpdir)
# By default, this collection doesn't have any git entry in the
# settings (but there is a repo)
collection.git_add_files([os.path.join(collection.itemdir, fname)])
@@ -499,12 +488,10 @@ class testCollectionCreation(unittest.TestCase):
collection.settings['git'] = True
collection.git_add_files([os.path.join(collection.itemdir, fname)])
self.assertTrue(self._find_file_in_git_index(fname, repo.index))
- shutil.rmtree(tmpdir)
def test_init_custom_settings(self):
- tmpdir = tempfile.mkdtemp()
collection = lesana.Collection.init(
- tmpdir,
+ self.tmpdir,
edit_file=self._do_nothing,
settings={
'name': 'A different name',
@@ -515,10 +502,9 @@ class testCollectionCreation(unittest.TestCase):
},
)
self.assertIsInstance(collection, lesana.Collection)
- self.assertTrue(os.path.isfile(os.path.join(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)
- shutil.rmtree(tmpdir)
if __name__ == '__main__':