Skip to content

test_ribbon_control_ids

Hosted tests for the ribbon ids the loader registers for pyRevit's own panels.

Run from Revit via the DevTools "Ribbon Control Id Tests" button (zero-doc context). The module is Integration level, so "Run All Tests" skips it. They assert that the control id of every command in the pyRevit tab resolves to the ribbon item Revit registered, whatever the pyRevit user_locale: panels are created under their folder name and only display the localized title (#4035).

Attributes

TEST_ENVIRONMENT = 'Revit' module-attribute

TEST_LEVEL = 'Integration' module-attribute

PYREVIT_TAB_PREFIX = 'CustomCtrl_%CustomCtrl_%pyRevit%' module-attribute

Classes

ControlIdTests

Bases: TestCase

Command control ids equal the ids of the ribbon items Revit registered.

Methods:

test_pyrevit_tab_commands_are_loaded()

The pyRevit tab contributes commands, so the checks below are not vacuous.

Source code in pyrevitlib/pyrevit/unittests/test_ribbon_control_ids.py
def test_pyrevit_tab_commands_are_loaded(self):
    """The pyRevit tab contributes commands, so the checks below are not vacuous."""
    self.assertTrue(_pyrevit_tab_commands())
test_control_id_matches_a_ribbon_item()

Every pyRevit tab command's control id is the id of a ribbon item.

Source code in pyrevitlib/pyrevit/unittests/test_ribbon_control_ids.py
def test_control_id_matches_a_ribbon_item(self):
    """Every pyRevit tab command's control id is the id of a ribbon item."""
    ribbon_item_ids = _ribbon_item_ids()
    missing = sorted(
        command.control_id
        for command in _pyrevit_tab_commands()
        if command.control_id not in ribbon_item_ids
    )
    self.assertEqual([], missing[:10], "{} unmatched".format(len(missing)))
test_control_id_resolves_to_a_command_id()

Every pyRevit tab command's control id resolves through LookupCommandId.

Source code in pyrevitlib/pyrevit/unittests/test_ribbon_control_ids.py
def test_control_id_resolves_to_a_command_id(self):
    """Every pyRevit tab command's control id resolves through LookupCommandId."""
    from pyrevit.api import UI

    missing = sorted(
        command.control_id
        for command in _pyrevit_tab_commands()
        if UI.RevitCommandId.LookupCommandId(command.control_id) is None
    )
    self.assertEqual([], missing[:10], "{} unresolved".format(len(missing)))