Merge lp:~veebers/autopilot/1.6-OR-removal_from-proxy-object into lp:autopilot

Proposed by Christopher Lee
Status: Needs review
Proposed branch: lp:~veebers/autopilot/1.6-OR-removal_from-proxy-object
Merge into: lp:autopilot
Prerequisite: lp:~veebers/autopilot/remove_object_registry-CPO_creation_explicit
Diff against target: 88 lines (+56/-0)
3 files modified
autopilot/introspection/dbus.py (+24/-0)
autopilot/tests/functional/test_introspection_features.py (+14/-0)
autopilot/tests/unit/test_introspection_dbus.py (+18/-0)
To merge this branch: bzr merge lp:~veebers/autopilot/1.6-OR-removal_from-proxy-object
Reviewer Review Type Date Requested Status
platform-qa-bot continuous-integration Approve
PS Jenkins bot continuous-integration Approve
Max Brustkern (community) Approve
prod-platform-qa continuous-integration Pending
Review via email: mp+262049@code.launchpad.net

Commit message

Provide classmethod to instantiate a Custom Proxy Object instance from an existing proxy object (Generated default or Custom.)

Description of the change

Provide classmethod to instantiate a Custom Proxy Object instance from an existing proxy object (Generated default or Custom.)

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

Pyflakes fix.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Max Brustkern (nuclearbob) wrote :

Seems reasonable to me.

review: Approve
583. By Christopher Lee

Merge pre-req. changes.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Max Brustkern (nuclearbob) wrote :

Those changes look fine here as well.

review: Approve
584. By Christopher Lee

Merge pre-req. updates.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Approve (continuous-integration)

Unmerged revisions

584. By Christopher Lee

Merge pre-req. updates.

583. By Christopher Lee

Merge pre-req. changes.

582. By Christopher Lee

Pyflakes fix.

581. By Christopher Lee

Merge pre-req changes

580. By Christopher Lee

Minor spelling mistake fix.

579. By Christopher Lee

Pyflakes fix

578. By Christopher Lee

Added note on from_proxy_object

577. By Christopher Lee

Merge pre req branch changes

576. By Christopher Lee

Merge pre req. branch updates.

575. By Christopher Lee

Make tests pass (slight update to test)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'autopilot/introspection/dbus.py'
2--- autopilot/introspection/dbus.py 2015-07-21 03:28:53 +0000
3+++ autopilot/introspection/dbus.py 2015-07-21 03:28:53 +0000
4@@ -587,6 +587,30 @@
5
6 return cls.__name__
7
8+ @classmethod
9+ def from_proxy_object(cls, proxy_object):
10+ """Return a instantiated proxy object of this class type.
11+
12+ Creation method that allows a new Custom Proxy Object to be
13+ instantiated from an existing CPO Object.
14+
15+ For instance a query can return a default generated proxy object and
16+ then use this method to create a specific CPO from it.
17+
18+ Note::
19+ There is no validation done on the acceptability of the passed
20+ proxy object to be instantiated as the calling class.
21+ (e.g. validate_dbus_object is not involved.)
22+ It is up to the caller to ensure that the passed proxy object is
23+ suitable.
24+
25+ """
26+ _, state_dict = proxy_object._get_new_state()
27+ path = proxy_object._path
28+ backend = proxy_object._backend
29+
30+ return cls(state_dict, path, backend)
31+
32
33 # TODO - can we add a deprecation warning around this somehow?
34 CustomEmulatorBase = DBusIntrospectionObject
35
36=== modified file 'autopilot/tests/functional/test_introspection_features.py'
37--- autopilot/tests/functional/test_introspection_features.py 2015-07-21 03:28:53 +0000
38+++ autopilot/tests/functional/test_introspection_features.py 2015-07-21 03:28:53 +0000
39@@ -196,6 +196,20 @@
40 Not(IsInstance(type(generic_window)))
41 )
42
43+ def test_object_created_from_proxy_object_methods_are_callable(self):
44+ """Creating a proxy object using the 'from_proxy_object' method must
45+ ensure that the new objects methods are callable and work.
46+
47+ """
48+ class TestCPO(EmulatorBase):
49+ def get_example_window(self):
50+ return self.select_single('QMainWindow')
51+
52+ app = self.start_mock_app(EmulatorBase)
53+ new_app = TestCPO.from_proxy_object(app)
54+
55+ self.assertThat(new_app.get_example_window(), Not(Equals(None)))
56+
57 def test_print_tree_full(self):
58 """Print tree of full application"""
59
60
61=== modified file 'autopilot/tests/unit/test_introspection_dbus.py'
62--- autopilot/tests/unit/test_introspection_dbus.py 2015-07-21 03:28:53 +0000
63+++ autopilot/tests/unit/test_introspection_dbus.py 2015-07-21 03:28:53 +0000
64@@ -109,6 +109,24 @@
65 return "TestCPO"
66 self.assertThat(TestCPO.get_type_query_name(), Equals("TestCPO"))
67
68+ def test_from_proxy_object_creates_new_cpo_of_expected_type(self):
69+ class TestCPO(dbus.DBusIntrospectionObject):
70+ pass
71+
72+ fake_state = dict(id=[0, 123], path=[0, '/some/path'])
73+
74+ fake_object = dbus.DBusIntrospectionObject(
75+ fake_state,
76+ b'/root',
77+ Mock()
78+ )
79+
80+ with patch.object(fake_object, '_get_new_state') as new_state:
81+ new_state.return_value = (None, fake_state)
82+ new_object = TestCPO.from_proxy_object(fake_object)
83+
84+ self.assertEqual(new_object.__class__, TestCPO)
85+
86
87 class ProxyObjectCreationTests(TestCase):
88 def test_default_class_mentioned_in_attr_error(self):

Subscribers

People subscribed via source and target branches