mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
A better test discovery function
This commit is contained in:
parent
6f362f1567
commit
1e7ab5cdcc
@ -7,7 +7,7 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import unittest, os, argparse, time, functools
|
||||
import unittest, os, argparse, time, functools, importlib
|
||||
|
||||
try:
|
||||
import init_calibre # noqa
|
||||
@ -59,7 +59,13 @@ class TestResult(unittest.TextTestResult):
|
||||
self.stream.writeln('\nSlowest tests: %s' % ' '.join(slowest))
|
||||
|
||||
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('calibre.db.tests.' + x.partition('.')[0])
|
||||
suits.append(unittest.defaultTestLoader.loadTestsFromModule(m))
|
||||
return unittest.TestSuite(suits)
|
||||
|
||||
def run_tests(find_tests=find_tests):
|
||||
parser = argparse.ArgumentParser()
|
||||
|
@ -12,10 +12,16 @@ try:
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
import os, unittest
|
||||
import os, unittest, 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('calibre.ebooks.oeb.polish.tests.' + x.partition('.')[0])
|
||||
suits.append(unittest.defaultTestLoader.loadTestsFromModule(m))
|
||||
return unittest.TestSuite(suits)
|
||||
|
||||
if __name__ == '__main__':
|
||||
from calibre.db.tests.main import run_tests
|
||||
|
@ -6,7 +6,7 @@ from __future__ import (unicode_literals, division, absolute_import,
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
import unittest, os, argparse, time, functools
|
||||
import unittest, os, argparse, time, functools, importlib
|
||||
|
||||
try:
|
||||
import init_calibre
|
||||
@ -59,7 +59,13 @@ class TestResult(unittest.TextTestResult):
|
||||
self.stream.writeln('\nSlowest tests: %s' % ' '.join(slowest))
|
||||
|
||||
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('calibre.srv.tests.' + x.partition('.')[0])
|
||||
suits.append(unittest.defaultTestLoader.loadTestsFromModule(m))
|
||||
return unittest.TestSuite(suits)
|
||||
|
||||
def run_tests(find_tests=find_tests):
|
||||
from calibre.gui2 import ensure_app, load_builtin_fonts
|
||||
|
Loading…
x
Reference in New Issue
Block a user