From b2d8d7f2e936c4862ca5554bb5ffe853a65c04e7 Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Mon, 2 Jan 2017 16:37:16 +0100 Subject: Move collection initialization to Collection --- tests/test_collection.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'tests/test_collection.py') diff --git a/tests/test_collection.py b/tests/test_collection.py index a55261f..9abb3f7 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -1,6 +1,7 @@ import logging import os.path import shutil +import tempfile import unittest import ruamel.yaml @@ -130,3 +131,37 @@ class testComplexCollection(unittest.TestCase): def test_index(self): self.collection.update_cache() + +class testCollectionCreation(unittest.TestCase): + def test_init(self): + tmpdir = tempfile.mkdtemp() + collection = lesana.Collection.init(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'))) + shutil.rmtree(tmpdir) + + def do_nothing(*args, **kwargs): + pass + + def test_init_edit_file(self): + tmpdir = tempfile.mkdtemp() + collection = lesana.Collection.init(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) + + def test_init_no_git(self): + tmpdir = tempfile.mkdtemp() + collection = lesana.Collection.init(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'))) + shutil.rmtree(tmpdir) -- cgit v1.2.3