diff --git a/mmgen/color.py b/mmgen/color.py index c8a9377e..63508c71 100755 --- a/mmgen/color.py +++ b/mmgen/color.py @@ -26,7 +26,7 @@ _colors = { 'green': ( 121, (32,1) ), 'yellow': ( 229, (33,1) ), 'blue': ( 75, (34,1) ), - 'magenta': ( 213, (35,1) ), + 'magenta': ( 205, (35,1) ), 'cyan': ( 122, (36,1) ), 'pink': ( 218, (35,1) ), 'orange': ( 216, (31,1) ), @@ -41,14 +41,14 @@ _colors = { 'yelbg': ( (232,229), (30,103) ), } -for c in _colors: - e = _colors[c] - globals()['_256_'+c] = '\033[38;5;{};1m'.format(e[0]) if type(e[0]) == int \ - else '\033[38;5;{};48;5;{};1m'.format(*e[0]) - globals()['_16_'+c] = '\033[{}m'.format(e[1][0]) if e[1][1] == 0 \ - else '\033[{};{}m'.format(*e[1]) - globals()['_clr_'+c] = ''; _reset = '' - exec('def {c}(s): return _clr_{c}+s+_reset'.format(c=c)) +for _c in _colors: + _e = _colors[_c] + globals()['_256_'+_c] = '\033[38;5;{};1m'.format(_e[0]) if type(_e[0]) == int \ + else '\033[38;5;{};48;5;{};1m'.format(*_e[0]) + globals()['_16_'+_c] = '\033[{}m'.format(_e[1][0]) if _e[1][1] == 0 \ + else '\033[{};{}m'.format(*_e[1]) + globals()['_clr_'+_c] = ''; _reset = '' + exec('def {c}(s): return _clr_{c}+s+_reset'.format(c=_c)) def nocolor(s): return s diff --git a/mmgen/devtools.py b/mmgen/devtools.py index 6630a472..5f24c267 100755 --- a/mmgen/devtools.py +++ b/mmgen/devtools.py @@ -6,7 +6,7 @@ from difflib import unified_diff def pmsg(*args,out=sys.stderr): d = args if len(args) > 1 else '' if not args else args[0] - out.write('\n' + pprint.PrettyPrinter(indent=4).pformat(d) + '\n') + out.write(pprint.PrettyPrinter(indent=4).pformat(d) + '\n') def pdie(*args,exit_val=1,out=sys.stderr): pmsg(*args,out=out) sys.exit(exit_val) diff --git a/mmgen/globalvars.py b/mmgen/globalvars.py index dabdcd1c..8ae24832 100755 --- a/mmgen/globalvars.py +++ b/mmgen/globalvars.py @@ -70,7 +70,7 @@ class g(object): tx_confs = 3 seed_len = 256 - # Constant vars - some of these might be overriden in opts.py, but they don't change thereafter + # Constant vars - some of these might be overridden in opts.py, but they don't change thereafter coin = 'BTC' dcoin = None # the display coin unit diff --git a/mmgen/obj.py b/mmgen/obj.py index 6587c705..77c706b0 100755 --- a/mmgen/obj.py +++ b/mmgen/obj.py @@ -486,7 +486,7 @@ class CoinAddr(str,Hilite,InitErrors,MMGenObject): assert set(s) <= set(ascii_letters+digits),'contains non-alphanumeric characters' me = str.__new__(cls,s) va = g.proto.verify_addr(s,hex_width=cls.hex_width,return_dict=True) - assert va,'failed verification' + assert va,'coin address {!r} failed verification'.format(s) me.addr_fmt = va['format'] me.hex = va['hex'] return me diff --git a/mmgen/tw.py b/mmgen/tw.py index c655bbd0..d6fb3e7f 100755 --- a/mmgen/tw.py +++ b/mmgen/tw.py @@ -61,7 +61,6 @@ Actions: [q]uit view, [p]rint to file, pager [v]iew, [w]ide view, add [l]abel: class MMGenTwOutputList(list,MMGenObject): pass class MMGenTwUnspentOutput(MMGenListItem): - # attrs = 'txid','vout','amt','label','twmmid','addr','confs','scriptPubKey','days','skip' txid = MMGenListItemAttr('txid','CoinTxID') vout = MMGenListItemAttr('vout',int,typeconv=False) amt = MMGenImmutableAttr('amt',g.proto.coin_amt.__name__) diff --git a/test/objtest.py b/test/objtest.py index e9424a9a..9b3cfd1c 100755 --- a/test/objtest.py +++ b/test/objtest.py @@ -115,13 +115,15 @@ def run_test(test,arg,input_data): die(2,red('{}'.format(e.args[0]))) def do_loop(): - utests = cmd_args + import importlib network = ('mainnet','testnet')[bool(g.testnet)] - gl = globals() - exec('from test.objtest_py_d.ot_{}_{} import tests'.format(g.coin.lower(),network),gl,gl) + modname = 'test.objtest_py_d.ot_{}_{}'.format(g.coin.lower(),network) + test_data = importlib.import_module(modname).tests gmsg('Running data object tests for {} {}'.format(g.coin,network)) + clr = None - for test in tests: + utests = cmd_args + for test in test_data: if utests and test not in utests: continue nl = ('\n','')[bool(opt.super_silent) or clr == None] clr = (blue,nocolor)[bool(opt.super_silent)] @@ -129,7 +131,7 @@ def do_loop(): for k in ('bad','good'): if not opt.silent: msg(purple(capfirst(k)+' input:')) - for arg in tests[test][k]: + for arg in test_data[test][k]: run_test(test,arg,input_data=k) do_loop() diff --git a/test/test.py b/test/test.py index a4b13e35..e095e5e8 100755 --- a/test/test.py +++ b/test/test.py @@ -140,10 +140,10 @@ If no command is given, the whole test suite is run. data_dir = os.path.join('test','data_dir' + ('','-α')[bool(os.getenv('MMGEN_DEBUG_UTF8'))]) # we need the values of two opts before running opts.init, so parse without initializing: -uopts = opts.init(opts_data,parse_only=True)[0] +_uopts = opts.init(opts_data,parse_only=True)[0] # step 1: delete data_dir symlink in ./test; -if not ('resume' in uopts or 'skip_deps' in uopts): +if not ('resume' in _uopts or 'skip_deps' in _uopts): try: os.unlink(data_dir) except: pass @@ -154,7 +154,7 @@ usr_args = opts.init(opts_data) # step 3: move data_dir to /dev/shm and symlink it back to ./test: trash_dir = os.path.join('test','trash') -if not ('resume' in uopts or 'skip_deps' in uopts): +if not ('resume' in _uopts or 'skip_deps' in _uopts): shm_dir = create_shm_dir(data_dir,trash_dir) check_segwit_opts() @@ -330,21 +330,24 @@ cfgs = { # addr_idx_lists (except 31,32,33,34) must contain exactly 8 addresses '34': {}, } -for k in ('6','7','8'): - cfgs['2'+k] = {} - cfgs['2'+k].update(cfgs[k]) +def fixup_cfgs(): + for k in ('6','7','8'): + cfgs['2'+k] = {} + cfgs['2'+k].update(cfgs[k]) -for k in cfgs: - cfgs[k]['tmpdir'] = os.path.join('test','tmp{}'.format(k)) - cfgs[k]['segwit'] = randbool() if opt.segwit_random else bool(opt.segwit or opt.bech32) + for k in cfgs: + cfgs[k]['tmpdir'] = os.path.join('test','tmp{}'.format(k)) + cfgs[k]['segwit'] = randbool() if opt.segwit_random else bool(opt.segwit or opt.bech32) -from copy import deepcopy -for a,b in (('6','11'),('7','12'),('8','13')): - cfgs[b] = deepcopy(cfgs[a]) - cfgs[b]['tmpdir'] = os.path.join('test','tmp'+b) + from copy import deepcopy + for a,b in (('6','11'),('7','12'),('8','13')): + cfgs[b] = deepcopy(cfgs[a]) + cfgs[b]['tmpdir'] = os.path.join('test','tmp'+b) -if g.debug_utf8: - for k in cfgs: cfgs[k]['tmpdir'] += '-α' + if g.debug_utf8: + for k in cfgs: cfgs[k]['tmpdir'] += '-α' + +fixup_cfgs() utils = { # 'check_deps': 'check dependencies for specified command (WIP)', # TODO diff --git a/test/test_py_d/ts_ref.py b/test/test_py_d/ts_ref.py index 4ea5401b..f069d1a7 100755 --- a/test/test_py_d/ts_ref.py +++ b/test/test_py_d/ts_ref.py @@ -30,6 +30,7 @@ from test.test_py_d.ts_base import * from test.test_py_d.ts_shared import * wpasswd = 'reference password' +nw_name = '{} {}'.format(g.coin,('Mainnet','Testnet')[g.testnet]) class TestSuiteRef(TestSuiteBase,TestSuiteShared): 'saved reference files' @@ -202,7 +203,7 @@ class TestSuiteRef(TestSuiteBase,TestSuiteShared): mmtype = None, add_args = [], id_key = None, - pat = 'BTC Mainnet.*Legacy'): + pat = '{}.*Legacy'.format(nw_name)): af_key = 'ref_{}file'.format(ftype) + ('_' + id_key if id_key else '') af_fn = TestSuiteRef.sources[af_key].format(pfx or self.altcoin_pfx,'' if coin else self.tn_ext) af = joinpath(ref_dir,(subdir or self.ref_subdir,'')[ftype=='passwd'],af_fn) @@ -225,12 +226,12 @@ class TestSuiteRef(TestSuiteBase,TestSuiteShared): def ref_segwitaddrfile_chk(self): if not 'S' in g.proto.mmtypes: return skip('not supported') - return self.ref_addrfile_chk(ftype='segwitaddr',pat='BTC Mainnet.*Segwit') + return self.ref_addrfile_chk(ftype='segwitaddr',pat='{}.*Segwit'.format(nw_name)) def ref_bech32addrfile_chk(self): if not 'B' in g.proto.mmtypes: return skip('not supported') - return self.ref_addrfile_chk(ftype='bech32addr',pat='BTC Mainnet.*Bech32') + return self.ref_addrfile_chk(ftype='bech32addr',pat='{}.*Bech32'.format(nw_name)) def ref_keyaddrfile_chk(self): return self.ref_addrfile_chk(ftype='keyaddr') diff --git a/test/unit_tests.py b/test/unit_tests.py index 5ddb68e1..181ee676 100755 --- a/test/unit_tests.py +++ b/test/unit_tests.py @@ -67,12 +67,14 @@ try: if test not in all_tests: die(1,"'{}': test not recognized".format(test)) + import importlib for test in (cmd_args or all_tests): - exec('from test.unit_tests_d.ut_{m} import unit_test'.format(m=test)) + modname = 'test.unit_tests_d.ut_{}'.format(test) + mod = importlib.import_module(modname) gmsg('Running unit test {}'.format(test)) - if not unit_test().run_test(test): + if not mod.unit_test().run_test(test): rdie(1,'Unit test {!r} failed'.format(test)) - exec('del unit_test'.format(test)) + del mod exit_msg() except KeyboardInterrupt: