Add the tag mapper tests to the main test runner

This commit is contained in:
Kovid Goyal 2016-07-04 09:37:15 +05:30
parent 7ff81c84b3
commit 08d56e2eee
2 changed files with 44 additions and 36 deletions

View File

@ -8,7 +8,7 @@ import unittest
from setup import Command
TEST_MODULES = frozenset('srv db polish opf css docx cfi matcher icu smartypants build'.split())
TEST_MODULES = frozenset('srv db polish opf css docx cfi matcher icu smartypants build misc'.split())
def find_tests(which_tests=None):
ans = []
@ -59,6 +59,9 @@ def find_tests(which_tests=None):
if ok('smartypants'):
from calibre.utils.smartypants import run_tests
a(run_tests(return_tests=True))
if ok('misc'):
from calibre.ebooks.metadata.tag_mapper import find_tests
a(find_tests())
tests = unittest.TestSuite(ans)
return tests
@ -68,7 +71,7 @@ class Test(Command):
description = 'Run the calibre test suite'
def add_options(self, parser):
parser.add_option('--test-module', default=[], action='append', type='choice', choices=sorted(map(str, TEST_MODULES)),
parser.add_option('--test-module', '--test-group', default=[], action='append', type='choice', choices=sorted(map(str, TEST_MODULES)),
help='The test module to run (can be specified more than once for multiple modules). Choices: %s' % ', '.join(sorted(TEST_MODULES)))
parser.add_option('--test-verbosity', type=int, default=4, help='Test verbosity (0-4)')
parser.add_option('--test-name', default=[], action='append',

View File

@ -122,7 +122,11 @@ def map_tags(tags, rules=()):
ans.extend(apply_rules(t, rules))
return uniq(filter(None, ans))
def test():
def find_tests():
import unittest
class TestTagMapper(unittest.TestCase):
def test_tag_mapper(self):
def rule(action, query, replace=None, match_type='one_of'):
ans = {'action':action, 'query': query, 'match_type':match_type}
@ -138,8 +142,7 @@ def test():
if isinstance(expected, type('')):
expected = [x.strip() for x in expected.split(',')]
ans = map_tags(tags, rules)
if ans != expected:
raise AssertionError('Expected: %r != %r' % (expected, ans))
self.assertEqual(ans, expected)
run(rule('capitalize', 't1,t2'), 't1,x1', 'T1,x1')
run(rule('upper', 'ta,t2'), 'ta,x1', 'TA,x1')
@ -158,6 +161,8 @@ def test():
run(rule('split', '/', '/', 'has'), '/,d', 'd')
run(rule('split', '/', '/', 'has'), '/a/', 'a')
run(rule('split', 'a,b', '/'), 'a,b', 'a,b')
return unittest.defaultTestLoader.loadTestsFromTestCase(TestTagMapper)
if __name__ == '__main__':
test()
from calibre.utils.run_tests import run_cli
run_cli(find_tests())