launch test and helper scripts with main.launch()

This commit is contained in:
The MMGen Project 2023-12-12 10:19:51 +00:00
commit 4c49a6e59c
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
11 changed files with 44 additions and 28 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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