Hosted unit tests for the output window API.
Run from Revit via the DevTools "Output Window Tests" button (zero-doc
context) or the "Run All Tests" aggregator. The tests exercise window
metadata, buffered printing, progress bar control, and chart factory
methods without requiring a document.
Visual correctness (styling, ordering, emoji rendering) is covered by
the print-based regression buttons under Log Output Tests and by the
"Test Output Stream" button; this suite only asserts programmatic
behavior.
Classes
Bases: TestCase
Window identity, title, size, and debug-mode handling.
Grab the shared output window instance.
Source code in pyrevitlib/pyrevit/unittests/test_output_window.py
| def setUp(self):
"""Grab the shared output window instance."""
from pyrevit import script
self.output = script.get_output()
|
Repeated get_output calls return the same output window.
Source code in pyrevitlib/pyrevit/unittests/test_output_window.py
| def test_output_is_singleton(self):
"""Repeated get_output calls return the same output window."""
from pyrevit import script
self.assertEqual(self.output.output_id, script.get_output().output_id)
|
Output window exposes a non-empty unique id.
Source code in pyrevitlib/pyrevit/unittests/test_output_window.py
| def test_output_uniqueid(self):
"""Output window exposes a non-empty unique id."""
self.assertTrue(self.output.output_uniqueid)
|
A stored title is retrievable via get_title.
Source code in pyrevitlib/pyrevit/unittests/test_output_window.py
| def test_title_round_trip(self):
"""A stored title is retrievable via get_title."""
self.output.set_title("pyRevit Output Window Tests")
self.assertEqual("pyRevit Output Window Tests", self.output.get_title())
|
A stored width is retrievable as a positive number.
Hosts may adjust the requested width (DPI scaling, window
chrome), so only the numeric round trip is asserted.
Source code in pyrevitlib/pyrevit/unittests/test_output_window.py
| def test_width_round_trip(self):
"""A stored width is retrievable as a positive number.
Hosts may adjust the requested width (DPI scaling, window
chrome), so only the numeric round trip is asserted.
"""
original_width = self.output.get_width()
self.assertIsInstance(original_width, (int, float))
self.output.set_width(600)
try:
new_width = self.output.get_width()
self.assertIsInstance(new_width, (int, float))
self.assertGreater(new_width, 0)
finally:
self.output.set_width(original_width)
|
Debug mode toggles are reflected by the getter.
Source code in pyrevitlib/pyrevit/unittests/test_output_window.py
| def test_debug_mode_round_trip(self):
"""Debug mode toggles are reflected by the getter."""
original_state = self.output.debug_mode
try:
self.output.debug_mode = True
self.assertTrue(self.output.debug_mode)
self.output.debug_mode = False
self.assertFalse(self.output.debug_mode)
finally:
self.output.debug_mode = original_state
|
Head html getter returns a string.
Source code in pyrevitlib/pyrevit/unittests/test_output_window.py
| def test_get_head_html_returns_string(self):
"""Head html getter returns a string."""
self.assertIsInstance(self.output.get_head_html(), str)
|
Open windows report False for user-closed state.
Source code in pyrevitlib/pyrevit/unittests/test_output_window.py
| def test_is_closed_by_user_returns_bool(self):
"""Open windows report False for user-closed state."""
self.assertFalse(self.output.is_closed_by_user)
|
OutputWindowPrintTests
Bases: TestCase
Buffered printing methods complete without error.
Methods:
setUp()
Grab the shared output window instance.
Source code in pyrevitlib/pyrevit/unittests/test_output_window.py
| def setUp(self):
"""Grab the shared output window instance."""
from pyrevit import script
self.output = script.get_output()
|
test_print_md()
Markdown printing completes without error.
Source code in pyrevitlib/pyrevit/unittests/test_output_window.py
| def test_print_md(self):
"""Markdown printing completes without error."""
self.assertIsNone(self.output.print_md("**bold** _italic_"))
|
test_print_html()
Raw html printing completes without error.
Source code in pyrevitlib/pyrevit/unittests/test_output_window.py
| def test_print_html(self):
"""Raw html printing completes without error."""
self.assertIsNone(self.output.print_html('<div style="color:red">html</div>'))
|
test_print_code()
Code block printing completes without error.
Source code in pyrevitlib/pyrevit/unittests/test_output_window.py
| def test_print_code(self):
"""Code block printing completes without error."""
self.assertIsNone(self.output.print_code("print('hello')"))
|
test_print_table()
Tabular data printing accepts columns and formats.
Source code in pyrevitlib/pyrevit/unittests/test_output_window.py
| def test_print_table(self):
"""Tabular data printing accepts columns and formats."""
self.assertIsNone(
self.output.print_table(
[[1, 2, 3], [4, 5, 6]],
columns=["C1", "C2", "C3"],
formats=["{}", "{}", "{}%"],
title="Output Window Tests Table",
)
)
|
test_insert_divider()
Divider insertion completes without error.
Source code in pyrevitlib/pyrevit/unittests/test_output_window.py
| def test_insert_divider(self):
"""Divider insertion completes without error."""
self.assertIsNone(self.output.insert_divider())
|
test_linkify_returns_html_str()
Linkified element ids render as clickable html anchors.
Source code in pyrevitlib/pyrevit/unittests/test_output_window.py
| def test_linkify_returns_html_str(self):
"""Linkified element ids render as clickable html anchors."""
from pyrevit import DB
from pyrevit.output.linkmaker import PROTOCOL_NAME
element_id = DB.ElementId(DB.BuiltInCategory.OST_Walls)
link = self.output.linkify(element_id)
self.assertIsInstance(link, str)
self.assertIn(PROTOCOL_NAME, link)
self.assertIn("element[]=", link)
|
test_linkify_registers_ids_that_do_not_fit_in_a_link()
Element ids beyond the url limit resolve through the output window.
Source code in pyrevitlib/pyrevit/unittests/test_output_window.py
| def test_linkify_registers_ids_that_do_not_fit_in_a_link(self):
"""Element ids beyond the url limit resolve through the output window."""
from pyrevit.compat import get_elementid_from_value_func
token = self.output.register_element_ids("1,2,3")
self.assertTrue(token.isdigit(), "token: {}".format(token))
elementid_from_value = get_elementid_from_value_func()
element_ids = [elementid_from_value(1000000 + i) for i in range(500)]
link = self.output.linkify(element_ids)
self.assertNotIn("element[]=", link)
self.assertIn("elements=", link)
self.assertIn("500 elements", link)
|
test_registered_link_selects_the_original_elements()
Clicking a token link selects every registered element, and only those.
Source code in pyrevitlib/pyrevit/unittests/test_output_window.py
| def test_registered_link_selects_the_original_elements(self):
"""Clicking a token link selects every registered element, and only those."""
import re
from System import Array
from System.Collections.Generic import List
from pyrevit import DB, HOST_APP
from pyrevit.compat import get_elementid_value_func
if HOST_APP.uidoc is None:
self.skipTest("selecting elements needs an open document")
element_ids = list(
DB.FilteredElementCollector(HOST_APP.doc)
.WhereElementIsNotElementType()
.ToElementIds()
)
if len(element_ids) < 500:
self.skipTest("the open document has too few elements for a long link")
window = self.output.window
process_url = (
window.GetType()
.Assembly.GetType("PyRevitLabs.PyRevit.Runtime.ScriptConsoleUtils")
.GetMethod("ProcessUrl")
)
def click(url):
process_url.Invoke(None, Array[object]([HOST_APP.uiapp, url, window]))
def select(ids):
HOST_APP.uidoc.Selection.SetElementIds(List[DB.ElementId](ids))
get_value = get_elementid_value_func()
def values(ids):
return set(get_value(eid) for eid in ids)
def selected():
return values(HOST_APP.uidoc.Selection.GetElementIds())
link = self.output.linkify(element_ids)
select_url, show_url = re.findall(r'href="([^"]+)"', link)
self.assertEqual(
re.search(r"elements=(\d+)", select_url).group(1),
re.search(r"elements=(\d+)", show_url).group(1),
)
select([])
click(select_url)
self.assertEqual(values(element_ids), selected())
select(element_ids[:1])
click(select_url + "&append=true")
self.assertEqual(values(element_ids), selected())
select(element_ids[:2])
click("revit://outputhelpers?&command=select&elements=0&show=false")
self.assertEqual(values(element_ids[:2]), selected())
select([])
|
OutputWindowProgressTests
Bases: TestCase
Progress bar control methods complete without error.
Methods:
setUp()
Grab the shared output window instance.
Source code in pyrevitlib/pyrevit/unittests/test_output_window.py
| def setUp(self):
"""Grab the shared output window instance."""
from pyrevit import script
self.output = script.get_output()
|
test_update_progress()
Progress updates accept current and max values.
Source code in pyrevitlib/pyrevit/unittests/test_output_window.py
| def test_update_progress(self):
"""Progress updates accept current and max values."""
self.assertIsNone(self.output.update_progress(50, 100))
|
test_indeterminate_progress()
Indeterminate progress state toggles without error.
Source code in pyrevitlib/pyrevit/unittests/test_output_window.py
| def test_indeterminate_progress(self):
"""Indeterminate progress state toggles without error."""
self.assertIsNone(self.output.indeterminate_progress(True))
self.assertIsNone(self.output.indeterminate_progress(False))
|
test_hide_unhide_reset_progress()
Hide/unhide/reset progress cycle without error.
Source code in pyrevitlib/pyrevit/unittests/test_output_window.py
| def test_hide_unhide_reset_progress(self):
"""Hide/unhide/reset progress cycle without error."""
self.assertIsNone(self.output.hide_progress())
self.assertIsNone(self.output.unhide_progress())
self.assertIsNone(self.output.reset_progress())
|
OutputWindowLogPanelTests
Bases: TestCase
Log panel and styled log record methods complete without error.
Methods:
setUp()
Grab the shared output window instance.
Source code in pyrevitlib/pyrevit/unittests/test_output_window.py
| def setUp(self):
"""Grab the shared output window instance."""
from pyrevit import script
self.output = script.get_output()
|
test_show_hide_logpanel()
Show/hide log panel cycle without error.
Source code in pyrevitlib/pyrevit/unittests/test_output_window.py
| def test_show_hide_logpanel(self):
"""Show/hide log panel cycle without error."""
self.assertIsNone(self.output.show_logpanel())
self.assertIsNone(self.output.hide_logpanel())
|
test_log_levels()
All styled log record levels render without error.
Source code in pyrevitlib/pyrevit/unittests/test_output_window.py
| def test_log_levels(self):
"""All styled log record levels render without error."""
self.assertIsNone(self.output.log_debug("test debug"))
self.assertIsNone(self.output.log_info("test info"))
self.assertIsNone(self.output.log_success("test success"))
self.assertIsNone(self.output.log_warning("test warning"))
self.assertIsNone(self.output.log_error("test error"))
|
OutputWindowChartFactoryTests
Bases: TestCase
Chart factory methods produce configurable chart objects.
Methods:
setUp()
Grab the shared output window instance.
Source code in pyrevitlib/pyrevit/unittests/test_output_window.py
| def setUp(self):
"""Grab the shared output window instance."""
from pyrevit import script
self.output = script.get_output()
|
test_make_chart()
Generic charts expose data, options, and draw.
Source code in pyrevitlib/pyrevit/unittests/test_output_window.py
| def test_make_chart(self):
"""Generic charts expose data, options, and draw."""
chart = self.output.make_chart()
self.assertIsNotNone(chart)
self.assertIsNotNone(chart.data)
self.assertIsNotNone(chart.options)
self.assertTrue(callable(chart.draw))
|
test_make_line_chart()
Line charts are created with the line chart type.
Source code in pyrevitlib/pyrevit/unittests/test_output_window.py
| def test_make_line_chart(self):
"""Line charts are created with the line chart type."""
from pyrevit.coreutils.charts import LINE_CHART
chart = self.output.make_line_chart()
self.assertIsNotNone(chart)
self.assertEqual(LINE_CHART, chart.type)
|