omni.asset_validator.core.tests API

class omni.asset_validator.core.tests.IsAFailure(message: str, at: Optional[str] = None)

IsAFailure let us assert messages and locations of failure to match against the real issue found in Validation Engine. This class is used in conjuntion to ValidationRuleTestCase.assertRule.

message

Regex pattern for the expected failure message.

at

Optional. The expected location of the expected failure.

class omni.asset_validator.core.tests.IsAWarning(message: str, at: Optional[str] = None)

IsAWarning let us assert messages and locations of warnings to match against the real issue found in Validation Engine. This class is used in conjuntion to ValidationRuleTestCase.assertRule.

message

Regex pattern for the expected failure message.

at

Optional. The expected location of the expected failure.

class omni.asset_validator.core.tests.IsAnError(message: str, at: Optional[str] = None)

IsAnError let us assert messages and locations of errors to match against the real issue found in Validation Engine. This class is used in conjuntion to ValidationRuleTestCase.assertRule.

message

Regex pattern for the expected failure message.

at

Optional. The expected location of the expected failure.

class omni.asset_validator.core.tests.ValidationRuleTestCase(*args: Any, **kwargs: Any)

A base class to simplify testing of individual Validation Rules

Rule authors can derive from this class and use the assertions to test the rule produces the expected results.

Example

Define a new Rule, register it, and define a new TestCase class to exercise it.

import omni.asset_validator.core

class MyRuleChecker(omni.asset_validator.core.BaseRuleChecker):
    '''
    Check that all prims are meshes for xforms
    '''

    def CheckPrim(self, prim) -> None:
        self._Msg("Checking prim <%s>." % prim.GetPath())
        if prim.GetTypeName() not in ("Mesh", "Xform"):
            self._AddFailedCheck(
                f"Prim <{prim.GetPath()}> has unsupported type '{prim.GetTypeName()}'."
            )

omni.asset_validator.core.ValidationRulesRegistry.registerRule(MyRuleChecker, "MyOwnRules")

import omni.asset_validator.core.tests

class MyTestCase(omni.asset_validator.core.tests.ValidationRuleTestCase):
    async def testMyRuleChecker(self):
        self.assertRule(
            url='omniverse://localhost/NVIDIA/Samples/Astronaut/Astronaut.usd',
            rule=MyRuleChecker,
            asserts=[
                IsAFailure("Prim.*has unsupported type.*"),
            ]
        )

# run test case via an appropriate TestSuite
assertRule(url: str, rule: Union[omni.asset_validator.core.complianceChecker.BaseRuleChecker, str], asserts: List[omni.asset_validator.core.tests.ruleTest.IsAnIssue]) None

Assert issues from validating one asset using one rule

Derived classes may use this to simplify testing of new rules with less consideration for the structure of omni.asset_validator.core.Results.

Note there will be only one enabled rule for the validation run, so all results will have necessarily been produced by the provided rule or by the engine itself (eg non-existent file).

Parameters
  • url – A single asset to validate

  • rule – Either a BaseRuleChecker derived class or the str class name of such a class

  • asserts – A list of assertions.

assertRuleFailures(url: str, rule: Union[omni.asset_validator.core.complianceChecker.BaseRuleChecker, str], expectedFailures: List[omni.asset_validator.core.tests.ruleTest.IsAFailure]) None

Deprecated since version 0.9.0: Please use assertRule instead.

Assert expected failures from validating one asset using one rule

Derived classes may use this to simplify testing of new rules with less consideration for the structure of omni.asset_validator.core.Results.

Note there will be only one enabled rule for the validation run, so all results will have necessarily been produced by the provided rule or by the engine itself (eg non-existent file).

Parameters
  • url – A single asset to validate

  • rule – Either a BaseRuleChecker derived class or the str class name of such a class

  • expectedFailures – A list of failures (or empty list if it should succeed).

assertSuggestion(url: str, rule: Union[omni.asset_validator.core.complianceChecker.BaseRuleChecker, str], predicate: Optional[omni.asset_validator.core.autofix.IssuePredicate]) None

Assert expected failures from validating one asset using one rule will be fixed using auto fix framework.

Derived classes may use this to simplify testing of new rules with less consideration for the structure of omni.asset_validator.core.IssueFixer.

Note there will be only one enabled rule for the validation run, so all results will have necessarily been produced by the provided rule or by the engine itself (eg non-existent file).

Parameters
  • url – A single asset to validate

  • rule – Either a BaseRuleChecker derived class or the str class name of such a class

  • predicate – A predicate (i.e. Callable[[Issue], bool]) to filter out issues.