12
12
13
13
# %% ../nbs/00_test.ipynb 6
14
14
def test_fail (f , msg = '' , contains = '' , args = None , kwargs = None ):
15
- args , kwargs = args or [], kwargs or {}
16
15
"Fails with `msg` unless `f()` raises an exception and (optionally) has `contains` in `e.args`"
16
+ args , kwargs = args or [], kwargs or {}
17
17
try : f (* args , ** kwargs )
18
18
except Exception as e :
19
19
assert not contains or contains in str (e )
20
20
return
21
21
assert False ,f"Expected exception but none raised. { msg } "
22
22
23
23
# %% ../nbs/00_test.ipynb 10
24
- def test (a , b , cmp ,cname = None ):
24
+ def test (a , b , cmp , cname = None ):
25
25
"`assert` that `cmp(a,b)`; display inputs and `cname or cmp.__name__` if it fails"
26
26
if cname is None : cname = cmp .__name__
27
27
assert cmp (a ,b ),f"{ cname } :\n { a } \n { b } "
@@ -34,7 +34,7 @@ def nequals(a,b):
34
34
# %% ../nbs/00_test.ipynb 20
35
35
def test_eq (a ,b ):
36
36
"`test` that `a==b`"
37
- test (a ,b ,equals , '==' )
37
+ test (a ,b ,equals , cname = '==' )
38
38
39
39
# %% ../nbs/00_test.ipynb 25
40
40
def test_eq_type (a ,b ):
@@ -78,14 +78,14 @@ def test_stdout(f, exp, regex=False):
78
78
"Test that `f` prints `exp` to stdout, optionally checking as `regex`"
79
79
s = io .StringIO ()
80
80
with redirect_stdout (s ): f ()
81
- if regex : assert re .search (exp , s .getvalue ()) is not None
81
+ if regex : assert re .search (exp , s .getvalue ()) is not None , f"regex ' { exp } ' did not not match stdout ' { s . getvalue () } '"
82
82
else : test_eq (s .getvalue (), f'{ exp } \n ' if len (exp ) > 0 else '' )
83
83
84
84
# %% ../nbs/00_test.ipynb 40
85
85
def test_warns (f , show = False ):
86
86
with warnings .catch_warnings (record = True ) as w :
87
87
f ()
88
- test_ne ( len ( w ), 0 )
88
+ assert w , "No warnings raised"
89
89
if show :
90
90
for e in w : print (f"{ e .category } : { e .message } " )
91
91
0 commit comments