mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Clean up python module import test
This commit is contained in:
parent
55b39e16bb
commit
68afcf4598
@ -73,28 +73,39 @@ class BuildTest(unittest.TestCase):
|
|||||||
from html5_parser import parse
|
from html5_parser import parse
|
||||||
parse('<p>xxx')
|
parse('<p>xxx')
|
||||||
|
|
||||||
def test_imports(self):
|
def test_import_of_all_python_modules(self):
|
||||||
import importlib
|
import importlib
|
||||||
exclude = ['dbus_export.demo', 'dbus_export.gtk', 'upstream']
|
exclude_modules = {'calibre.gui2.dbus_export.demo', 'calibre.gui2.dbus_export.gtk'}
|
||||||
|
exclude_packages = {'calibre.devices.mtp.unix.upstream'}
|
||||||
if not iswindows:
|
if not iswindows:
|
||||||
exclude.extend(['iphlpapi', 'windows', 'winreg', 'winusb'])
|
exclude_modules |= {'calibre.utils.iphlpapi', 'calibre.utils.open_with.windows', 'calibre.devices.winusb'}
|
||||||
|
exclude_packages |= {'calibre.utils.winreg'}
|
||||||
if not isosx:
|
if not isosx:
|
||||||
exclude.append('osx')
|
exclude_modules.add('calibre.utils.open_with.osx')
|
||||||
if not islinux:
|
if not islinux:
|
||||||
exclude.extend(['dbus', 'linux'])
|
exclude_modules |= {'calibre.utils.dbus_service', 'calibre.linux'}
|
||||||
|
exclude_packages.add('calibre.gui2.dbus_export')
|
||||||
base = os.path.dirname(__file__)
|
base = os.path.dirname(__file__)
|
||||||
trimpath = len(os.path.dirname(base)) + 1
|
import_base = os.path.dirname(base)
|
||||||
|
count = 0
|
||||||
for root, dirs, files in os.walk(base):
|
for root, dirs, files in os.walk(base):
|
||||||
for dir in dirs:
|
for d in dirs:
|
||||||
if not os.path.isfile(os.path.join(root, dir, '__init__.py')):
|
if not os.path.isfile(os.path.join(root, d, '__init__.py')):
|
||||||
dirs.remove(dir)
|
dirs.remove(d)
|
||||||
for file in files:
|
for fname in files:
|
||||||
file, ext = os.path.splitext(file)
|
module_name, ext = os.path.splitext(fname)
|
||||||
if ext != '.py':
|
if ext != '.py':
|
||||||
continue
|
continue
|
||||||
name = '.'.join(root[trimpath:].split(os.path.sep) + [file])
|
path = os.path.join(root, module_name)
|
||||||
if not any(x for x in exclude if x in name):
|
relpath = os.path.relpath(path, import_base).replace(os.sep, '/')
|
||||||
importlib.import_module(name)
|
full_module_name = '.'.join(relpath.split('/'))
|
||||||
|
if full_module_name.endswith('.__init__'):
|
||||||
|
full_module_name = full_module_name.rpartition('.')[0]
|
||||||
|
if full_module_name in exclude_modules or ('.' in full_module_name and full_module_name.rpartition('.')[0] in exclude_packages):
|
||||||
|
continue
|
||||||
|
importlib.import_module(full_module_name)
|
||||||
|
count += 1
|
||||||
|
self.assertGreater(count, 1000)
|
||||||
|
|
||||||
def test_plugins(self):
|
def test_plugins(self):
|
||||||
exclusions = set()
|
exclusions = set()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user