+++ /dev/null
-
-import os
-import unittest
-from m_librarian.db import open_db, init_db
-from m_librarian.inp import import_inpx
-
-__all__ = ['TestCase', 'main']
-
-
-class TestCase(unittest.TestCase):
- def setUp(self):
- try:
- os.remove('/tmp/m_librarian-test.sqlite')
- except OSError:
- pass
- open_db('sqlite:///tmp/m_librarian-test.sqlite')
- init_db()
-
- def tearDown(self):
- try:
- os.remove('/tmp/m_librarian-test.sqlite')
- except OSError:
- pass
-
- def import_inpx(self, inpx):
- import_inpx(os.path.join(os.path.dirname(__file__), inpx))
--- /dev/null
+
+import os
+from m_librarian.db import open_db, init_db
+from m_librarian.inp import import_inpx
+
+__all__ = ['setup_module', 'teardown_module', 'load_inpx']
+
+
+def setup_module():
+ try:
+ os.remove('/tmp/m_librarian-test.sqlite')
+ except OSError:
+ pass
+ open_db('sqlite:///tmp/m_librarian-test.sqlite')
+ init_db()
+
+
+def teardown_module():
+ try:
+ os.remove('/tmp/m_librarian-test.sqlite')
+ except OSError:
+ pass
+
+
+def load_inpx(inpx):
+ import_inpx(os.path.join(os.path.dirname(__file__), inpx))
import os
-import unittest
from m_librarian.config import get_config
-class TestFormat(unittest.TestCase):
- def test_config(self):
- config_path = os.path.join(
- os.path.dirname(__file__), 'test_config.conf')
- get_config(config_path)
- ml_conf = get_config()
- self.assertEqual(ml_conf.get('library', 'path'), '/home/test-config')
+def test_config():
+ config_path = os.path.join(
+ os.path.dirname(__file__), 'test_config.conf')
+ get_config(config_path)
+ ml_conf = get_config()
+ assert ml_conf.get('library', 'path') == '/home/test-config'
import os
-import unittest
from m_librarian import download
from m_librarian.config import get_config
-class TestFormat(unittest.TestCase):
- def test_compile_format(self):
- config_path = os.path.join(
- os.path.dirname(__file__), 'test_config.conf')
- get_config(config_path)
- ml_conf = get_config()
- ml_conf.set('download', 'format', '%a/%s/%n %t')
- download._compile_format()
- self.assertEqual(download.compiled_format,
- u'%(author)s/%(series)s/%(ser_no)d %(title)s')
+def test_compile_format():
+ config_path = os.path.join(
+ os.path.dirname(__file__), 'test_config.conf')
+ get_config(config_path)
+ ml_conf = get_config()
+ ml_conf.set('download', 'format', '%a/%s/%n %t')
+ download._compile_format()
+ assert download.compiled_format == \
+ u'%(author)s/%(series)s/%(ser_no)d %(title)s'
-from tests import TestCase
+from dbutils import setup_module, teardown_module # noqa
from m_librarian.db import Genre
from m_librarian.glst import import_glst
-class TestGlst(TestCase):
- def test_import_glst(self):
- import_glst()
- self.assertEqual(Genre.select().count(), 340)
+def test_import_glst():
+ import_glst()
+ assert Genre.select().count() == 340
-from tests import TestCase
+from pytest import raises
+from dbutils import setup_module, teardown_module # noqa
+from dbutils import load_inpx
from m_librarian.db import Author, Book
-class TestInp(TestCase):
- def test_import_bad_inpx(self):
- self.assertRaises(ValueError, self.import_inpx, 'bad.inpx')
+def test_import_bad_inpx():
+ raises(ValueError, load_inpx, 'bad.inpx')
- def test_import_inpx(self):
- self.import_inpx('test.inpx')
- self.assertEqual(Author.select().count(), 4)
- self.assertEqual(Book.select().count(), 4)
+
+def test_import_inpx():
+ load_inpx('test.inpx')
+ assert Author.select().count() == 4
+ assert Book.select().count() == 4
# coding: utf-8
-from tests import TestCase
+from dbutils import setup_module, teardown_module # noqa
+from dbutils import load_inpx
from m_librarian.db import Author, Book
from m_librarian.search import mk_search_conditions, \
search_authors, search_books
-class TestSearch(TestCase):
- def test_search_authors(self):
- self.import_inpx('test.inpx')
- self.assertEqual(
- search_authors('full', True, {'surname': u'Друг'}).count(), 1)
- self.assertEqual(
- search_authors('start', True, {'surname': u'Друг'}).count(), 2)
- self.assertEqual(
- search_authors('substring', True, {'surname': u'Друг'}).count(), 2)
- self.assertEqual(
- search_authors('substring', False, {'surname': u'друг'}).count(),
- 3)
+def test_search_authors():
+ load_inpx('test.inpx')
+ assert search_authors('full', True, {'surname': u'Друг'}).count() == 1
+ assert search_authors('start', True, {'surname': u'Друг'}).count() == 2
+ assert search_authors('substring', True, {'surname': u'Друг'}).count() == 2
+ assert search_authors(
+ 'substring', False, {'surname': u'друг'}).count() == 3
- join_expressions = []
- join_expressions.append(Book.j.authors)
- conditions = mk_search_conditions(
- Author, 'start', False, {'surname': u'друг'})
- join_expressions.extend(conditions)
- self.assertEqual(
- search_books('start', False,
- {'title': u'тест'}, join_expressions).count(),
- 2)
+ join_expressions = []
+ join_expressions.append(Book.j.authors)
+ conditions = mk_search_conditions(
+ Author, 'start', False, {'surname': u'друг'})
+ join_expressions.extend(conditions)
+ assert search_books(
+ 'start', False, {'title': u'тест'}, join_expressions).count() == 2