usdex.test#

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

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

A unittest base class to simplify testing common USD authoring functionality

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: 1.0.0-rc3+v100-rc3.421.200db8ea.gl, usd_ver: (0, 24, 8), 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: AssetType,
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: AssetType,
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(layer: Layer, encoding: str)#

Assert that the given layer uses the given encoding type

assertSdfLayerIdentifier(layer, identifier)#

Assert that the given layer has the expected identifier

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

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

assertMatricesAlmostEqual(first, second, places=12)#

Assert that all 16 values of a pair of 4x4 matrices are equal, to a specified number of decimal places

assertVecAlmostEqual(first, second, places=12)#

Assert that all elements of a Vec are equal, to a specified number of decimal places

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

static isUsdOlderThan(version: str)#

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

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.

static getUsdEncoding(layer: Layer)#

Get the extension of the encoding type used within an SdfLayer

class usdex.test.ScopedDiagnosticChecker(
testCase,
expected: List[Tuple[DiagnosticType, str]],
)#

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.

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')#

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.

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