test: add test to try importing every file

The testsuite does not currently exercise every file, but we can at
least try importing it to make sure it isn't obviously broken. This
additionally helps to iterate through python3 syntax-level
incompatibilities.
This commit is contained in:
Eli Schwartz 2019-03-26 02:17:33 -04:00
parent 564f053c02
commit 67f3ca17dd
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6

View File

@ -73,6 +73,27 @@ class BuildTest(unittest.TestCase):
from html5_parser import parse from html5_parser import parse
parse('<p>xxx') parse('<p>xxx')
def test_imports(self):
import importlib
exclude = ['dbus_export.demo', 'dbus_export.gtk', 'upstream']
if not iswindows:
exclude.extend(['iphlpapi', 'windows', 'winreg', 'winusb'])
if not isosx:
exclude.append('osx')
if not islinux:
exclude.extend(['dbus', 'linux'])
for root, dirs, files in os.walk('src/calibre'):
for dir in dirs:
if not os.path.isfile(os.path.join(root, dir, '__init__.py')):
dirs.remove(dir)
for file in files:
file, ext = os.path.splitext(file)
if ext != '.py':
continue
name = '.'.join(root.split(os.path.sep)[1:] + [file])
if not any(x for x in exclude if x in name):
importlib.import_module(name)
def test_plugins(self): def test_plugins(self):
exclusions = set() exclusions = set()
if is_ci: if is_ci: