omni.asset_validator.core.tests API

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

Failure 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.assertRuleFailures.

message

Regex pattern for the expected failure message.

Type

str

at

Optional. The expected location of the expected failure.

Type

Optional[str]

class omni.asset_validator.core.tests.ValidationRuleTestCase(methodName='runTest')

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

    @staticmethod
    def GetDescription():
        return "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.assertRuleFailures(
            url='omniverse://localhost/NVIDIA/Samples/Astronaut/Astronaut.usd',
            rule=MyRuleChecker,
            expectedFailures=[
                Failure("Prim.*has unsupported type.*"),
            ],
        )

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

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[Callable[[omni.asset_validator.core.autofix.Issue], bool]]) 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.