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) –

LieGroupOpsType#

alias of Union[LieGroup, float]

KEEP_PATHS = ['.*/__pycache__/.*', '.*\\.pyc']#
static should_update()[source]#
Return type:

bool

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.

Parameters:
Return type:

None

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:
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 | None) –

Return type:

None

make_output_dir(prefix=None, 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 | None) – The prefix for the directory name - a random unique identifier is added to this. Defaults to the name of the test, in snake_case

  • dir – Location of the output directory. Defaults to “/tmp”.

  • directory (Path) –

Returns:

str – The absolute path to the created output directory

Return type:

Path

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:
Return type:

None

compare_or_update_file(path, new_file)[source]#
Parameters:
Return type:

None

compare_or_update_directory(actual_dir, expected_dir)[source]#

Check the contents of actual_dir match expected_dir, OR update the expected directory if the --update flag was passed to the test.

Parameters:
Return type:

None