From d57631695a343ffee5e8b27a0eeb40d9881d1503 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Wed, 23 Oct 2019 10:01:11 +0000 Subject: [PATCH] test suite: move path fixup code to test/tests_header.py --- scripts/traceback_run.py | 2 +- test/hashfunc.py | 6 +----- test/pexpect.py | 4 ++-- test/scrambletest.py | 6 +----- test/test.py | 7 +------ test/tests_header.py | 5 +++++ test/tooltest.py | 7 +------ test/tooltest2.py | 7 +------ test/unit_tests.py | 7 +------ 9 files changed, 14 insertions(+), 37 deletions(-) create mode 100755 test/tests_header.py diff --git a/scripts/traceback_run.py b/scripts/traceback_run.py index e59590cd..5a3d5a71 100755 --- a/scripts/traceback_run.py +++ b/scripts/traceback_run.py @@ -8,7 +8,7 @@ import sys,os,time def traceback_run_init(): import os - sys.path.insert(0,'.') + sys.path[0] = 'test' if os.path.dirname(sys.argv[1]) == 'test' else '.' if 'TMUX' in os.environ: del os.environ['TMUX'] os.environ['MMGEN_TRACEBACK'] = '1' diff --git a/test/hashfunc.py b/test/hashfunc.py index cd707cb9..88fd1d90 100755 --- a/test/hashfunc.py +++ b/test/hashfunc.py @@ -20,11 +20,7 @@ test/hashfunc.py: Test internal implementations of SHA256, SHA512 and Keccak256 """ import sys,os - -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 = [repo_root] + sys.path - +import tests_header 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/pexpect.py b/test/pexpect.py index 216b81a9..9023c3fb 100755 --- a/test/pexpect.py +++ b/test/pexpect.py @@ -29,8 +29,8 @@ from test.common import * try: import pexpect from pexpect.popen_spawn import PopenSpawn -except: - die(2,red('Pexpect module is missing. Cannnot run test suite')) +except ImportError as e: + die(2,red('Pexpect module is missing. Cannnot run test suite ({!r})'.format(e))) def debug_pexpect_msg(p): if opt.debug_pexpect: diff --git a/test/scrambletest.py b/test/scrambletest.py index 7ea82036..a963c6d9 100755 --- a/test/scrambletest.py +++ b/test/scrambletest.py @@ -23,12 +23,8 @@ supported coins + passwords import sys,os from subprocess import run,PIPE -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.__setitem__(0,repo_root) -os.environ['MMGEN_TEST_SUITE'] = '1' -# Import this _after_ local path's been added to sys.path +from tests_header import repo_root from mmgen.common import * from test.common import * diff --git a/test/test.py b/test/test.py index 93d665f5..987afeb3 100755 --- a/test/test.py +++ b/test/test.py @@ -71,16 +71,11 @@ def create_shm_dir(data_dir,trash_dir): return shm_dir import sys,os,time - -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.__setitem__(0,repo_root) +from tests_header import repo_root try: os.unlink(os.path.join(repo_root,'my.err')) except: pass -# Import these _after_ local path's been added to sys.path from mmgen.common import * from test.common import * from test.test_py_d.common import * diff --git a/test/tests_header.py b/test/tests_header.py new file mode 100755 index 00000000..f0badae2 --- /dev/null +++ b/test/tests_header.py @@ -0,0 +1,5 @@ +import sys,os +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 +os.environ['MMGEN_TEST_SUITE'] = '1' diff --git a/test/tooltest.py b/test/tooltest.py index 07fc2441..b4b96c06 100755 --- a/test/tooltest.py +++ b/test/tooltest.py @@ -23,12 +23,7 @@ test/tooltest.py: Tests for the 'mmgen-tool' utility import sys,os,binascii from subprocess import run,PIPE -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.__setitem__(0,repo_root) -os.environ['MMGEN_TEST_SUITE'] = '1' - -# Import this _after_ local path's been added to sys.path +from tests_header import repo_root from mmgen.common import * from test.common import * diff --git a/test/tooltest2.py b/test/tooltest2.py index a2f59433..8e5f04cd 100755 --- a/test/tooltest2.py +++ b/test/tooltest2.py @@ -27,12 +27,7 @@ import sys,os,time from subprocess import run,PIPE from decimal import Decimal -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 -os.environ['MMGEN_TEST_SUITE'] = '1' - -# Import these _after_ prepending repo_root to sys.path +from tests_header import repo_root from mmgen.common import * from test.common import * from mmgen.obj import is_wif,is_coin_addr diff --git a/test/unit_tests.py b/test/unit_tests.py index 181ee676..f3fde726 100755 --- a/test/unit_tests.py +++ b/test/unit_tests.py @@ -22,12 +22,7 @@ test/unit_tests.py: Unit tests for the MMGen suite import sys,os,time -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 -os.environ['MMGEN_TEST_SUITE'] = '1' - -# Import these _after_ prepending repo_root to sys.path +from tests_header import repo_root from mmgen.common import * opts_data = {