Merge lp:~canonical-platform-qa/ubuntu-system-tests/shared-cpo-data into lp:ubuntu-system-tests

Proposed by Richard Huddie
Status: Work in progress
Proposed branch: lp:~canonical-platform-qa/ubuntu-system-tests/shared-cpo-data
Merge into: lp:ubuntu-system-tests
Diff against target: 210 lines (+85/-23)
4 files modified
ubuntu_system_tests/helpers/data.py (+36/-14)
ubuntu_system_tests/helpers/file_system.py (+3/-0)
ubuntu_system_tests/helpers/indicators/battery.json (+29/-0)
ubuntu_system_tests/helpers/indicators/battery.py (+17/-9)
To merge this branch: bzr merge lp:~canonical-platform-qa/ubuntu-system-tests/shared-cpo-data
Reviewer Review Type Date Requested Status
Michał Sawicz (community) Needs Information
Santiago Baldassin (community) Needs Information
Review via email: mp+294934@code.launchpad.net
To post a comment you must log in.
388. By Richard Huddie

Use data file names for accessing properties.

389. By Richard Huddie

simplify the data structure.

390. By Richard Huddie

Simplify the data structure.

391. By Richard Huddie

Move the json file to helpers dir.

Revision history for this message
Santiago Baldassin (sbaldassin) wrote :

Hi Richard, thanks for mp. I just have a couple of comments about the use of a global variable to keep the metadata and another one about always loading all the matadata for all the helpers. Would you please let me know your thoughts about it?

review: Needs Information
Revision history for this message
Richard Huddie (rhuddie) wrote :

> Hi Richard, thanks for mp. I just have a couple of comments about the use of a
> global variable to keep the metadata and another one about always loading all
> the matadata for all the helpers. Would you please let me know your thoughts
> about it?

Thanks for taking a look. I was also thinking about how to structure the data. I think it makes sense for a metadata file to exist for each helper file. The helper would then need to only load the corresponding metadata from a single file. The only potential problem I see with this is that if you have an object defined in one file, a helper in another file might also want to include that, rather than having to re-define it again locally. This would require all the helpers data to be loaded at once.

This is still very much a work-in-progress so, we'll have to see how useful (or not) this might actually be. I'll give this approach a try and see how it goes.

392. By Richard Huddie

Merge from trunk.

393. By Richard Huddie

Can load metadata for a single file.

Revision history for this message
Michał Sawicz (saviq) :
review: Needs Information
Revision history for this message
Richard Huddie (rhuddie) wrote :

Reply comments below.

Unmerged revisions

393. By Richard Huddie

Can load metadata for a single file.

392. By Richard Huddie

Merge from trunk.

391. By Richard Huddie

Move the json file to helpers dir.

390. By Richard Huddie

Simplify the data structure.

389. By Richard Huddie

simplify the data structure.

388. By Richard Huddie

Use data file names for accessing properties.

387. By Richard Huddie

Add first attempt at importing data for cpo.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu_system_tests/helpers/data.py'
2--- ubuntu_system_tests/helpers/data.py 2016-02-02 19:58:03 +0000
3+++ ubuntu_system_tests/helpers/data.py 2016-05-19 14:30:31 +0000
4@@ -26,6 +26,7 @@
5
6
7 _full_dict = AttrDict()
8+_helpers_dict = AttrDict()
9
10
11 class AttrDictDecoder(JSONDecoder):
12@@ -35,10 +36,10 @@
13 JSONDecoder.__init__(self, object_hook=dict_to_attr_dict)
14
15
16-def _get_metadata_file(dir):
17+def _get_metadata_file(root):
18 """ Retrieve the metadata file path from a dir, in case there is not one
19 return None """
20- file = path.join(dir, 'metadata.json')
21+ file = path.join(root, 'metadata.json')
22 if not path.isfile(file):
23 return None
24 return file
25@@ -51,26 +52,29 @@
26 return d
27
28
29-def _load_metadata(dir):
30+def _load_metadata(target):
31 """ Load the metadata object from an specific dir """
32- file = _get_metadata_file(dir)
33+ if not path.isfile(target):
34+ target = _get_metadata_file(target)
35
36- if file:
37- with open(file) as data_file:
38+ if target:
39+ with open(target) as data_file:
40 return load(data_file, cls=AttrDictDecoder)
41 else:
42 return AttrDict()
43
44
45-def _load_metadata_list(parent):
46- """ Load the metadata object from a list of dirs """
47+def _load_metadata_list(target):
48+ """ Load the metadata object from target file or folder"""
49 all_dict = AttrDict()
50- for root, dirs, files in walk(parent):
51- for dir in dirs:
52- subdict = _load_metadata(path.join(parent, dir))
53- if subdict:
54- all_dict[dir] = subdict
55-
56+ if path.isfile(target):
57+ all_dict = _load_metadata(target)
58+ else:
59+ for root, dirs, files in walk(target):
60+ for dir in dirs:
61+ subdict = _load_metadata(path.join(target, dir))
62+ if subdict:
63+ all_dict[dir] = subdict
64 return all_dict
65
66
67@@ -84,3 +88,21 @@
68
69 _full_dict = _load_metadata_list(fs.DIR_TEST_DATA)
70 return _full_dict
71+
72+
73+def load_helpers_metadata(file_path=None):
74+ if file_path:
75+ root, ext = path.splitext(file_path)
76+ if ext == '.json':
77+ target = file_path
78+ else:
79+ target = root + '.json'
80+ else:
81+ target = fs.DIR_HELPERS
82+
83+ global _helpers_dict
84+ if _helpers_dict:
85+ return _helpers_dict
86+
87+ _helpers_dict = _load_metadata_list(target)
88+ return _helpers_dict
89
90=== modified file 'ubuntu_system_tests/helpers/file_system.py'
91--- ubuntu_system_tests/helpers/file_system.py 2016-05-13 10:10:54 +0000
92+++ ubuntu_system_tests/helpers/file_system.py 2016-05-19 14:30:31 +0000
93@@ -97,6 +97,9 @@
94 DIR_HOME_LOCAL_SHARE_WEBBROWSER = os.path.join(DIR_HOME_LOCAL_SHARE,
95 DIR_WEBBROWSER)
96
97+# Helpers dir
98+DIR_HELPERS = os.path.dirname(__file__)
99+
100 # Test data dirs
101 DIR_TESTS = os.path.realpath(__file__ + '/../../tests')
102 DIR_TEST_DATA = os.path.join(DIR_TESTS, 'data')
103
104=== added file 'ubuntu_system_tests/helpers/indicators/battery.json'
105--- ubuntu_system_tests/helpers/indicators/battery.json 1970-01-01 00:00:00 +0000
106+++ ubuntu_system_tests/helpers/indicators/battery.json 2016-05-19 14:30:31 +0000
107@@ -0,0 +1,29 @@
108+{
109+"battery_indicator":
110+ {
111+ "cls": "BatteryIndicatorPage",
112+ "objectName": "indicator-power-page",
113+ "children": [
114+ "slider",
115+ "switch_menu",
116+ "standard_menu"
117+ ]
118+ },
119+"switch_menu":
120+ {
121+ "cls": "SwitchMenu",
122+ "objectName": "indicator.auto-brightness",
123+ "checked": "checked"
124+ },
125+"standard_menu":
126+ {
127+ "cls": "StandardMenu",
128+ "objectName": "indicator.activate-phone-settings"
129+ },
130+"slider":
131+ {
132+ "cls": "Slider",
133+ "objectName": "slider",
134+ "value": "value"
135+ }
136+}
137\ No newline at end of file
138
139=== modified file 'ubuntu_system_tests/helpers/indicators/battery.py'
140--- ubuntu_system_tests/helpers/indicators/battery.py 2016-04-06 14:34:20 +0000
141+++ ubuntu_system_tests/helpers/indicators/battery.py 2016-05-19 14:30:31 +0000
142@@ -25,8 +25,11 @@
143 validate_dbus_object,
144 click_object
145 )
146+from ubuntu_system_tests.helpers.data import load_helpers_metadata
147 from ubuntu_system_tests.helpers import unity8
148
149+cpo_data = load_helpers_metadata(__file__)
150+
151
152 class BatteryIndicatorPage(IndicatorPage):
153 """Autopilot helper for the battery indicator page."""
154@@ -35,13 +38,13 @@
155 def validate_dbus_object(cls, path, state):
156 return validate_dbus_object(
157 path, state, unity8.UNITY8_PATH_ROOT, INDICATOR_PAGE_PATH,
158- objectName='indicator-power-page')
159+ objectName=cpo_data.battery_indicator.objectName)
160
161 def _get_battery_settings_menu_item(self):
162 """Return the battery settings list item."""
163 return self.select_single(
164- 'StandardMenu',
165- objectName='indicator.activate-phone-settings')
166+ cpo_data.standard_menu.cls,
167+ objectName=cpo_data.standard_menu.objectName)
168
169 @click_object
170 def open_battery_settings(self):
171@@ -50,15 +53,18 @@
172
173 def get_brightness_slider_widget(self):
174 """Return the slider widget on the battery indicator page."""
175- return self.select_single(slider.Slider, objectName='slider')
176+ return self.select_single(
177+ slider.Slider, objectName=cpo_data.slider.objectName)
178
179 def get_current_brightness(self):
180- return float(self.get_brightness_slider_widget().value)
181+ return float(getattr(self.get_brightness_slider_widget(),
182+ cpo_data.slider.value))
183
184 def _get_brightness_switch(self):
185 """Return the auto brightness switch."""
186- return self.select_single('SwitchMenu',
187- objectName='indicator.auto-brightness')
188+ return self.select_single(
189+ cpo_data.switch_menu.cls,
190+ objectName=cpo_data.switch_menu.objectName)
191
192 @click_object
193 def click_brightness_switch(self):
194@@ -76,10 +82,12 @@
195
196 def get_auto_adjust_status(self):
197 """Return checked state of auto adjust switch."""
198- return self._get_brightness_switch().checked
199+ return getattr(self._get_brightness_switch(),
200+ cpo_data.switch_menu.checked)
201
202 def toggle_auto_adjust(self):
203 """Press the auto adjust switch and wait for state to change."""
204 original_state = self.get_auto_adjust_status()
205 self.click_brightness_switch()
206- self._get_brightness_switch().checked.wait_for(not original_state)
207+ getattr(self._get_brightness_switch(),
208+ cpo_data.switch_menu.checked).wait_for(not original_state)
209
210=== added directory 'ubuntu_system_tests/tests/data/cpo'

Subscribers

People subscribed via source and target branches

to all changes: