diff options
author | Julian Taylor <jtaylor.debian@googlemail.com> | 2013-10-19 19:02:51 +0200 |
---|---|---|
committer | Julian Taylor <jtaylor.debian@googlemail.com> | 2013-10-19 19:04:28 +0200 |
commit | b0dd6901d54e687571e44c4fa1d9c7db0d00e299 (patch) | |
tree | b23f9caac031a8bc5c3926c3aa182ef87b0c59a7 /numpy/testing/utils.py | |
parent | 46a3fc10ef27be3637d72b5a6befb440a012dc87 (diff) | |
download | numpy-b0dd6901d54e687571e44c4fa1d9c7db0d00e299.tar.gz |
ENH: accept callable as message in assert_
Allows deferring evaluation until failure.
Used for blocked minmax test which evaluate array representations for
the error message many thousand times accumulating to a full second
useless runtime.
Diffstat (limited to 'numpy/testing/utils.py')
-rw-r--r-- | numpy/testing/utils.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py index 1aee5c507..2a99fe5cb 100644 --- a/numpy/testing/utils.py +++ b/numpy/testing/utils.py @@ -33,6 +33,7 @@ verbose = 0 def assert_(val, msg='') : """ Assert that works in release mode. + Accepts callable msg to allow deferring evaluation until failure. The Python built-in ``assert`` does not work when executing code in optimized mode (the ``-O`` flag) - no byte-code is generated for it. @@ -41,7 +42,11 @@ def assert_(val, msg='') : """ if not val : - raise AssertionError(msg) + try: + smsg = msg() + except TypeError: + smsg = msg + raise AssertionError(smsg) def gisnan(x): """like isnan, but always raise an error if type not supported instead of |