| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | import unittest |
| | import FreeCAD |
| | import FreeCADGui |
| | from bimtests.TestArchBase import TestArchBase |
| |
|
| |
|
| | class TestArchBaseGui(TestArchBase): |
| | """ |
| | The base class for all Arch/BIM GUI unit tests. |
| | It inherits from TestArchBase to handle document setup and adds |
| | GUI-specific initialization by activating the BIM workbench. |
| | """ |
| |
|
| | @classmethod |
| | def setUpClass(cls): |
| | """ |
| | Ensure the GUI is available and activate the BIM workbench once |
| | before any tests in the inheriting class are run. |
| | """ |
| | if not FreeCAD.GuiUp: |
| | raise unittest.SkipTest("Cannot run GUI tests in a CLI environment.") |
| |
|
| | |
| | |
| | |
| | |
| |
|
| | def setUp(self): |
| | """ |
| | Run the parent's setup to create the uniquely named document. |
| | The workbench is already activated by setUpClass. |
| | """ |
| | super().setUp() |
| |
|
| | def tearDown(self): |
| | """ |
| | Ensure GUI events are processed and dialogs closed before the document is destroyed. |
| | This prevents race conditions where pending GUI tasks try to access a closed document. |
| | """ |
| | |
| | self.pump_gui_events() |
| |
|
| | |
| | if FreeCAD.GuiUp: |
| | FreeCADGui.Control.closeDialog() |
| |
|
| | super().tearDown() |
| |
|
| | def pump_gui_events(self, timeout_ms=200): |
| | """Run the Qt event loop briefly so queued GUI callbacks execute. |
| | |
| | This helper starts a QEventLoop and quits it after `timeout_ms` milliseconds using |
| | QTimer.singleShot. Any exception (e.g. missing Qt in the environment) is silently ignored so |
| | tests can still run in pure-CLI environments where the GUI isn't available. |
| | """ |
| | try: |
| | from PySide import QtCore |
| |
|
| | loop = QtCore.QEventLoop() |
| | QtCore.QTimer.singleShot(int(timeout_ms), loop.quit) |
| | loop.exec_() |
| | except Exception: |
| | |
| | pass |
| |
|