Browse Source

test suite: `sys.path`, overlay, `PYTHONPATH` cleanups

The MMGen Project 1 year ago
parent
commit
31a6e62a24

+ 1 - 1
mmgen/data/version

@@ -1 +1 @@
-14.0.dev2
+14.0.dev3

+ 1 - 1
scripts/exec_wrapper.py

@@ -19,7 +19,7 @@ def exec_wrapper_init():
 		exec_wrapper_sys.path[0] = 'test'
 	else:
 		from test.overlay import overlay_setup
-		exec_wrapper_sys.path[0] = overlay_setup(repo_root=os.getcwd()) # assume we're in the repo root
+		overlay_setup(repo_root=os.getcwd()) # assume we're in the repo root
 
 	if 'TMUX' in os.environ:
 		del os.environ['TMUX']

+ 1 - 1
test/colortest.py

@@ -7,7 +7,7 @@
 test/colortest.py: test color handling for the MMGen suite
 """
 
-import include.tests_header
+import include.test_init
 from include.common import *
 from mmgen.color import *
 import mmgen.color as color_mod

+ 1 - 3
test/gentest.py

@@ -22,9 +22,7 @@ test/gentest.py: Cryptocoin key/address generation tests for the MMGen suite
 
 import sys,os,time
 
-from include.tests_header import repo_root
-from test.overlay import overlay_setup
-sys.path.insert(0,overlay_setup(repo_root))
+import include.test_init
 
 # Import these _after_ local path's been added to sys.path
 import mmgen.opts as opts

+ 1 - 1
test/hashfunc.py

@@ -21,7 +21,7 @@ test/hashfunc.py: Test internal implementations of SHA256, SHA512 and Keccak256
 """
 
 import sys,os
-import include.tests_header
+import include.test_init
 from mmgen.util import die,ymsg
 
 assert len(sys.argv) in (2,3),"Test takes 1 or 2 arguments: test name, plus optional rounds count"

+ 1 - 1
test/include/coin_daemon_control.py

@@ -12,7 +12,7 @@
 test.include.coin_daemon_control: Start and stop daemons for the MMGen test suite
 """
 
-from .tests_header import repo_root
+import include.test_init
 from mmgen.common import *
 from mmgen.protocol import init_proto
 

+ 3 - 0
test/include/tests_header.py → test/include/test_init.py

@@ -1,5 +1,8 @@
 import sys,os
 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)))
+os.environ['PYTHONPATH'] = repo_root
 os.chdir(repo_root)
 sys.path[0] = repo_root
+from test.overlay import overlay_setup
+overlay_setup(repo_root)

+ 1 - 1
test/objattrtest.py

@@ -24,7 +24,7 @@ test/objattrtest.py: Test immutable attributes of MMGen data objects
 
 import sys,os
 
-from include.tests_header import repo_root
+import include.test_init
 
 # Import these _after_ local path's been added to sys.path
 from mmgen.common import *

+ 1 - 3
test/objtest.py

@@ -22,9 +22,7 @@ test/objtest.py: Test MMGen data objects
 
 import sys,os,re
 
-from include.tests_header import repo_root
-from test.overlay import overlay_setup
-sys.path.insert(0,overlay_setup(repo_root))
+import include.test_init
 
 from mmgen.devinit import init_dev
 init_dev()

+ 2 - 0
test/overlay/__init__.py

@@ -66,4 +66,6 @@ def overlay_setup(repo_root):
 			for d in cfg.get('options','packages').split():
 				process_srcdir(pkgname,d)
 
+	sys.path.insert(0,overlay_tree_dir)
+
 	return overlay_tree_dir

+ 2 - 1
test/scrambletest.py

@@ -24,7 +24,8 @@ test/scrambletest.py: seed scrambling and addrlist data generation tests for all
 import sys,os,time
 from subprocess import run,PIPE
 
-from include.tests_header import repo_root
+import include.test_init
+
 import mmgen.opts as opts
 from mmgen.cfg import gc,Config
 from mmgen.util import msg,msg_r,bmsg

+ 10 - 7
test/test.py

@@ -72,18 +72,21 @@ def create_shm_dir(data_dir,trash_dir):
 
 import sys,os,time
 
-from include.tests_header import repo_root
-from test.overlay import get_overlay_tree_dir,overlay_setup
-
-overlay_tree_dir = get_overlay_tree_dir(repo_root)
-sys.path.insert(0,overlay_tree_dir)
-
 if sys.argv[-1] == 'clean':
+	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)))
+	os.chdir(repo_root)
+	sys.path[0] = repo_root
+
 	from shutil import rmtree
+	from test.overlay import get_overlay_tree_dir
+	overlay_tree_dir = get_overlay_tree_dir(repo_root)
 	rmtree(overlay_tree_dir,ignore_errors=True)
+	print(f'Removed {os.path.relpath(overlay_tree_dir)!r}')
 else:
 	# overlay must be set up before importing mmgen mods!
-	overlay_setup(repo_root)
+	import include.test_init
+	repo_root = include.test_init.repo_root
 
 from mmgen.common import *
 

+ 2 - 6
test/tooltest.py

@@ -23,9 +23,7 @@ test/tooltest.py: Tests for the 'mmgen-tool' utility
 import sys,os,binascii
 from subprocess import run,PIPE
 
-from include.tests_header import repo_root
-from test.overlay import overlay_setup
-sys.path.insert(0,overlay_setup(repo_root))
+import include.test_init
 
 from mmgen.common import *
 from test.include.common import *
@@ -131,11 +129,9 @@ ref_subdir  = '' if proto.base_coin == 'BTC' else proto.name.lower()
 altcoin_pfx = '' if proto.base_coin == 'BTC' else '-'+proto.base_coin
 tn_ext = ('','.testnet')[proto.testnet]
 
-os.environ['PYTHONPATH'] = repo_root
-
 spawn_cmd = [
 	'scripts/exec_wrapper.py',
-	os.path.relpath(os.path.join(repo_root,'cmds','mmgen-tool')) ]
+	os.path.relpath(os.path.join(include.test_init.repo_root,'cmds','mmgen-tool')) ]
 
 if cfg.coverage:
 	d,f = init_coverage()

+ 1 - 4
test/tooltest2.py

@@ -27,9 +27,7 @@ import sys,os,time,importlib
 from subprocess import run,PIPE
 from decimal import Decimal
 
-from include.tests_header import repo_root
-from test.overlay import overlay_setup
-sys.path.insert(0,overlay_setup(repo_root))
+import include.test_init
 
 from mmgen.common import *
 from test.include.common import set_globals,end_msg,sample_text
@@ -970,7 +968,6 @@ if cfg.list_tested_cmds:
 	list_tested_cmds()
 	sys.exit(0)
 
-os.environ['PYTHONPATH'] = repo_root
 tool_exec = os.path.relpath(os.path.join('cmds','mmgen-tool'))
 
 if cfg.fork:

+ 2 - 4
test/unit_tests.py

@@ -22,7 +22,7 @@ test/unit_tests.py: Unit tests for the MMGen suite
 
 import sys,os,time,importlib,platform
 
-from include.tests_header import repo_root
+import include.test_init
 
 from mmgen.devinit import init_dev
 init_dev()
@@ -61,11 +61,9 @@ type(cfg)._reset_ok += ('use_internal_keccak_module','debug_addrlist')
 
 set_globals(cfg)
 
-os.environ['PYTHONPATH'] = repo_root
-
 file_pfx = 'ut_'
 
-tests_d = os.path.join(repo_root,'test','unit_tests_d')
+tests_d = os.path.join(include.test_init.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))