testing¶
Extensions of the unittest
module.
- class nutils.testing.PrintHandler(level=0)¶
Bases:
Handler
similar to StreamHandler except using always the current sys.stdout
- nutils.testing.parametrize(TestCase)¶
Parametrize a
unittest.TestCase
.>>> @parametrize ... class TestSomething(unittest.TestCase): ... def test_equality(self): ... self.assertEqual(self.x, self.y) >>> TestSomething(x=1, y=1) >>> TestSomething(x=2, y=2)
- class nutils.testing.TestCase(methodName='runTest')¶
Bases:
TestCase
A class whose instances are single test cases.
All
nutils.warnings.NutilsWarning
are turned into an exception by default. Usedef test(self): with TestCase.assertWarns(...): ...
to assert expected warnings. Use
def test(self): with warnings.catch_warnings(): warnings.simplefilter('ignore', ...) ...
to ignore warnings locally or
def setUp(self): super().setUp() warnings.simplefilter('ignore', ...)
to ignore warnings for the entire class.
- assertAlmostEqual64(self, actual, desired, *, atol=2e-15, rtol=0.002, dtype='int16')¶
Assert numerical equivalence with packed data.
Test closeness of
actual
todesired
data, where the latter are specified as a base64 packed data string (seenutils.numeric.pack()
andnutils.numeric.unpack()
for details on packing). The primary use case is embedded regression testing.The
atol
,rtol
anddtype
arguments are used for both unpacking and equivalence testing and cannot be changed independently of the base64 string. Doing so will raise an exception with a suggested update.