Skip to content

test_revit_api_catalog

Revit-hosted check that the Revit API change catalog matches the live API.

The static linter dev/scripts/check_revit_api_compat.py trusts dev/scripts/revit_api_catalog/catalog.json, which is generated offline from each Revit year's RevitAPI/RevitAPIUI assemblies. Running this suite in a given Revit confirms that every cataloged type and member exists exactly when the catalog says it does for that year, catching extraction mistakes and update-release drift that no offline step can see. Run it from the pyRevit DevTools "Revit API Catalog Tests" button in each Revit version you have.

The lint itself runs in CI without Revit; this suite only validates its data. It is opt-in: the "Run All Tests" button leaves it out, because it resolves hundreds of types against whichever Revit build is installed.

Note

Years that only some update releases have an entry in (partial) are not checked, since the result depends on which update is installed. Skips when the catalog is absent (installed builds ship without dev/) or when the running Revit year is outside the cataloged years.

Attributes

CATALOG_PATH = os.path.join(HOME_DIR, 'dev', 'scripts', 'revit_api_catalog', 'catalog.json') module-attribute

MAX_REPORTED = 40 module-attribute

REVIT_NAMESPACES = ('Autodesk.Revit.DB', 'Autodesk.Revit.UI') module-attribute

Classes

RevitApiCatalogTests

Bases: TestCase

Cataloged availability agrees with the running Revit's API.

Methods:

setUpClass() classmethod

Load the catalog, or skip when absent or out of range.

Source code in pyrevitlib/pyrevit/unittests/test_revit_api_catalog.py
@classmethod
def setUpClass(cls):
    """Load the catalog, or skip when absent or out of range."""
    if not os.path.exists(CATALOG_PATH):
        raise unittest.SkipTest("catalog not found: {}".format(CATALOG_PATH))
    with io.open(CATALOG_PATH, encoding="utf-8") as handle:
        cls.catalog = json.load(handle)
    try:
        cls.year = int(HOST_APP.version)
    except (TypeError, ValueError):
        raise unittest.SkipTest(
            "cannot read the Revit year from {!r}".format(HOST_APP.version)
        )
    cls.label = "Revit {}".format(HOST_APP.subversion or cls.year)
    if cls.year not in cls.catalog["years"]:
        raise unittest.SkipTest(
            "Revit {} is outside the catalog ({}-{})".format(
                cls.year, cls.catalog["years"][0], cls.catalog["years"][-1]
            )
        )
test_types_exist_when_cataloged()

A cataloged type is importable exactly in its available years.

Source code in pyrevitlib/pyrevit/unittests/test_revit_api_catalog.py
def test_types_exist_when_cataloged(self):
    """A cataloged type is importable exactly in its available years."""
    problems = []
    all_years = self.catalog["years"]
    for type_name, cls_obj in self._live_types().items():
        entry = self.catalog["types"][type_name]
        expected = _expected(entry, self.year, all_years)
        if expected is not None and expected != (cls_obj is not None):
            problems.append(
                "{}: expected {} in {}".format(
                    type_name, "present" if expected else "absent", self.label
                )
            )
    self.assertFalse(problems, _mismatch_report(problems))
test_members_exist_when_cataloged()

A cataloged member is reachable exactly in its available years.

Source code in pyrevitlib/pyrevit/unittests/test_revit_api_catalog.py
def test_members_exist_when_cataloged(self):
    """A cataloged member is reachable exactly in its available years."""
    problems = []
    all_years = self.catalog["years"]
    for type_name, cls_obj in self._live_types().items():
        if cls_obj is None:
            continue
        type_entry = self.catalog["types"][type_name]
        for member, entry in type_entry.get("members", {}).items():
            if member.startswith("."):
                continue
            expected = _expected(entry, self.year, all_years)
            if expected is not None and expected != hasattr(cls_obj, member):
                problems.append(
                    "{}.{}: expected {} in {}".format(
                        type_name,
                        member,
                        "present" if expected else "absent",
                        self.label,
                    )
                )
    self.assertFalse(problems, _mismatch_report(problems))