Move get_all_objects() tests into a class.
This commit is contained in:
parent
bf156cf554
commit
52ec9ed28f
@ -206,53 +206,44 @@ def test_dbg_signal(stubs, args, expected):
|
|||||||
assert debug.dbg_signal(stubs.FakeSignal(), args) == expected
|
assert debug.dbg_signal(stubs.FakeSignal(), args) == expected
|
||||||
|
|
||||||
|
|
||||||
class ExampleObject(QObject):
|
class TestGetAllObjects:
|
||||||
|
|
||||||
def __init__(self, num, parent=None):
|
class Object(QObject):
|
||||||
self._num = num
|
|
||||||
super().__init__(parent)
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __init__(self, name, parent=None):
|
||||||
return '<ExampleObject {}>'.format(self._num)
|
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):
|
root = QObject()
|
||||||
self._num = num
|
o1 = self.Object('Object 1', root)
|
||||||
super().__init__(parent)
|
o2 = self.Object('Object 2', o1)
|
||||||
|
o3 = self.Object('Object 3', root)
|
||||||
|
|
||||||
def __repr__(self):
|
expected = textwrap.dedent("""
|
||||||
return '<ExampleWidget {}>'.format(self._num)
|
Qt widgets - 2 objects:
|
||||||
|
<Widget 1>
|
||||||
|
<Widget 2>
|
||||||
|
|
||||||
|
Qt objects - 3 objects:
|
||||||
|
<Object 1>
|
||||||
|
<Object 2>
|
||||||
|
<Object 3>
|
||||||
|
|
||||||
def test_get_all_objects(stubs, monkeypatch):
|
global object registry - 0 objects:
|
||||||
# pylint: disable=unused-variable
|
""").rstrip('\n')
|
||||||
widgets = [ExampleWidget(1), ExampleWidget(2)]
|
|
||||||
app = stubs.FakeQApplication(all_widgets=widgets)
|
|
||||||
monkeypatch.setattr(debug, 'QApplication', app)
|
|
||||||
|
|
||||||
root = QObject()
|
assert debug.get_all_objects(start_obj=root) == expected
|
||||||
o1 = ExampleObject(1, root)
|
|
||||||
o2 = ExampleObject(2, o1)
|
|
||||||
o3 = ExampleObject(3, root)
|
|
||||||
|
|
||||||
expected = textwrap.dedent("""
|
def test_get_all_objects_qapp(self):
|
||||||
Qt widgets - 2 objects:
|
objects = debug.get_all_objects()
|
||||||
<ExampleWidget 1>
|
assert '<PyQt5.QtCore.QAbstractEventDispatcher object at' in objects
|
||||||
<ExampleWidget 2>
|
|
||||||
|
|
||||||
Qt objects - 3 objects:
|
|
||||||
<ExampleObject 1>
|
|
||||||
<ExampleObject 2>
|
|
||||||
<ExampleObject 3>
|
|
||||||
|
|
||||||
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 '<PyQt5.QtCore.QAbstractEventDispatcher object at' in objects
|
|
||||||
|
Loading…
Reference in New Issue
Block a user