Merge lp:~veebers/autopilot/1.3_generic_proxy_objects_id into lp:autopilot/1.3

Proposed by Christopher Lee
Status: Merged
Approved by: Thomi Richards
Approved revision: 343
Merged at revision: 341
Proposed branch: lp:~veebers/autopilot/1.3_generic_proxy_objects_id
Merge into: lp:autopilot/1.3
Diff against target: 95 lines (+48/-6)
3 files modified
autopilot/introspection/__init__.py (+5/-2)
autopilot/introspection/dbus.py (+9/-3)
autopilot/tests/functional/test_introspection_features.py (+34/-1)
To merge this branch: bzr merge lp:~veebers/autopilot/1.3_generic_proxy_objects_id
Reviewer Review Type Date Requested Status
Thomi Richards (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+187656@code.launchpad.net

Commit message

Changes how the proxy objects are created so the inheritance is correct

Description of the change

Changes how the proxy objects are created so the inheritance is correct regardless if it's a generic type or custom emulator.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
342. By Christopher Lee

Spelling and docstring fixes

343. By Christopher Lee

Made fall-through case clearer

Revision history for this message
Thomi Richards (thomir-deactivatedaccount) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'autopilot/introspection/__init__.py'
2--- autopilot/introspection/__init__.py 2013-09-26 04:34:18 +0000
3+++ autopilot/introspection/__init__.py 2013-09-26 05:11:36 +0000
4@@ -476,10 +476,13 @@
5
6 _clear_backends_for_proxy_object(emulator_base)
7 clsobj = type(
8- str(cls_name), proxy_bases, dict(_Backend=data_source)
9+ # Merge the object hierarchy.
10+ str("%sBase" % cls_name), proxy_bases, dict(_Backend=data_source)
11 )
12
13- proxy = clsobj.get_root_instance()
14+ proxy_class = type(str(cls_name), (clsobj,), {})
15+
16+ proxy = proxy_class.get_root_instance()
17 return proxy
18
19
20
21=== modified file 'autopilot/introspection/dbus.py'
22--- autopilot/introspection/dbus.py 2013-09-17 15:57:39 +0000
23+++ autopilot/introspection/dbus.py 2013-09-26 05:11:36 +0000
24@@ -570,9 +570,15 @@
25 get_debug_logger().warning(
26 "Generating introspection instance for type '%s' based on "
27 "generic class.", name)
28- # override the _id attr from cls, since we don't want generated
29- # types to end up in the object registry.
30- class_type = type(str(name), (cls,), {'_id': None})
31+ # we want the object to inherit from the custom emulator base, not
32+ # the object class that is doing the selecting
33+ for base in cls.__bases__:
34+ if issubclass(base, CustomEmulatorBase):
35+ base_class = base
36+ break
37+ else:
38+ base_class = cls
39+ class_type = type(str(name), (base_class,), {})
40 return class_type(state, path)
41
42 @contextmanager
43
44=== modified file 'autopilot/tests/functional/test_introspection_features.py'
45--- autopilot/tests/functional/test_introspection_features.py 2013-09-24 23:38:39 +0000
46+++ autopilot/tests/functional/test_introspection_features.py 2013-09-26 05:11:36 +0000
47@@ -24,7 +24,7 @@
48 import subprocess
49 import tempfile
50 from tempfile import mktemp
51-from testtools.matchers import Equals
52+from testtools.matchers import Equals, IsInstance, Not
53 from textwrap import dedent
54
55 from autopilot.matchers import Eventually
56@@ -86,6 +86,39 @@
57
58 self.assertThat(test_widget.visible, Eventually(Equals(True)))
59
60+ def test_selecting_generic_from_custom_is_not_inherited_from_custom(self):
61+ """Selecting a generic proxy object from a custom proxy object must not
62+ return an object derived of the custom object type.
63+
64+ """
65+ class MouseTestWidget(EmulatorBase):
66+ pass
67+
68+ app = self.start_mock_app(EmulatorBase)
69+ mouse_widget = app.select_single(MouseTestWidget)
70+
71+ child_label = mouse_widget.select_many("QLabel")[0]
72+
73+ self.assertThat(child_label, Not(IsInstance(MouseTestWidget)))
74+
75+ def test_selecting_custom_from_generic_is_not_inherited_from_generic(self):
76+ """Selecting a custom proxy object from a generic proxy object must
77+ return an object that is of the custom type.
78+
79+ """
80+ class MouseTestWidget(EmulatorBase):
81+ pass
82+
83+ app = self.start_mock_app(EmulatorBase)
84+ generic_window = app.select_single("QMainWindow")
85+
86+ mouse_widget = generic_window.select_single(MouseTestWidget)
87+
88+ self.assertThat(
89+ mouse_widget,
90+ Not(IsInstance(type(generic_window)))
91+ )
92+
93
94 class QMLCustomEmulatorTestCase(AutopilotTestCase):
95 """Test the introspection of a QML application with a custom emulator."""

Subscribers

People subscribed via source and target branches