testing

Extensions of the unittest module.

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: unittest.case.TestCase

A class whose instances are single test cases.

assertAlmostEqual64(self, actual, desired, atol=2e-15, rtol=0.002)

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 and rtol 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

nutils.testing.ContextTestCase

alias of nutils.testing.TestCase