unit_tests.py: new UnitTestHelpers class
This commit is contained in:
parent
f9778043c2
commit
1810b50b09
8 changed files with 27 additions and 8 deletions
|
|
@ -57,6 +57,25 @@ start_time = int(time.time())
|
|||
if opt.list:
|
||||
Die(0,' '.join(all_tests))
|
||||
|
||||
class UnitTestHelpers(object):
|
||||
|
||||
@classmethod
|
||||
def process_bad_data(cls,data):
|
||||
desc_w = max(len(e[0]) for e in data)
|
||||
exc_w = max(len(e[1]) for e in data)
|
||||
for (desc,exc_chk,emsg_chk,func) in data:
|
||||
try:
|
||||
vmsg_r(' {:{w}}'.format(desc+':',w=desc_w+1))
|
||||
func()
|
||||
except Exception as e:
|
||||
exc = type(e).__name__
|
||||
emsg = e.args[0]
|
||||
vmsg(' {:{w}} [{}]'.format(exc,emsg,w=exc_w))
|
||||
assert exc == exc_chk,'{!r}: incorrect exception type (expected {!r})'.format(exc,exc_chk)
|
||||
assert emsg_chk in emsg,'{!r}: incorrect error msg (should contain {!r}'.format(emsg,emsg_chk)
|
||||
else:
|
||||
rdie(3,"\nillegal action '{}' failed to raise exception {!r}".format(desc,exc_chk))
|
||||
|
||||
try:
|
||||
for test in cmd_args:
|
||||
if test not in all_tests:
|
||||
|
|
@ -67,7 +86,7 @@ try:
|
|||
modname = 'test.unit_tests_d.ut_{}'.format(test)
|
||||
mod = importlib.import_module(modname)
|
||||
gmsg('Running unit test {}'.format(test))
|
||||
if not mod.unit_test().run_test(test):
|
||||
if not mod.unit_test().run_test(test,UnitTestHelpers):
|
||||
rdie(1,'Unit test {!r} failed'.format(test))
|
||||
del mod
|
||||
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ class unit_test(object):
|
|||
),
|
||||
}
|
||||
|
||||
def run_test(self,name):
|
||||
def run_test(self,name,ut):
|
||||
|
||||
msg_r('Testing base conversion routines...')
|
||||
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ class unit_test(object):
|
|||
)
|
||||
)
|
||||
|
||||
def run_test(self,name):
|
||||
def run_test(self,name,ut):
|
||||
|
||||
msg_r('Testing BIP39 conversion routines...')
|
||||
qmsg('')
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ from mmgen.common import *
|
|||
|
||||
class unit_test(object):
|
||||
|
||||
def run_test(self,name):
|
||||
def run_test(self,name,ut):
|
||||
bad_msg = ( 'initializing values via constructor',
|
||||
'reassignment to existing key',
|
||||
'item deletion',
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ from test.common import *
|
|||
|
||||
class unit_test(object):
|
||||
|
||||
def run_test(self,name):
|
||||
def run_test(self,name,ut):
|
||||
import time
|
||||
|
||||
msg_r('Testing password hashing...')
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ from mmgen.common import *
|
|||
|
||||
class unit_test(object):
|
||||
|
||||
def run_test(self,name):
|
||||
def run_test(self,name,ut):
|
||||
from mmgen.seed import Seed,SeedShareList
|
||||
from mmgen.obj import SeedShareIdx
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ from mmgen.common import *
|
|||
|
||||
class unit_test(object):
|
||||
|
||||
def run_test(self,name):
|
||||
def run_test(self,name,ut):
|
||||
from mmgen.seed import Seed
|
||||
from mmgen.obj import SubSeedIdxRange
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class unit_test(object):
|
|||
if not self.core_repo_root:
|
||||
die(1,'The environmental variable CORE_REPO_ROOT must be set before running this test')
|
||||
|
||||
def run_test(self,name):
|
||||
def run_test(self,name,ut):
|
||||
|
||||
def test_tx(txhex,desc,n):
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue