test suite: sys.path, overlay, PYTHONPATH cleanups

This commit is contained in:
The MMGen Project 2023-09-26 09:40:12 +00:00
commit 31a6e62a24
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
15 changed files with 30 additions and 34 deletions

View file

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

View file

@ -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']

View file

@ -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

View file

@ -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

View file

@ -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"

View file

@ -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

View file

@ -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)

View file

@ -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 *

View file

@ -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()

View file

@ -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

View file

@ -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

View file

@ -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 *

View file

@ -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()

View file

@ -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:

View file

@ -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))