1212
1313# %% ../nbs/00_test.ipynb 6
1414def test_fail (f , msg = '' , contains = '' , args = None , kwargs = None ):
15- args , kwargs = args or [], kwargs or {}
1615 "Fails with `msg` unless `f()` raises an exception and (optionally) has `contains` in `e.args`"
16+ args , kwargs = args or [], kwargs or {}
1717 try : f (* args , ** kwargs )
1818 except Exception as e :
1919 assert not contains or contains in str (e )
2020 return
2121 assert False ,f"Expected exception but none raised. { msg } "
2222
2323# %% ../nbs/00_test.ipynb 10
24- def test (a , b , cmp ,cname = None ):
24+ def test (a , b , cmp , cname = None ):
2525 "`assert` that `cmp(a,b)`; display inputs and `cname or cmp.__name__` if it fails"
2626 if cname is None : cname = cmp .__name__
2727 assert cmp (a ,b ),f"{ cname } :\n { a } \n { b } "
@@ -34,7 +34,7 @@ def nequals(a,b):
3434# %% ../nbs/00_test.ipynb 20
3535def test_eq (a ,b ):
3636 "`test` that `a==b`"
37- test (a ,b ,equals , '==' )
37+ test (a ,b ,equals , cname = '==' )
3838
3939# %% ../nbs/00_test.ipynb 25
4040def test_eq_type (a ,b ):
@@ -78,14 +78,14 @@ def test_stdout(f, exp, regex=False):
7878 "Test that `f` prints `exp` to stdout, optionally checking as `regex`"
7979 s = io .StringIO ()
8080 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 () } '"
8282 else : test_eq (s .getvalue (), f'{ exp } \n ' if len (exp ) > 0 else '' )
8383
8484# %% ../nbs/00_test.ipynb 40
8585def test_warns (f , show = False ):
8686 with warnings .catch_warnings (record = True ) as w :
8787 f ()
88- test_ne ( len ( w ), 0 )
88+ assert w , "No warnings raised"
8989 if show :
9090 for e in w : print (f"{ e .category } : { e .message } " )
9191
0 commit comments