tests: Allow tests to add windows to win_registry.
This commit is contained in:
parent
4577659342
commit
4f250ba5d7
@ -84,21 +84,34 @@ def pytest_runtest_setup(item):
|
|||||||
pytest.skip("Can only run when frozen!")
|
pytest.skip("Can only run when frozen!")
|
||||||
|
|
||||||
|
|
||||||
FakeWindow = collections.namedtuple('FakeWindow', ['registry'])
|
class WinRegistryHelper:
|
||||||
|
|
||||||
|
"""Helper class for win_registry."""
|
||||||
|
|
||||||
|
FakeWindow = collections.namedtuple('FakeWindow', ['registry'])
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self._ids = []
|
||||||
|
|
||||||
|
def add_window(self, win_id):
|
||||||
|
assert win_id not in objreg.window_registry
|
||||||
|
registry = objreg.ObjectRegistry()
|
||||||
|
window = self.FakeWindow(registry)
|
||||||
|
objreg.window_registry[win_id] = window
|
||||||
|
self._ids.append(win_id)
|
||||||
|
|
||||||
|
def cleanup(self):
|
||||||
|
for win_id in self._ids:
|
||||||
|
del objreg.window_registry[win_id]
|
||||||
|
|
||||||
|
|
||||||
@pytest.yield_fixture
|
@pytest.yield_fixture
|
||||||
def win_registry():
|
def win_registry():
|
||||||
"""Fixture providing a window registry for win_id 0 and 1."""
|
"""Fixture providing a window registry for win_id 0 and 1."""
|
||||||
registry1 = objreg.ObjectRegistry()
|
helper = WinRegistryHelper()
|
||||||
registry2 = objreg.ObjectRegistry()
|
helper.add_window(0)
|
||||||
window1 = FakeWindow(registry1)
|
yield helper
|
||||||
window2 = FakeWindow(registry2)
|
helper.cleanup()
|
||||||
objreg.window_registry[0] = window1
|
|
||||||
objreg.window_registry[1] = window2
|
|
||||||
yield [window1, window2]
|
|
||||||
del objreg.window_registry[1]
|
|
||||||
del objreg.window_registry[0]
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.yield_fixture
|
@pytest.yield_fixture
|
||||||
|
Loading…
Reference in New Issue
Block a user