From 02be4edee24ecc94fccfd9a6165903a60901a9f3 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Tue, 26 Mar 2019 16:46:44 -0400 Subject: [PATCH] test: try to make test_import work better without assuming cwd Allows it to run properly on Windows. --- src/calibre/test_build.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/calibre/test_build.py b/src/calibre/test_build.py index 397299264b..50fb71430d 100644 --- a/src/calibre/test_build.py +++ b/src/calibre/test_build.py @@ -82,7 +82,9 @@ class BuildTest(unittest.TestCase): exclude.append('osx') if not islinux: exclude.extend(['dbus', 'linux']) - for root, dirs, files in os.walk('src/calibre'): + base = os.path.dirname(__file__) + trimpath = len(os.path.dirname(base)) + 1 + for root, dirs, files in os.walk(base): for dir in dirs: if not os.path.isfile(os.path.join(root, dir, '__init__.py')): dirs.remove(dir) @@ -90,7 +92,7 @@ class BuildTest(unittest.TestCase): file, ext = os.path.splitext(file) if ext != '.py': continue - name = '.'.join(root.split(os.path.sep)[1:] + [file]) + name = '.'.join(root[trimpath:].split(os.path.sep) + [file]) if not any(x for x in exclude if x in name): importlib.import_module(name)