Browse Source

launch test and helper scripts with `main.launch()`

The MMGen Project 11 months ago
parent
commit
4c49a6e59c

+ 13 - 9
scripts/compute-file-chksum.py

@@ -3,6 +3,7 @@
 import sys,os
 
 import script_init
+from mmgen.main import launch
 from mmgen.cfg import Config
 from mmgen.util import msg,Msg,make_chksum_6
 from mmgen.fileutil import get_lines_from_file
@@ -20,12 +21,15 @@ opts_data = {
 
 cfg = Config(opts_data=opts_data)
 
-lines = get_lines_from_file( cfg, cfg._args[0] )
-start = (1,0)[bool(cfg.include_first_line)]
-a = make_chksum_6(' '.join(lines[start:]).encode())
-if start == 1:
-	b = lines[0]
-	msg(
-		'Checksum in file OK' if a == b else
-		f"Checksum in file ({b}) doesn't match computed value!")
-Msg(a)
+def main():
+	lines = get_lines_from_file(cfg, cfg._args[0])
+	start = (1,0)[bool(cfg.include_first_line)]
+	a = make_chksum_6(' '.join(lines[start:]).encode())
+	if start == 1:
+		b = lines[0]
+		msg(
+			'Checksum in file OK' if a == b else
+			f"Checksum in file ({b}) doesn't match computed value!")
+	Msg(a)
+
+launch(func=main)

+ 6 - 2
scripts/create-token.py

@@ -25,6 +25,7 @@ from subprocess import run,PIPE
 from collections import namedtuple
 
 import script_init
+from mmgen.main import launch
 from mmgen.cfg import Config
 from mmgen.util import Msg,msg,rmsg,ymsg,die
 
@@ -263,8 +264,7 @@ def compile_code(cfg,code):
 	else:
 		cfg._util.vmsg(out)
 
-if __name__ == '__main__':
-
+def main():
 	cfg = Config(opts_data=opts_data)
 
 	if cfg.check_solc_version:
@@ -288,3 +288,7 @@ if __name__ == '__main__':
 		print(json.dumps(out))
 
 	msg('Contract successfully compiled')
+
+if __name__ == '__main__':
+
+	launch(func=main)

+ 0 - 1
test/cmdtest_py_d/ct_ethdev.py

@@ -958,7 +958,6 @@ class CmdTestEthdev(CmdTestBase,CmdTestShared):
 			pass
 		cmd = [
 			'python3',
-			'scripts/exec_wrapper.py',
 			'scripts/create-token.py',
 			'--coin=' + self.proto.coin,
 			'--outdir=' + odir

+ 2 - 1
test/gentest.py

@@ -586,4 +586,5 @@ if proto.coin == 'XMR':
 	load_cryptodomex()
 
 if __name__ == '__main__':
-	main()
+	from mmgen.main import launch
+	launch(func=main)

+ 4 - 1
test/hashfunc.py

@@ -165,8 +165,9 @@ class TestSha512(TestSha2):
 
 from test.include.common import getrand,set_globals
 from mmgen.cfg import Config
+from mmgen.main import launch
 
-if __name__ == '__main__':
+def main():
 
 	if len(sys.argv) not in (2,3):
 		die(1,'Test takes 1 or 2 arguments: test name, plus optional rounds count')
@@ -184,3 +185,5 @@ if __name__ == '__main__':
 	t.test_constants()
 	t.test_ref()
 	t.test_random(random_rounds)
+
+launch(func=main)

+ 4 - 1
test/scrambletest.py

@@ -153,7 +153,7 @@ def do_passwd_tests():
 		s = fs.format('','')
 		do_test(cmd,tdata,s+' '*(40-len(s)),'password')
 
-if __name__ == '__main__':
+def main():
 	start_time = int(time.time())
 
 	cmds = cfg._args or ('coin','pw')
@@ -161,3 +161,6 @@ if __name__ == '__main__':
 		{'coin': do_coin_tests, 'pw': do_passwd_tests }[cmd]()
 
 	end_msg(int(time.time()) - start_time)
+
+from mmgen.main import launch
+launch(func=main)

+ 2 - 1
test/start-coin-daemons.py

@@ -9,4 +9,5 @@ try:
 except ImportError:
 	from test.include.coin_daemon_control import main
 
-main()
+from mmgen.main import launch
+launch(func=main)

+ 2 - 1
test/stop-coin-daemons.py

@@ -9,4 +9,5 @@ try:
 except ImportError:
 	from test.include.coin_daemon_control import main
 
-main()
+from mmgen.main import launch
+launch(func=main)

+ 4 - 4
test/tooltest.py

@@ -486,7 +486,7 @@ def do_cmds(cmd_group):
 		cmdline = [cmd] + [os.path.join(tcfg['tmpdir'],fn) for fn in fns]
 		getattr(tc,cmd)(*cmdline)
 
-try:
+def main():
 	if cfg._args:
 		if len(cfg._args) != 1:
 			die(1,'Only one command may be specified')
@@ -507,7 +507,7 @@ try:
 			do_cmds(cmd)
 			if cmd is not list(cmd_data.keys())[-1]:
 				msg('')
-except KeyboardInterrupt:
-	die(1,green('\nExiting at user request'))
+	end_msg(int(time.time()) - start_time)
 
-end_msg(int(time.time()) - start_time)
+from mmgen.main import launch
+launch(func=main)

+ 3 - 4
test/tooltest2.py

@@ -342,8 +342,7 @@ if cfg.fork:
 	else:
 		tool_cmd_preargs = ['python3','scripts/exec_wrapper.py']
 
+from mmgen.main import launch
 start_time = int(time.time())
-
-if __name__ == '__main__':
-	async_run(main())
-	end_msg(int(time.time()) - start_time)
+launch(func = lambda: async_run(main()))
+end_msg(int(time.time()) - start_time)

+ 4 - 3
test/unit_tests.py

@@ -207,7 +207,7 @@ def run_test(test,subtest=None):
 		if not mod.unit_test().run_test(test,UnitTestHelpers(test)):
 			die(4,'Unit test {test!r} failed')
 
-try:
+def main():
 	for test in (cfg._args or all_tests):
 		if '.' in test:
 			test,subtest = test.split('.')
@@ -218,5 +218,6 @@ try:
 		if test not in exclude:
 			run_test(test,subtest=subtest)
 	end_msg(int(time.time()) - start_time)
-except KeyboardInterrupt:
-	die(1,green('\nExiting at user request'))
+
+from mmgen.main import launch
+launch(func=main)