diff --git a/scripts/exec_wrapper.py b/scripts/exec_wrapper.py index 492e2f4f..eb99003f 100755 --- a/scripts/exec_wrapper.py +++ b/scripts/exec_wrapper.py @@ -27,11 +27,7 @@ def exec_wrapper_init(): if exec_wrapper_os.path.dirname(exec_wrapper_sys.argv[1]) == 'test': # support running of test scripts under wrapper - cwd = exec_wrapper_os.getcwd() # assume we’re in repo root - exec_wrapper_sys.path[0] = cwd - exec_wrapper_sys.path[1] = exec_wrapper_os.path.join(cwd,'test') - from test.overlay import get_overlay_tree_dir - exec_wrapper_sys.path.insert(0, get_overlay_tree_dir(cwd)) + exec_wrapper_sys.path[0] = exec_wrapper_os.getcwd() # assume we’re in repo root else: exec_wrapper_sys.path.pop(0) diff --git a/test/cmdtest.py b/test/cmdtest.py index a1171c89..9d5ef442 100755 --- a/test/cmdtest.py +++ b/test/cmdtest.py @@ -88,8 +88,10 @@ if sys.argv[-1] == 'clean': print(f'Removed {os.path.relpath(overlay_tree_dir)!r}') else: # overlay must be set up before importing mmgen mods! - import include.test_init - repo_root = include.test_init.repo_root + try: + from include.test_init import repo_root + except ImportError: + from test.include.test_init import repo_root from mmgen.cfg import Config,gc from mmgen.color import red,yellow,green,blue,cyan,nocolor,init_color diff --git a/test/colortest.py b/test/colortest.py index 99eed61d..c72af97e 100755 --- a/test/colortest.py +++ b/test/colortest.py @@ -9,7 +9,10 @@ test/colortest.py: test color handling for the MMGen suite import os -import include.test_init +try: + from include import test_init +except ImportError: + from test.include import test_init from mmgen.color import * from mmgen.util import msg,ymsg,gmsg diff --git a/test/gentest.py b/test/gentest.py index 36614a8a..923b2f79 100755 --- a/test/gentest.py +++ b/test/gentest.py @@ -22,7 +22,10 @@ test/gentest.py: Cryptocoin key/address generation tests for the MMGen suite import sys,os,time -import include.test_init +try: + from include import test_init +except ImportError: + from test.include import test_init # Import these _after_ local path's been added to sys.path from mmgen.cfg import gc,Config diff --git a/test/hashfunc.py b/test/hashfunc.py index e1dedf1e..03b15ccf 100755 --- a/test/hashfunc.py +++ b/test/hashfunc.py @@ -21,7 +21,12 @@ test/hashfunc.py: Test internal implementations of SHA256, SHA512 and Keccak256 """ import sys -import include.test_init + +try: + from include import test_init +except ImportError: + from test.include import test_init + from mmgen.util import die assert len(sys.argv) in (2,3),"Test takes 1 or 2 arguments: test name, plus optional rounds count" diff --git a/test/include/test_init.py b/test/include/test_init.py index 6ef20c14..12f5f847 100755 --- a/test/include/test_init.py +++ b/test/include/test_init.py @@ -13,8 +13,9 @@ test.include.test_init: Initialization module for test scripts """ import sys,os +from pathlib import PurePath os.environ['MMGEN_TEST_SUITE'] = '1' -repo_root = os.path.normpath(os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]),os.pardir))) +repo_root = str(PurePath(*PurePath(sys.modules[__name__].__file__).parts[:-3])) os.chdir(repo_root) sys.path[0] = repo_root diff --git a/test/objattrtest.py b/test/objattrtest.py index c5cedbc8..727253c3 100755 --- a/test/objattrtest.py +++ b/test/objattrtest.py @@ -24,7 +24,10 @@ test/objattrtest.py: Test immutable attributes of MMGen data objects from collections import namedtuple -import include.test_init +try: + from include import test_init +except ImportError: + from test.include import test_init from mmgen.cfg import Config from mmgen.util import msg,msg_r,gmsg,die diff --git a/test/objtest.py b/test/objtest.py index 040c44d5..debef590 100755 --- a/test/objtest.py +++ b/test/objtest.py @@ -22,7 +22,10 @@ test/objtest.py: Test MMGen data objects import os,re -import include.test_init +try: + from include import test_init +except ImportError: + from test.include import test_init # for objtest, violate MMGen Project best practices and allow use of the dev tools # in production code: diff --git a/test/scrambletest.py b/test/scrambletest.py index 14767a63..215d7477 100755 --- a/test/scrambletest.py +++ b/test/scrambletest.py @@ -25,7 +25,10 @@ import sys,os,time from subprocess import run,PIPE from collections import namedtuple -import include.test_init +try: + from include import test_init +except ImportError: + from test.include import test_init from mmgen.cfg import Config from mmgen.util import msg,msg_r,bmsg,die diff --git a/test/start-coin-daemons.py b/test/start-coin-daemons.py index 8f36c41c..c75cf7e2 100755 --- a/test/start-coin-daemons.py +++ b/test/start-coin-daemons.py @@ -4,4 +4,7 @@ test/start-coin-daemons.py: Start daemons for the MMGen test suite """ -import include.coin_daemon_control +try: + import include.coin_daemon_control +except ImportError: + import test.include.coin_daemon_control diff --git a/test/stop-coin-daemons.py b/test/stop-coin-daemons.py index 83387058..c5fdbec9 100755 --- a/test/stop-coin-daemons.py +++ b/test/stop-coin-daemons.py @@ -4,4 +4,7 @@ test/stop-coin-daemons.py: Stop daemons for the MMGen test suite """ -import include.coin_daemon_control +try: + import include.coin_daemon_control +except ImportError: + import test.include.coin_daemon_control diff --git a/test/tooltest.py b/test/tooltest.py index 5da777dd..00b2f999 100755 --- a/test/tooltest.py +++ b/test/tooltest.py @@ -23,7 +23,10 @@ test/tooltest.py: Tests for the 'mmgen-tool' utility import sys,os,time from subprocess import run,PIPE -import include.test_init +try: + from include.test_init import repo_root +except ImportError: + from test.include.test_init import repo_root from mmgen.cfg import Config from mmgen.color import red,yellow,green,blue,cyan @@ -147,7 +150,7 @@ tn_ext = ('','.testnet')[proto.testnet] spawn_cmd = [ 'scripts/exec_wrapper.py', - os.path.relpath(os.path.join(include.test_init.repo_root,'cmds','mmgen-tool')) ] + os.path.relpath(os.path.join(repo_root,'cmds','mmgen-tool')) ] if cfg.coverage: d,f = init_coverage() diff --git a/test/tooltest2.py b/test/tooltest2.py index 12a7cbec..d1d89f83 100755 --- a/test/tooltest2.py +++ b/test/tooltest2.py @@ -27,7 +27,10 @@ import sys,os,time,importlib from subprocess import run,PIPE from decimal import Decimal -import include.test_init +try: + from include import test_init +except ImportError: + from test.include import test_init from test.include.common import set_globals,end_msg,sample_text,init_coverage diff --git a/test/unit_tests.py b/test/unit_tests.py index bf97d139..49feeefe 100755 --- a/test/unit_tests.py +++ b/test/unit_tests.py @@ -22,7 +22,10 @@ test/unit_tests.py: Unit tests for the MMGen suite import sys,os,time,importlib,platform -import include.test_init +try: + from include.test_init import repo_root +except ImportError: + from test.include.test_init import repo_root # for the unit tests, violate MMGen Project best practices and allow use of the dev tools # in production code: @@ -72,7 +75,7 @@ set_globals(cfg) file_pfx = 'ut_' -tests_d = os.path.join(include.test_init.repo_root,'test','unit_tests_d') +tests_d = os.path.join(repo_root,'test','unit_tests_d') all_tests = sorted(fn[len(file_pfx):-len('.py')] for fn in os.listdir(tests_d) if fn.startswith(file_pfx))