test_revit_handle_contract
Exercise production host accessors without importing Revit-dependent modules.
Only the selected production definitions are compiled; their dependencies use small host doubles. This keeps None and missing-builtin tests isolated from the process-wide builtins used by live engines.
Attributes
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..'))
module-attribute
SimpleNamespace = _Namespace
module-attribute
Classes
HostHandleTests
Bases: TestCase
Cover defined, missing, legacy and event-limited host handles.
Methods:
setUp()
Load fresh production definitions for every test.
Source code in pyrevitlib/pyrevit/unittests/test_revit_handle_contract.py
test_missing_builtin()
Absent handles preserve the safe accessor subset.
test_null_builtin()
test_live_ui_handle()
UI accessors and application metadata follow the injected handle.
Source code in pyrevitlib/pyrevit/unittests/test_revit_handle_contract.py
test_legacy_application()
Third-party DB handles retain application access without UI access.
Source code in pyrevitlib/pyrevit/unittests/test_revit_handle_contract.py
test_handle_is_read_again()
Cached Python modules observe the next execution's builtin.
Source code in pyrevitlib/pyrevit/unittests/test_revit_handle_contract.py
test_db_event_document_refusal()
API exceptions degrade UI-document access without losing the app.
Source code in pyrevitlib/pyrevit/unittests/test_revit_handle_contract.py
test_event_document_property_fallback()
DB event arguments provide the document when the UI cannot.
Source code in pyrevitlib/pyrevit/unittests/test_revit_handle_contract.py
test_event_document_method_fallback()
DocumentChanged-style GetDocument arguments remain reachable.
Source code in pyrevitlib/pyrevit/unittests/test_revit_handle_contract.py
test_none_metadata_is_safe()
Metadata returns None and version comparisons return False without a host.
Source code in pyrevitlib/pyrevit/unittests/test_revit_handle_contract.py
VersionHandleTests
Bases: TestCase
Cover compatibility version dispatch independently of CLR imports.
Methods:
test_all_supported_shapes()
UI, DB, controlled, unknown, missing and None handles dispatch safely.
Source code in pyrevitlib/pyrevit/unittests/test_revit_handle_contract.py
RpwHandleTests
Bases: TestCase
Cover RPW fallback and document safety without loading its import graph.
Methods:
setUp()
Compile the production wrapper with inert external dependencies.
Source code in pyrevitlib/pyrevit/unittests/test_revit_handle_contract.py
test_null_and_missing_use_dynamo()
Missing pyRevit handles do not suppress the Dynamo fallback.
Source code in pyrevitlib/pyrevit/unittests/test_revit_handle_contract.py
test_live_handle_precedes_dynamo()
The injected handle wins over an available Dynamo handle.
Source code in pyrevitlib/pyrevit/unittests/test_revit_handle_contract.py
test_missing_dynamo_is_safe()
Unavailable fallback reports no host.
Source code in pyrevitlib/pyrevit/unittests/test_revit_handle_contract.py
test_none_and_refused_document()
Both absent and event-limited UI handles yield no document.
Source code in pyrevitlib/pyrevit/unittests/test_revit_handle_contract.py
test_live_document()
The active document remains available for command execution.
test_cached_handle_follows_reinjection()
Cached RPW instances follow new and null builtins.
Source code in pyrevitlib/pyrevit/unittests/test_revit_handle_contract.py
test_cached_wrapper_adopts_late_pyrevit_handle()
A wrapper initialized without a host adopts a later pyRevit handle.
Source code in pyrevitlib/pyrevit/unittests/test_revit_handle_contract.py
test_sphinx_compat_import_without_imp()
The compatibility module imports on Python versions without imp.
Source code in pyrevitlib/pyrevit/unittests/test_revit_handle_contract.py
test_forms_environment_members_are_class_attributes()
Python.NET resolves Environment as a CLR type, not a module.
Source code in pyrevitlib/pyrevit/unittests/test_revit_handle_contract.py
test_cpython_ui_import_does_not_load_ironpython_forms()
RPW host imports avoid forms that Python.NET cannot construct.