hdmf.testing.testcase module

class hdmf.testing.testcase.TestCase(methodName='runTest')

Bases: TestCase

Extension of unittest’s TestCase to add useful functions for unit testing in HDMF.

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

assertRaisesWith(exc_type, exc_msg, *args, **kwargs)

Asserts the given invocation raises the expected exception. This is similar to unittest’s assertRaises and assertRaisesRegex, but checks for an exact match.

assertWarnsWith(warn_type, exc_msg, *args, **kwargs)

Asserts the given invocation raises the expected warning. This is similar to unittest’s assertWarns and assertWarnsRegex, but checks for an exact match.

assertContainerEqual(container1, container2, ignore_name=False, ignore_hdmf_attrs=False, ignore_string_to_byte=False, message=None)

Asserts that the two AbstractContainers have equal contents. This applies to both Container and Data types.

Parameters:
  • container1 (AbstractContainer) – First container

  • container2 (AbstractContainer) – Second container to compare with container 1

  • ignore_name – whether to ignore testing equality of name of the top-level container

  • ignore_hdmf_attrs – whether to ignore testing equality of HDMF container attributes, such as container_source and object_id

  • ignore_string_to_byte – ignore conversion of str to bytes and compare as unicode instead

  • message – custom additional message to show when assertions as part of this assert are failing

assertBuilderEqual(builder1, builder2, check_path=True, check_source=True, message=None)

Test whether two builders are equal. Like assertDictEqual but also checks type, name, path, and source.

Parameters:
  • builder1 (Builder) – The first builder

  • builder2 (Builder) – The second builder

  • check_path (bool) – Check that the builder.path values are equal

  • check_source (bool) – Check that the builder.source values are equal

  • message (str or None) – Custom message to add when any asserts as part of this assert are failing (default=None)

class hdmf.testing.testcase.H5RoundTripMixin

Bases: object

Mixin class for methods to run a roundtrip test writing a container to and reading the container from an HDF5 file. The setUp, test_roundtrip, and tearDown methods will be run by unittest.

The abstract method setUpContainer needs to be implemented by classes that include this mixin.

Example:

class TestMyContainerRoundTrip(H5RoundTripMixin, TestCase):
    def setUpContainer(self):
        # return the Container to read/write

NOTE: This class is a mix-in and not a subclass of TestCase so that unittest does not discover it, try to run it, and skip it.

setUp()
tearDown()
abstract setUpContainer()

Return the Container to read/write.

test_roundtrip()

Test whether the container read from a written file is the same as the original file.

test_roundtrip_export()

Test whether the container read from a written and then exported file is the same as the original file.

roundtripContainer(cache_spec=False)

Write the container to an HDF5 file, read the container from the file, and return it.

roundtripExportContainer(cache_spec=False)

Write the container to an HDF5 file, read it, export it to a new file, read that file, and return it.

validate(experimental=False)

Validate the written and exported files, if they exist.