usdex.test#
usdex.test provides unittest
based test
utilities for validating in-memory OpenUSD data for consistency and correctness.
Classes:
|
A unittest base class to simplify testing common USD authoring functionality |
|
A context manager to capture and assert expected Tf.Diagnostics and Tf.ErrorMarks |
|
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
(layer, encoding)Assert that the given layer uses the given encoding type
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 timeassertMatricesAlmostEqual
(first, second[, ...])Assert that all 16 values of a pair of 4x4 matrices are equal, to a specified number of decimal places
assertVecAlmostEqual
(first, second[, places])Assert that all elements of a Vec are equal, to a specified number of decimal places
tmpLayer
([name, ext])Create a temporary Sdf.Layer on the local filesystem
tmpFile
([name, ext])Create a temporary file on the local filesystem
isUsdOlderThan
(version)Determine if the provided versions 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
(layer)Get the extension of the encoding type used within an SdfLayer
- 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+v1-0-0.475.a0234b12.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]],
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.
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