usdex.test#

usdex.test provides unittest based test utilities for validating in-memory OpenUSD data for consistency and correctness.

Classes:

TestCase([methodName])

A unittest base class to simplify testing common USD authoring functionality

ScopedDiagnosticChecker(testCase, expected, ...)

A context manager to capture and assert expected Tf.Diagnostics and Tf.ErrorMarks

DefineFunctionTestCase([methodName])

Class to make assertions that should be valid for all usdex functions that define typed prims

class usdex.test.TestCase(methodName='runTest')#

Bases: TestCase

A unittest base class to simplify testing common USD authoring functionality

Attributes:

maxDiff

See unittest.TestCase.maxDiff documentation

defaultPrimName

The default prim name to be used when configuring a Usd.Stage

defaultUpAxis

The default Up Axis to be used when configuring a Usd.Stage

defaultLinearUnits

The default Linear Units to be used when configuring a Usd.Stage

defaultAuthoringMetadata

The default authoring metadata to be used when configuring a Usd.Stage

defaultValidationIssuePredicates

A list of callables to determine if certain USD validation Issues should be ignored for this TestCase

Methods:

setUpClass()

Hook method for setting up class fixture before running tests in the class.

setUp()

Hook method for setting up the test fixture before exercising it.

assertIsValidUsd(asset[, issuePredicates, msg])

Assert that given asset passes all enabled validation rules

assertIsInvalidUsd(asset, issuePredicates)

Assert that given asset reported with issuePredicates

assertUsdLayerEncoding(**kwargs)

assertUsdLayerEncoding was deprecated in v2.2 and will be removed in the future.

assertSdfLayerIdentifier(layer, identifier)

Assert that the given layer has the expected identifier

assertAttributeHasAuthoredValue(attr[, time])

Asserts that a Usd.Attribute has a value authored at a given time

assertMatricesAlmostEqual(**kwargs)

assertMatricesAlmostEqual was deprecated in v2.2 and will be removed in the future.

assertRotationsAlmostEqual(rot1, rot2[, ...])

Assert two rotations are almost equal (same concrete type required).

assertVecAlmostEqual(**kwargs)

assertVecAlmostEqual was deprecated in v2.2 and will be removed in the future.

tmpLayer([name, ext])

Create a temporary Sdf.Layer on the local filesystem

tmpFile([name, ext])

Create a temporary file on the local filesystem

tmpDir([name])

Create a temporary directory on the local filesystem

isUsdOlderThan(version)

Determine if the provided version is older than the current USD runtime

tmpBaseDir()

Get the path of the base temp directory.

tearDownClass()

Hook method for deconstructing the class fixture after running all tests in the class.

getUsdEncoding(**kwargs)

getUsdEncoding was deprecated in v2.2 and will be removed in the future.

maxDiff = None#

See unittest.TestCase.maxDiff documentation

defaultPrimName = 'Root'#

The default prim name to be used when configuring a Usd.Stage

defaultUpAxis = 'Y'#

The default Up Axis to be used when configuring a Usd.Stage

defaultLinearUnits = 1.0#

The default Linear Units to be used when configuring a Usd.Stage

defaultAuthoringMetadata = 'usdex_ver: 2.2.0, usd_ver: (0, 25, 5), python_ver: 3.10'#

The default authoring metadata to be used when configuring a Usd.Stage

defaultValidationIssuePredicates = []#

A list of callables to determine if certain USD validation Issues should be ignored for this TestCase

classmethod setUpClass()#

Hook method for setting up class fixture before running tests in the class.

setUp()#

Hook method for setting up the test fixture before exercising it.

assertIsValidUsd(
asset: str | Stage,
issuePredicates: List | None = None,
msg: str | None = None,
)#

Assert that given asset passes all enabled validation rules

Parameters:
  • asset – The Asset to validate. Either a Usd.Stage object or a path to a USD Layer.

  • issuePredicates – Optional List of additional callables - func(issue) that are used to check if the issue can be bypassed. The default list of IssuePredicates will always be enabled.

  • msg – Optional message to report while validation failed.

assertIsInvalidUsd(
asset: str | Stage,
issuePredicates: IssuePredicates,
)#

Assert that given asset reported with issuePredicates

Parameters:
  • asset – The Asset to validate. Either a Usd.Stage object or a path to a USD Layer.

  • issuePredicates (List) – List of omni.asset_validator.IssuePredicates.

assertUsdLayerEncoding(**kwargs)#

assertUsdLayerEncoding was deprecated in v2.2 and will be removed in the future. Use usdex.core.getUsdLayerEncoding instead

assertSdfLayerIdentifier(layer, identifier)#

Assert that the given layer has the expected identifier

Parameters:
  • layer – The Sdf.Layer to check

  • identifier – The expected identifier string

assertAttributeHasAuthoredValue(
attr: Attribute,
time=Usd.TimeCode.Default(),
)#

Asserts that a Usd.Attribute has a value authored at a given time

Parameters:
  • attr – The Usd.Attribute to check

  • time – The Usd.TimeCode at which to check for an authored value (default: Usd.TimeCode.Default())

assertMatricesAlmostEqual(**kwargs)#

assertMatricesAlmostEqual was deprecated in v2.2 and will be removed in the future. Use Gf.IsClose instead

assertRotationsAlmostEqual(
rot1: Rotation | Quatf | Quatd,
rot2: Rotation | Quatf | Quatd,
tolerance: float = 1e-06,
)#

Assert two rotations are almost equal (same concrete type required).

Note

Rotations must be the same class (Rotation vs Quatf vs Quatd). Quaternions with opposite signs/sense are treated as different.

Parameters:
  • rot1 – The first rotation to compare

  • rot2 – The second rotation to compare

  • tolerance – A non-negative threshold for comparing values (default: 1e-6)

assertVecAlmostEqual(**kwargs)#

assertVecAlmostEqual was deprecated in v2.2 and will be removed in the future. Use Gf.IsClose instead

tmpLayer(name: str = '', ext: str = 'usda') Layer#

Create a temporary Sdf.Layer on the local filesystem

Parameters:
  • name – an optional identifier prefix. If not provided the test name will be used

  • ext – an optional file extension (excluding .) which must match a registered Sdf.FileFormatPlugin

Returns:

The Sdf.Layer object

tmpFile(name: str = '', ext: str = '') str#

Create a temporary file on the local filesystem

Parameters:
  • name – an optional filename prefix. If not provided the test name will be used

  • ext – an optional file extension (excluding .)

Returns:

The filesystem path

tmpDir(name: str = '') str#

Create a temporary directory on the local filesystem

Parameters:

name – an optional directory name. If not provided the test name will be used

Returns:

The filesystem path

static isUsdOlderThan(version: str)#

Determine if the provided version is older than the current USD runtime

Parameters:

version – The version string to compare against the current USD runtime (e.g. ‘21.08.3’)

Returns:

True if the current USD runtime is older than the provided version

static tmpBaseDir() str#

Get the path of the base temp directory. All temp files and directories in the same process will be created under this directory.

Returns:

The filesystem path

classmethod tearDownClass()#

Hook method for deconstructing the class fixture after running all tests in the class.

getUsdEncoding(**kwargs)#

getUsdEncoding was deprecated in v2.2 and will be removed in the future. Use usdex.core.getUsdLayerEncoding instead

class usdex.test.ScopedDiagnosticChecker(testCase, expected: ~typing.List[~typing.Tuple[~pxr.Tf.DiagnosticType, str]], level: ~usdex.core._usdex_core.DiagnosticsLevel = <DiagnosticsLevel.eStatus: 3>)#

Bases: object

A context manager to capture and assert expected Tf.Diagnostics and Tf.ErrorMarks

Construct a ScopedDiagnosticChecker with a unittest.TestCase instance and a list of expected diagnostic messages.

Each Tuple must contain:

  • One Tf.DiagnosticType (e.g Tf.TF_DIAGNOSTIC_STATUS_TYPE)

  • A regex pattern matching the expected diagnostic commentary (message)

On context exit, the ScopedDiagnosticChecker will assert that all expected Tf.Diagnostics and Tf.ErrorMarks were emmitted.

Note

Any Tf.ErrorMarks will be diagnosed before any general Tf.Diagnostics. The supplied list of expected values should account for this.

Parameters:
  • testCase – The unittest.TestCase instance to use for assertions.

  • expected – A list of tuples containing the expected diagnostic type and commentary pattern.

  • level – The minimum severity of diagnostics to check for. Defaults to usdex.core.DiagnosticsLevel.eStatus.

Example

import unittest

import usdex.test
from pxr import Tf

class MyTestCase(unittest.TestCase):
    def testDiagnostics(self):
        with usdex.test.ScopedDiagnosticChecker(self, [(Tf.TF_DIAGNOSTIC_WARNING_TYPE, ".*foo")]):
            Tf.Warn("This message ends in foo")
class usdex.test.DefineFunctionTestCase(methodName='runTest')#

Bases: TestCase

Class to make assertions that should be valid for all usdex functions that define typed prims

This class inherits from usdex.test.TestCase and adds several abstract properties that must be overridden by derived classes in order to configure the expected results of a default “define” operation.

It also adds 2 useful assertions: assertDefineFunctionSuccess and assertDefineFunctionFailure and adds several concrete test method implementations to cover scenarios that all “define” functions must adhere to.

Attributes:

defineFunc

The function used to define the prim

requiredArgs

A tuple of valid values for the required arguments

schema

The class that the return value should be an instance of

typeName

The type name that the defined prim should have

requiredPropertyNames

A set of property names that the defined prim should have

Methods:

createTestStage()

Create an in memory stage holding a range of prims that are useful for testing

assertDefineFunctionSuccess(result)

Assert that the result returned represents success

assertDefineFunctionFailure(result)

Assert that the result returned represents a failure

abstract property defineFunc#

The function used to define the prim

abstract property requiredArgs#

A tuple of valid values for the required arguments

abstract property schema#

The class that the return value should be an instance of

abstract property typeName#

The type name that the defined prim should have

abstract property requiredPropertyNames#

A set of property names that the defined prim should have

createTestStage()#

Create an in memory stage holding a range of prims that are useful for testing

assertDefineFunctionSuccess(result)#

Assert that the result returned represents success

assertDefineFunctionFailure(result)#

Assert that the result returned represents a failure