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. Use

def 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 to desired data, where the latter are specified as a base64 packed data string (see nutils.numeric.pack() and nutils.numeric.unpack() for details on packing). The primary use case is embedded regression testing.

The atol, rtol and dtype 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.

Parameters:
  • actual (float array) – The obtained data.

  • desired (str) – The desired data in the form of a base64 string.

  • atol (float) – Absolute tolerance

  • rtol (float) – Relative tolerance

  • dtype (str) – Packed dtype

nutils.testing.ContextTestCase

alias of TestCase