Merge lp:~thomir-deactivatedaccount/autopilot/trunk-object-ordering-docs into lp:autopilot

Proposed by Thomi Richards
Status: Merged
Approved by: Christopher Lee
Approved revision: 360
Merged at revision: 360
Proposed branch: lp:~thomir-deactivatedaccount/autopilot/trunk-object-ordering-docs
Merge into: lp:autopilot
Diff against target: 50 lines (+31/-1)
2 files modified
autopilot/introspection/dbus.py (+5/-1)
docs/tutorial/good_tests.rst (+26/-0)
To merge this branch: bzr merge lp:~thomir-deactivatedaccount/autopilot/trunk-object-ordering-docs
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Leo Arias (community) Approve
Christopher Lee (community) Approve
Review via email: mp+194276@code.launchpad.net

Commit message

Add more documentation around object ordering.

Description of the change

Add more documentation around object ordering.

To post a comment you must log in.
Revision history for this message
Christopher Lee (veebers) wrote :

Looks good to me.

review: Approve
Revision history for this message
Leo Arias (elopio) wrote :

Thank you!

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

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 2013-11-05 22:24:38 +0000
3+++ autopilot/introspection/dbus.py 2013-11-07 03:21:29 +0000
4@@ -396,7 +396,11 @@
5 # returns a list of QAction objects who appear below file_menu in
6 # the object tree.
7
8- .. note:: The order in which objects are returned is not guaranteed.
9+ .. warning::
10+ The order in which objects are returned is not guaranteed. It is
11+ bad practise to write tests that depend on the order in which
12+ this method returns objects. (see :ref:`object_ordering` for more
13+ information).
14
15 If you only want to get one item, use :meth:`select_single` instead.
16
17
18=== modified file 'docs/tutorial/good_tests.rst'
19--- docs/tutorial/good_tests.rst 2013-05-28 00:52:21 +0000
20+++ docs/tutorial/good_tests.rst 2013-11-07 03:21:29 +0000
21@@ -504,3 +504,29 @@
22 As a general rule, tests shouldn't have assert statements inside an if statement unless there's a very good reason for doing so.
23
24 Scenarios can be useful, but we must be careful not to abuse them. It is far better to spend more time typing and end up with clear, readable tests than it is to end up with fewer, less readable tests. Like all code, tests are read far more often than they're written.
25+
26+.. _object_ordering:
27+
28+Do Not Depend on Object Ordering
29+++++++++++++++++++++++++++++++++
30+
31+Calls such as :meth:`~autopilot.introspection.dbus.DBusIntrospectionObject.select_many` return several objects at once. These objects are explicitly unordered, and test authors must take care not to make assumptions about their order.
32+
33+**Bad Example:**
34+
35+.. code-block:: python
36+
37+ buttons = self.select_many('Button')
38+ save_button = buttons[0]
39+ print_button = buttons[1]
40+
41+This code may work initially, but there's absolutely no guarantee that the order of objects won't change in the future. A better approach is to select the individual components you need:
42+
43+**Good Example:**
44+
45+.. code-block:: python
46+
47+ save_button = self.select_single('Button', objectName='btnSave')
48+ print_button = self.select_single('Button', objectName='btnPrint')
49+
50+This code will continue to work in the future.

Subscribers

People subscribed via source and target branches