From 52ec9ed28f79b9457d2b790b7ac03bda61c36869 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 11 Aug 2015 18:13:02 +0200 Subject: [PATCH] Move get_all_objects() tests into a class. --- tests/utils/test_debug.py | 71 +++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 40 deletions(-) diff --git a/tests/utils/test_debug.py b/tests/utils/test_debug.py index 278f21ff1..76fb130cf 100644 --- a/tests/utils/test_debug.py +++ b/tests/utils/test_debug.py @@ -206,53 +206,44 @@ def test_dbg_signal(stubs, args, expected): assert debug.dbg_signal(stubs.FakeSignal(), args) == expected -class ExampleObject(QObject): +class TestGetAllObjects: - def __init__(self, num, parent=None): - self._num = num - super().__init__(parent) + class Object(QObject): - def __repr__(self): - return ''.format(self._num) + def __init__(self, name, parent=None): + self._name = name + super().__init__(parent) + + def __repr__(self): + return '<{}>'.format(self._name) -class ExampleWidget(QObject): + def test_get_all_objects(self, stubs, monkeypatch): + # pylint: disable=unused-variable + widgets = [self.Object('Widget 1'), self.Object('Widget 2')] + app = stubs.FakeQApplication(all_widgets=widgets) + monkeypatch.setattr(debug, 'QApplication', app) - def __init__(self, num, parent=None): - self._num = num - super().__init__(parent) + root = QObject() + o1 = self.Object('Object 1', root) + o2 = self.Object('Object 2', o1) + o3 = self.Object('Object 3', root) - def __repr__(self): - return ''.format(self._num) + expected = textwrap.dedent(""" + Qt widgets - 2 objects: + + + Qt objects - 3 objects: + + + -def test_get_all_objects(stubs, monkeypatch): - # pylint: disable=unused-variable - widgets = [ExampleWidget(1), ExampleWidget(2)] - app = stubs.FakeQApplication(all_widgets=widgets) - monkeypatch.setattr(debug, 'QApplication', app) + global object registry - 0 objects: + """).rstrip('\n') - root = QObject() - o1 = ExampleObject(1, root) - o2 = ExampleObject(2, o1) - o3 = ExampleObject(3, root) + assert debug.get_all_objects(start_obj=root) == expected - expected = textwrap.dedent(""" - Qt widgets - 2 objects: - - - - Qt objects - 3 objects: - - - - - global object registry - 0 objects: - """).rstrip('\n') - - assert debug.get_all_objects(start_obj=root) == expected - - -def test_get_all_objects_qapp(): - objects = debug.get_all_objects() - assert '