Testing

Testing utilities for Bio2BEL.

This module has tools for quickly writing unit tests with unittest that involve the usage of a mock data with a Bio2BEL manager.

class bio2bel.testing.TemporaryConnectionMethodMixin(methodName='runTest')[source]

Creates a unittest.TestCase that has a persistent file for use with SQLite during testing.

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.

setUp()[source]

Create a temporary file to use as a persistent database throughout tests in this class.

tearDown()[source]

Close the connection to the database and removes the files created for it.

class bio2bel.testing.TemporaryConnectionMixin(methodName='runTest')[source]

Creates a unittest.TestCase that has a persistent file for use with SQLite during testing.

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.

classmethod setUpClass()[source]

Create a temporary file to use as a persistent database throughout tests in this class.

Subclasses of TemporaryCacheClsMixin can extend TemporaryCacheClsMixin.setUpClass() to populate the database.

classmethod tearDownClass()[source]

Close the connection to the database and removes the files created for it.

class bio2bel.testing.MockConnectionMixin(methodName='runTest')[source]

Allows for testing with a consistent connection without changing the configuration.

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.

setUp()[source]

Set up the test with a mock connection string.

Add two class-level variables: mock_global_connection and mock_module_connection that can be used as context managers to mock the bio2bel connection getter functions.

class bio2bel.testing.AbstractTemporaryCacheMethodMixin(methodName='runTest')[source]

Allows for testing with a consistent connection and creation of a manager class wrapping that connection.

Requires the class variable Manager to be overriden with the class corresponding to the manager to be used that is a subclass of bio2bel.AbstractManager.

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.

setUp()[source]

Set up the class with the given manager and allows an optional populate hook to be overridden.

tearDown()[source]

Close the connection in the manager and deletes the temporary database.

populate()[source]

Populate the database.

This stub should be overridden.

Return type

None

class bio2bel.testing.AbstractTemporaryCacheClassMixin(methodName='runTest')[source]

Allows for testing with a consistent connection and creation of a manager class wrapping that connection.

Requires the class variable Manager to be overriden with the class corresponding to the manager to be used that is a subclass of bio2bel.AbstractManager.

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.

classmethod setUpClass()[source]

Set up the class with the given manager and allows an optional populate hook to be overridden.

classmethod tearDownClass()[source]

Close the connection in the manager and deletes the temporary database.

classmethod populate()[source]

Populate the database.

This stub should be overridden.

bio2bel.testing.make_temporary_cache_class_mixin(manager_cls)[source]

Build a testing class that has a Bio2BEL manager instance ready to go.

Return type

Type[AbstractTemporaryCacheClassMixin]