mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
A single entry point to run all tests
This commit is contained in:
parent
beb53457a8
commit
538f0a7186
@ -12,7 +12,7 @@ __all__ = [
|
||||
'gui',
|
||||
'develop', 'install',
|
||||
'kakasi', 'coffee', 'rapydscript', 'cacerts', 'resources',
|
||||
'check',
|
||||
'check', 'test',
|
||||
'sdist', 'bootstrap',
|
||||
'manual', 'tag_release',
|
||||
'pypi_register', 'pypi_upload', 'upload_to_server',
|
||||
@ -50,6 +50,9 @@ gui = GUI()
|
||||
from setup.check import Check
|
||||
check = Check()
|
||||
|
||||
from setup.test import Test
|
||||
test = Test()
|
||||
|
||||
from setup.resources import Resources, Kakasi, Coffee, CACerts, RapydScript
|
||||
resources = Resources()
|
||||
kakasi = Kakasi()
|
||||
|
67
setup/test.py
Normal file
67
setup/test.py
Normal file
@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env python2
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
from __future__ import (unicode_literals, division, absolute_import,
|
||||
print_function)
|
||||
import unittest
|
||||
|
||||
from setup import Command
|
||||
|
||||
TEST_MODULES = frozenset('srv db polish selectors opf css docx cfi matcher icu smartypants'.split())
|
||||
|
||||
def find_tests(which_tests=None):
|
||||
ans = []
|
||||
a = ans.append
|
||||
if not which_tests or 'srv' in which_tests:
|
||||
from calibre.srv.tests.main import find_tests
|
||||
a(find_tests())
|
||||
if not which_tests or 'db' in which_tests:
|
||||
from calibre.db.tests.main import find_tests
|
||||
a(find_tests())
|
||||
if not which_tests or 'polish' in which_tests:
|
||||
from calibre.ebooks.oeb.polish.tests.main import find_tests
|
||||
a(find_tests())
|
||||
if not which_tests or 'selectors' in which_tests:
|
||||
from css_selectors.tests import find_tests
|
||||
a(find_tests())
|
||||
if not which_tests or 'opf' in which_tests:
|
||||
from calibre.ebooks.metadata.opf2 import suite
|
||||
a(suite())
|
||||
from calibre.ebooks.metadata.opf3_test import suite
|
||||
a(suite())
|
||||
if not which_tests or 'css' in which_tests:
|
||||
from tinycss.tests.main import find_tests
|
||||
a(find_tests())
|
||||
from calibre.ebooks.oeb.normalize_css import test_normalization
|
||||
a(test_normalization(return_tests=True))
|
||||
from calibre.ebooks.css_transform_rules import test
|
||||
a(test(return_tests=True))
|
||||
if not which_tests or 'docx' in which_tests:
|
||||
from calibre.ebooks.docx.fields import test_parse_fields
|
||||
a(test_parse_fields(return_tests=True))
|
||||
from calibre.ebooks.docx.writer.utils import test_convert_color
|
||||
a(test_convert_color(return_tests=True))
|
||||
if not which_tests or 'cfi' in which_tests:
|
||||
from calibre.ebooks.epub.cfi.tests import find_tests
|
||||
a(find_tests())
|
||||
if not which_tests or 'matcher' in which_tests:
|
||||
from calibre.utils.matcher import test
|
||||
a(test(return_tests=True))
|
||||
if not which_tests or 'icu' in which_tests:
|
||||
from calibre.utils.icu_test import find_tests
|
||||
a(find_tests())
|
||||
if not which_tests or 'smartypants' in which_tests:
|
||||
from calibre.utils.smartypants import run_tests
|
||||
a(run_tests(return_tests=True))
|
||||
|
||||
tests = unittest.TestSuite(ans)
|
||||
return tests
|
||||
|
||||
class Test(Command):
|
||||
|
||||
def run(self, opts):
|
||||
from calibre.gui2 import ensure_app, load_builtin_fonts
|
||||
ensure_app(), load_builtin_fonts()
|
||||
r = unittest.TextTestRunner
|
||||
r(verbosity=2).run(find_tests())
|
@ -349,7 +349,7 @@ def import_rules(raw_data):
|
||||
if current_rule:
|
||||
yield sanitize(current_rule)
|
||||
|
||||
def test(): # {{{
|
||||
def test(return_tests=False): # {{{
|
||||
import unittest
|
||||
|
||||
def apply_rule(style, **rule):
|
||||
@ -430,6 +430,8 @@ def test(): # {{{
|
||||
self.ae(rule, next(import_rules(export_rules([rule]))))
|
||||
|
||||
tests = unittest.defaultTestLoader.loadTestsFromTestCase(TestTransforms)
|
||||
if return_tests:
|
||||
return tests
|
||||
unittest.TextTestRunner(verbosity=4).run(tests)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -224,7 +224,7 @@ class Fields(object):
|
||||
for idx, blocks in self.index_fields:
|
||||
polish_index_markup(idx, [rmap[b] for b in blocks])
|
||||
|
||||
def test_parse_fields():
|
||||
def test_parse_fields(return_tests=False):
|
||||
import unittest
|
||||
|
||||
class TestParseFields(unittest.TestCase):
|
||||
@ -249,6 +249,8 @@ def test_parse_fields():
|
||||
ae(r'\b \c 1', {'bookmark':None, 'columns-per-page': '1'})
|
||||
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(TestParseFields)
|
||||
if return_tests:
|
||||
return suite
|
||||
unittest.TextTestRunner(verbosity=4).run(suite)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -27,7 +27,7 @@ def convert_color(value):
|
||||
return
|
||||
return '%02X%02X%02X' % (int(val.red * 255), int(val.green * 255), int(val.blue * 255))
|
||||
|
||||
def test_convert_color():
|
||||
def test_convert_color(return_tests=False):
|
||||
import unittest
|
||||
class TestColors(unittest.TestCase):
|
||||
|
||||
@ -48,5 +48,7 @@ def test_convert_color():
|
||||
ae('FFFFFF', cc('rgb(255, 255, 255)'))
|
||||
ae('FF0000', cc('rgba(255, 0, 0, 23)'))
|
||||
tests = unittest.defaultTestLoader.loadTestsFromTestCase(TestColors)
|
||||
if return_tests:
|
||||
return tests
|
||||
unittest.TextTestRunner(verbosity=4).run(tests)
|
||||
# }}}
|
||||
|
@ -90,6 +90,8 @@ class Tests(unittest.TestCase):
|
||||
]:
|
||||
self.assertEqual(p.parse_path(raw), (path, leftover))
|
||||
|
||||
def find_tests():
|
||||
return unittest.TestLoader().loadTestsFromTestCase(Tests)
|
||||
|
||||
if __name__ == '__main__':
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(Tests)
|
||||
unittest.TextTestRunner(verbosity=2).run(suite)
|
||||
unittest.TextTestRunner(verbosity=2).run(find_tests())
|
||||
|
@ -174,11 +174,13 @@ class TestOPF3(unittest.TestCase):
|
||||
|
||||
# Run tests {{{
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromTestCase(TestOPF3)
|
||||
|
||||
class TestRunner(unittest.main):
|
||||
|
||||
def createTests(self):
|
||||
tl = unittest.TestLoader()
|
||||
self.test = tl.loadTestsFromTestCase(TestOPF3)
|
||||
self.test = suite()
|
||||
|
||||
def run(verbosity=4):
|
||||
TestRunner(verbosity=verbosity, exit=False)
|
||||
|
@ -284,7 +284,7 @@ def condense_sheet(sheet):
|
||||
if rule.type == rule.STYLE_RULE:
|
||||
condense_rule(rule.style)
|
||||
|
||||
def test_normalization(): # {{{
|
||||
def test_normalization(return_tests=False): # {{{
|
||||
import unittest
|
||||
from cssutils import parseStyle
|
||||
from itertools import product
|
||||
@ -442,6 +442,8 @@ def test_normalization(): # {{{
|
||||
self.assertEqual(style.getProperty('border-left').value, vals.replace('red', 'green'))
|
||||
|
||||
tests = unittest.defaultTestLoader.loadTestsFromTestCase(TestNormalization)
|
||||
if return_tests:
|
||||
return tests
|
||||
unittest.TextTestRunner(verbosity=4).run(tests)
|
||||
# }}}
|
||||
|
||||
|
@ -197,11 +197,13 @@ class TestICU(unittest.TestCase):
|
||||
fpos = index_of(needle, haystack)
|
||||
self.ae(pos, fpos, 'Failed to find index of %r in %r (%d != %d)' % (needle, haystack, pos, fpos))
|
||||
|
||||
def find_tests():
|
||||
return unittest.defaultTestLoader.loadTestsFromTestCase(TestICU)
|
||||
|
||||
class TestRunner(unittest.main):
|
||||
|
||||
def createTests(self):
|
||||
tl = unittest.TestLoader()
|
||||
self.test = tl.loadTestsFromTestCase(TestICU)
|
||||
self.test = find_tests()
|
||||
|
||||
def run(verbosity=4):
|
||||
TestRunner(verbosity=verbosity, exit=False)
|
||||
|
@ -220,7 +220,7 @@ class CScorer(object):
|
||||
for score, pos in izip(scores, positions):
|
||||
yield score, pos
|
||||
|
||||
def test():
|
||||
def test(return_tests=False):
|
||||
import unittest
|
||||
|
||||
class Test(unittest.TestCase):
|
||||
@ -251,6 +251,9 @@ def test():
|
||||
positions = next(m(raw).itervalues())
|
||||
self.assertEqual(positions, (0, 1, (2 if sys.maxunicode >= 0x10ffff else 3)))
|
||||
|
||||
if return_tests:
|
||||
return unittest.TestLoader().loadTestsFromTestCase(Test)
|
||||
|
||||
class TestRunner(unittest.main):
|
||||
|
||||
def createTests(self):
|
||||
|
@ -887,7 +887,7 @@ def _tokenize(str):
|
||||
|
||||
return tokens
|
||||
|
||||
def run_tests():
|
||||
def run_tests(return_tests=False):
|
||||
import unittest
|
||||
sp = smartyPants
|
||||
|
||||
@ -929,6 +929,8 @@ def run_tests():
|
||||
self.assertEqual(sp('''"Isn't this fun?"'''), '''“Isn’t this fun?”''')
|
||||
|
||||
tests = unittest.defaultTestLoader.loadTestsFromTestCase(TestSmartypantsAllAttributes)
|
||||
if return_tests:
|
||||
return tests
|
||||
unittest.TextTestRunner(verbosity=4).run(tests)
|
||||
|
||||
|
||||
|
@ -6,10 +6,16 @@ from __future__ import (unicode_literals, division, absolute_import,
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
import unittest, os, argparse
|
||||
import unittest, os, argparse, importlib
|
||||
|
||||
def find_tests():
|
||||
return unittest.defaultTestLoader.discover(os.path.dirname(os.path.abspath(__file__)), pattern='*.py')
|
||||
base = os.path.dirname(os.path.abspath(__file__))
|
||||
suits = []
|
||||
for x in os.listdir(base):
|
||||
if x.endswith('.py') and x != 'main.py':
|
||||
m = importlib.import_module('tinycss.tests.' + x.partition('.')[0])
|
||||
suits.append(unittest.defaultTestLoader.loadTestsFromModule(m))
|
||||
return unittest.TestSuite(suits)
|
||||
|
||||
def run_tests(find_tests=find_tests, for_build=False):
|
||||
if not for_build:
|
||||
|
Loading…
x
Reference in New Issue
Block a user