Browse Source

test suite: move path fixup code to test/tests_header.py

The MMGen Project 5 years ago
parent
commit
d57631695a
9 changed files with 14 additions and 37 deletions
  1. 1 1
      scripts/traceback_run.py
  2. 1 5
      test/hashfunc.py
  3. 2 2
      test/pexpect.py
  4. 1 5
      test/scrambletest.py
  5. 1 6
      test/test.py
  6. 5 0
      test/tests_header.py
  7. 1 6
      test/tooltest.py
  8. 1 6
      test/tooltest2.py
  9. 1 6
      test/unit_tests.py

+ 1 - 1
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'

+ 1 - 5
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"

+ 2 - 2
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:

+ 1 - 5
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 *
 

+ 1 - 6
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 *

+ 5 - 0
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'

+ 1 - 6
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 *
 

+ 1 - 6
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

+ 1 - 6
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 = {