symforce.test_util.test_case_mixin module¶
- class SymforceTestCaseMixin(methodName='runTest')[source]¶
Bases:
TestCase
Mixin for SymForce tests, adds useful helpers for code generation
- Parameters:
methodName (
str
) –
- KEEP_PATHS = ['.*/__pycache__/.*', '.*\\.pyc']¶
- __init__(methodName='runTest')[source]¶
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.
- Parameters:
methodName (
str
) –
- static main(*args, **kwargs)[source]¶
Call this to run all tests in scope.
- Parameters:
args (
Any
) –kwargs (
Any
) –
- Return type:
None
- static assertStorageNear(actual, desired, *, places=7, msg='', verbose=True)[source]¶
Check that two elements are close. Handles sequences, scalars, and geometry types using StorageOps.
- Parameters:
actual (
Any
) –desired (
Any
) –places (
int
) –msg (
str
) –verbose (
bool
) –
- Return type:
None
- static assertLieGroupNear(actual, desired, *, places=7, msg='', verbose=True)[source]¶
Check that two LieGroup elements are close.
- static assertArrayEqual(actual, desired, msg='')[source]¶
Called by unittest base class when comparing ndarrays when “assertEqual” is called. By default, “assertEqual” uses the “==” operator, which is not implemented for ndarrays.
- Parameters:
actual (
ndarray
) –desired (
ndarray
) –msg (
str
) –
- Return type:
None
- assertNotEqual(first, second, msg='')[source]¶
Overrides unittest.assertNotEqual to handle ndarrays separately. “assertNotEqual” uses the “!=” operator, but this is not implemented for ndarrays. Instead, we check that np.testing.assert_array_equal raises an assertion error, as numpy testing does not provide a assert_array_not_equal function.
Note that assertNotEqual does not work like assertEqual in unittest. Rather than allowing you to register a custom equality evaluator (e.g. with addTypeEqualityFunc()), assertNotEqual assumes the “!=” can be used with the arguments regardless of type.
- Parameters:
first (
Any
) –second (
Any
) –msg (
str
) –
- Return type:
None
- make_output_dir(prefix, directory=PosixPath('/tmp'))[source]¶
Create a temporary output directory, which will be automatically removed (regardless of exceptions) on shutdown, unless logger.level is DEBUG
- Parameters:
prefix (
str
) – The prefix for the directory name - a random unique identifier is added to thisdir – Location of the output directory. Defaults to “/tmp”.
directory (
Path
) –
- Returns:
The absolute path to the created output directory
- Return type:
str
- setUp()[source]¶
Creates list of temporary directories that will be removed before shutdown (unless debug mode is on)
- Return type:
None
- tearDown()[source]¶
Removes temporary output directories (unless debug mode is on)
- Return type:
None
- compare_or_update(path, data)[source]¶
Compare the given data to what is saved in path, OR update the saved data if the –update flag was passed to the test.
- Parameters:
path (
Union
[str
,PathLike
]) –data (
str
) –
- Return type:
None