Showing the changes to python (1 of 1 file). Show all
Unified · Split
| @@ -0,0 +1,50 @@ | ||
| 1 | +""" | |
| 2 | +This file imports test methods from different testing modules, in this | |
| 3 | +order: | |
| 4 | + | |
| 5 | + - if 'nose2' is found in the list of loaded module, use it | |
| 6 | + - otherwise, try using 'pytest' | |
| 7 | + - if that also fails, fallback to 'numpy.testing' | |
| 8 | +""" | |
| 9 | + | |
| 10 | +import sys | |
| 11 | + | |
| 12 | +_has_pytest = False | |
| 13 | +_has_nose2 = False | |
| 14 | + | |
| 15 | +# if nose2 has already been imported, use it | |
| 16 | +if 'nose2' in sys.modules: | |
| 17 | + from nose2.tools import params, such | |
| 18 | + def parametrize(argnames, argvalues): | |
| 19 | + return params(*argvalues) | |
| 20 | + assert_raises = such.helper.assertRaises | |
| 21 | + assert_warns = such.helper.assertWarns | |
| 22 | + skipTest = such.helper.skipTest | |
| 23 | + _has_nose2 = True | |
| 24 | + print ('using nose2') | |
| 25 | + | |
| 26 | +# otherwise, check if we have pytest | |
| 27 | +if not _has_nose2: | |
| 28 | + try: | |
| 29 | + import pytest | |
| 30 | + parametrize = pytest.mark.parametrize | |
| 31 | + _has_pytest = True | |
| 32 | + assert_raises = pytest.raises | |
| 33 | + assert_warns = pytest.warns | |
| 34 | + skipTest = pytest.skip | |
| 35 | + print ('using pytest') | |
| 36 | + except: | |
| 37 | + pass | |
| 38 | + | |
| 39 | +# otherwise fallback on numpy.testing | |
| 40 | +if not _has_pytest and not _has_nose2: | |
| 41 | + from numpy.testing import dec, assert_raises, assert_warns | |
| 42 | + from numpy.testing import SkipTest | |
| 43 | + parametrize = dec.parametrize | |
| 44 | + def skipTest(msg): | |
| 45 | + raise SkipTest(msg) | |
| 46 | + print ('using numpy') | |
| 47 | + | |
| 48 | +# always use numpy's assert_equal | |
| 49 | +import numpy | |
| 50 | +assert_equal = numpy.testing.assert_equal | |