Merge lp:~om26er/ubuntu-system-settings/pep8_pyflakes_fix into lp:ubuntu-system-settings

Proposed by Omer Akram
Status: Superseded
Proposed branch: lp:~om26er/ubuntu-system-settings/pep8_pyflakes_fix
Merge into: lp:ubuntu-system-settings
Diff against target: 762 lines (+236/-121)
12 files modified
debian/control (+2/-0)
debian/rules (+3/-0)
debian/ubuntu-system-settings-sound-gsettings-to-accountsservice.py (+14/-4)
tests/autopilot/ubuntu_system_settings/tests/__init__.py (+43/-39)
tests/autopilot/ubuntu_system_settings/tests/test_about.py (+11/-6)
tests/autopilot/ubuntu_system_settings/tests/test_cellular.py (+19/-15)
tests/autopilot/ubuntu_system_settings/tests/test_datetime.py (+17/-10)
tests/autopilot/ubuntu_system_settings/tests/test_plugins.py (+69/-31)
tests/autopilot/ubuntu_system_settings/tests/test_search.py (+5/-7)
tests/autopilot/ubuntu_system_settings/tests/test_system_updates.py (+1/-6)
tests/autopilot/ubuntu_system_settings/utils/i18n.py (+5/-3)
tests/test_code.py (+47/-0)
To merge this branch: bzr merge lp:~om26er/ubuntu-system-settings/pep8_pyflakes_fix
Reviewer Review Type Date Requested Status
Sebastien Bacher (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+207966@code.launchpad.net

This proposal has been superseded by a proposal from 2014-03-11.

Commit message

autopilot tests code:
* fix pep8 and pyflakes warnings.
* add tests to make sure we don't regress on pep8/pyflakes

Description of the change

fix pep8 and pyflakes warning, our tests are now pep8 and pyflakes compliant.

This branch is a prerequisite for many to come in a series to improve autopilot tests for ubuntu-system-settings

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)
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)
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: Approve (continuous-integration)
Revision history for this message
Omer Akram (om26er) wrote :

Finally \o/ -- Its read for review now.

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
Sebastien Bacher (seb128) wrote :

Thanks for the work there, nice job, some comments though:

- why do you drop the use of translations? some of us run non-english locales and it's important to be able to run the tests under those

- why those sort of changes

690 - """ Checks whether the Battery plugin is not available as we have no battery """
691 - self.assertThat(lambda: self.main_view.select_single(objectName='entryComponent-battery'),
692 - raises(StateNotFoundError))
693 + """ Checks whether the Battery plugin is not available as we
694 + have no battery
695 +
696 + """

the emtpy line at the end of the comment seems weird?

- could you add a test that runs pep8 and pyflake? so we can make sure we don't introduce new issues with futur commits

review: Needs Fixing
Revision history for this message
Omer Akram (om26er) wrote :

sorry for not replying, I am on vacation this week, will fix this MR when I
get back on Monday.

On Thu, Mar 6, 2014 at 4:55 PM, Sebastien Bacher <email address hidden> wrote:

> The proposal to merge lp:~om26er/ubuntu-system-settings/pep8_pyflakes_fix
> into lp:ubuntu-system-settings has been updated.
>
> Status: Needs review => Work in progress
>
> For more details, see:
>
> https://code.launchpad.net/~om26er/ubuntu-system-settings/pep8_pyflakes_fix/+merge/207966
> --
>
> https://code.launchpad.net/~om26er/ubuntu-system-settings/pep8_pyflakes_fix/+merge/207966
> You are the owner of lp:~om26er/ubuntu-system-settings/pep8_pyflakes_fix.
>

Revision history for this message
Omer Akram (om26er) wrote :

> Thanks for the work there, nice job, some comments though:
>
Thanks for the review.

> - why do you drop the use of translations? some of us run non-english locales
> and it's important to be able to run the tests under those
>

In an optimal world we should not be testing labels in our apps because they are well tested in the UIToolkit, but in this case there are many places where we are testing label text which we should not be, My Further branches for system-settings will try and remove the reliability on labels as much as possible.

Instead of translating I am making sure that the app always loads en.US note:

35 + self.patch_environment('LC_MESSAGES', 'en_US.UTF-8')

> - why those sort of changes
>
> 690 - """ Checks whether the Battery plugin is not available as we have no
> battery """
> 691 - self.assertThat(lambda: self.main_view.select_single(objectName
> ='entryComponent-battery'),
> 692 - raises(StateNotFoundError))
> 693 + """ Checks whether the Battery plugin is not available as we
> 694 + have no battery
> 695 +
> 696 + """
>
> the emtpy line at the end of the comment seems weird?
>

Fixed that.

> - could you add a test that runs pep8 and pyflake? so we can make sure we
> don't introduce new issues with futur commits

Added two new tests to test both pyflakes and pep8, they currently are skipped if the related tool is not installed, do you think it makes sense for our suite to depend on pyflakes and pep8 ?

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)
641. By Omer Akram

don't remove string translations, they need to stay

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
642. By Omer Akram

run python static code test during build, also fix some pep8 complaints in the migrator script

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

Looks good now, thanks!

review: Approve
643. By Omer Akram

merge in laney' branch to base this one on it

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2014-03-03 17:03:21 +0000
3+++ debian/control 2014-03-11 14:59:49 +0000
4@@ -24,6 +24,8 @@
5 libapt-pkg-dev,
6 xvfb,
7 cmake,
8+ pep8,
9+ pyflakes,
10 Standards-Version: 3.9.4
11 Homepage: https://launchpad.net/ubuntu-system-settings
12 # If you aren't a member of ~system-settings-touch but need to upload packaging
13
14=== modified file 'debian/rules'
15--- debian/rules 2014-03-03 17:03:21 +0000
16+++ debian/rules 2014-03-11 14:59:49 +0000
17@@ -21,3 +21,6 @@
18
19 %:
20 dh $@ --fail-missing --with python2,migrations
21+
22+override_dh_auto_test:
23+ python tests/test_code.py
24
25=== modified file 'debian/ubuntu-system-settings-sound-gsettings-to-accountsservice.py' (properties changed: -x to +x)
26--- debian/ubuntu-system-settings-sound-gsettings-to-accountsservice.py 2014-01-09 13:02:44 +0000
27+++ debian/ubuntu-system-settings-sound-gsettings-to-accountsservice.py 2014-03-11 14:59:49 +0000
28@@ -20,9 +20,12 @@
29
30 # Migrate ubuntu-system-settings sound panel settings from GSettings to
31 # AccountsService
32-
33+
34+from __future__ import print_function
35+
36 import dbus
37 import os
38+import sys
39
40 from gi.repository import Gio
41
42@@ -30,20 +33,27 @@
43 manager_proxy = system_bus.get_object('org.freedesktop.Accounts',
44 '/org/freedesktop/Accounts')
45 object_path = manager_proxy.FindUserById(
46- os.getuid(), dbus_interface='org.freedesktop.Accounts')
47+ os.getuid(), dbus_interface='org.freedesktop.Accounts'
48+)
49 user_proxy = system_bus.get_object('org.freedesktop.Accounts', object_path)
50
51 gsettings = Gio.Settings(schema="com.ubuntu.touch.sound")
52
53+
54 def get_string(key):
55 return gsettings.get_string(key)
56
57+
58 def get_bool(key):
59 return gsettings.get_boolean(key)
60
61+
62 def set_as_setting(interface, setting, value):
63- user_proxy.Set(interface, setting, value,
64- dbus_interface=dbus.PROPERTIES_IFACE)
65+ try:
66+ user_proxy.Set(interface, setting, value,
67+ dbus_interface=dbus.PROPERTIES_IFACE)
68+ except dbus.exceptions.DBusException as e:
69+ print("Couldn't update %s: %s" % (setting, e), file=sys.stderr)
70
71 # (gsettings key, accountsservice key, function to retrieve from gsettings)
72 keys = [('silent-mode', 'SilentMode', get_bool),
73
74=== modified file 'tests/autopilot/ubuntu_system_settings/tests/__init__.py'
75--- tests/autopilot/ubuntu_system_settings/tests/__init__.py 2014-02-18 15:42:24 +0000
76+++ tests/autopilot/ubuntu_system_settings/tests/__init__.py 2014-03-11 14:59:49 +0000
77@@ -13,7 +13,6 @@
78
79 from autopilot.input import Mouse, Touch, Pointer
80 from autopilot.platform import model
81-from autopilot.testcase import AutopilotTestCase
82 from autopilot.matchers import Eventually
83 from testtools.matchers import Equals, NotEquals, GreaterThan
84
85@@ -25,12 +24,13 @@
86 import subprocess
87 from time import sleep
88
89+
90 class UbuntuSystemSettingsTestCase(UbuntuUIToolkitAppTestCase):
91 """ Base class for Ubuntu System Settings """
92 if model() == 'Desktop':
93- scenarios = [ ('with mouse', dict(input_device_class=Mouse)) ]
94+ scenarios = [('with mouse', dict(input_device_class=Mouse))]
95 else:
96- scenarios = [ ('with touch', dict(input_device_class=Touch)) ]
97+ scenarios = [('with touch', dict(input_device_class=Touch))]
98
99 def setUp(self, panel=None):
100 super(UbuntuSystemSettingsTestCase, self).setUp()
101@@ -40,7 +40,8 @@
102 def launch_system_settings(self, panel=None):
103 params = ['/usr/bin/system-settings']
104 if (model() != 'Desktop'):
105- params.append('--desktop_file_hint=/usr/share/applications/ubuntu-system-settings.desktop')
106+ params.append('--desktop_file_hint=/usr/share/applications/'
107+ 'ubuntu-system-settings.desktop')
108
109 # Launch to a specific panel
110 if panel is not None:
111@@ -69,8 +70,8 @@
112 page_center_x = int(page_right / 2)
113 page_center_y = int(page_bottom / 2)
114 while obj.globalRect[1] + obj.height > page_bottom:
115- self.pointer.drag(page_center_x, page_center_y,
116- page_center_x, page_center_y - obj.height * 2)
117+ self.pointer.drag(page_center_x, page_center_y,
118+ page_center_x, page_center_y - obj.height * 2)
119 # avoid a flick
120 sleep(0.5)
121
122@@ -96,7 +97,9 @@
123
124 def add_mock_battery(self):
125 """ Make sure we have a battery """
126- self.dbusmock.AddDischargingBattery('mock_BATTERY', 'Battery', 50.0, 10)
127+ self.dbusmock.AddDischargingBattery(
128+ 'mock_BATTERY', 'Battery', 50.0, 10
129+ )
130
131
132 class UbuntuSystemSettingsBatteryTestCase(UbuntuSystemSettingsUpowerTestCase):
133@@ -123,37 +126,39 @@
134 def setUp(self, panel=None):
135 self.obj_ofono.Reset()
136 # Add an available carrier
137- self.dbusmock.AddObject('/ril_0/operator/op2',
138- 'org.ofono.NetworkOperator',
139- {
140- 'Name': 'my.cool.telco',
141- 'Status': 'available',
142- 'MobileCountryCode': '777',
143- 'MobileNetworkCode': '22',
144- 'Technologies': ['gsm'],
145- },
146- [
147- ('GetProperties', '', 'a{sv}',
148- 'ret = self.GetAll("org.ofono.NetworkOperator")'),
149- ('Register', '', '', ''),
150- ]
151- )
152+ self.dbusmock.AddObject(
153+ '/ril_0/operator/op2',
154+ 'org.ofono.NetworkOperator',
155+ {
156+ 'Name': 'my.cool.telco',
157+ 'Status': 'available',
158+ 'MobileCountryCode': '777',
159+ 'MobileNetworkCode': '22',
160+ 'Technologies': ['gsm'],
161+ },
162+ [
163+ ('GetProperties', '', 'a{sv}',
164+ 'ret = self.GetAll("org.ofono.NetworkOperator")'),
165+ ('Register', '', '', ''),
166+ ]
167+ )
168 # Add a forbidden carrier
169- self.dbusmock.AddObject('/ril_0/operator/op3',
170- 'org.ofono.NetworkOperator',
171- {
172- 'Name': 'my.bad.telco',
173- 'Status': 'forbidden',
174- 'MobileCountryCode': '777',
175- 'MobileNetworkCode': '22',
176- 'Technologies': ['gsm'],
177- },
178- [
179- ('GetProperties', '', 'a{sv}',
180- 'ret = self.GetAll("org.ofono.NetworkOperator")'),
181- ('Register', '', '', ''),
182- ]
183- )
184+ self.dbusmock.AddObject(
185+ '/ril_0/operator/op3',
186+ 'org.ofono.NetworkOperator',
187+ {
188+ 'Name': 'my.bad.telco',
189+ 'Status': 'forbidden',
190+ 'MobileCountryCode': '777',
191+ 'MobileNetworkCode': '22',
192+ 'Technologies': ['gsm'],
193+ },
194+ [
195+ ('GetProperties', '', 'a{sv}',
196+ 'ret = self.GetAll("org.ofono.NetworkOperator")'),
197+ ('Register', '', '', ''),
198+ ]
199+ )
200 super(UbuntuSystemSettingsOfonoTestCase, self).setUp('cellular')
201
202 @property
203@@ -194,8 +199,7 @@
204 """ Checks whether an space item exists and returns a value """
205 item = self.storage_page.select_single(objectName=object_name)
206 self.assertThat(item, NotEquals(None))
207- label = item.label # Label
208- space = item.value # Disk space (bytes)
209+ label = item.label # Label
210 self.assertThat(label, Equals(text))
211 # Get item's label
212 size_label = item.select_single(objectName='sizeLabel')
213
214=== modified file 'tests/autopilot/ubuntu_system_settings/tests/test_about.py'
215--- tests/autopilot/ubuntu_system_settings/tests/test_about.py 2014-01-27 16:17:57 +0000
216+++ tests/autopilot/ubuntu_system_settings/tests/test_about.py 2014-03-11 14:59:49 +0000
217@@ -8,13 +8,17 @@
218 from time import sleep
219
220 from autopilot.platform import model
221-from autopilot.matchers import Eventually
222 from testtools.matchers import Equals, NotEquals, GreaterThan
223 from unittest import expectedFailure
224
225-from ubuntu_system_settings.tests import AboutBaseTestCase, StorageBaseTestCase, LicenseBaseTestCase
226+from ubuntu_system_settings.tests import (
227+ AboutBaseTestCase,
228+ StorageBaseTestCase,
229+ LicenseBaseTestCase
230+)
231 from ubuntu_system_settings.utils.i18n import ugettext as _
232
233+
234 class AboutTestCase(AboutBaseTestCase):
235 """ Tests for About this phone Page """
236
237@@ -96,7 +100,7 @@
238 """ Tests for Storage """
239
240 def test_storage_page(self):
241- """ Check whether Storage page is available """
242+ """ Check whether Storage page is available """
243 self.assertThat(self.storage_page, NotEquals(None))
244
245 def test_disk(self):
246@@ -136,7 +140,9 @@
247
248 def test_installed_apps(self):
249 """ Checks whether Installed Apps list is available """
250- installed_apps_list_view = self.storage_page.select_single(objectName='installedAppsListView')
251+ installed_apps_list_view = self.storage_page.select_single(
252+ objectName='installedAppsListView'
253+ )
254 self.assertThat(installed_apps_list_view, NotEquals(None))
255
256
257@@ -145,6 +151,5 @@
258
259 @expectedFailure
260 def test_licenses_page(self):
261- """ Check whether Storage page is available """
262+ """ Check whether Storage page is available """
263 self.assertThat(self.licenses_page, NotEquals(None))
264-
265
266=== modified file 'tests/autopilot/ubuntu_system_settings/tests/test_cellular.py'
267--- tests/autopilot/ubuntu_system_settings/tests/test_cellular.py 2014-02-18 12:16:22 +0000
268+++ tests/autopilot/ubuntu_system_settings/tests/test_cellular.py 2014-03-11 14:59:49 +0000
269@@ -5,29 +5,28 @@
270 # under the terms of the GNU General Public License version 3, as published
271 # by the Free Software Foundation.
272
273-from time import sleep
274-
275 from autopilot.introspection.dbus import StateNotFoundError
276-from autopilot.matchers import Eventually
277 from testtools.matchers import Equals, NotEquals, raises
278-from unittest import expectedFailure
279
280 from ubuntu_system_settings.tests import UbuntuSystemSettingsOfonoTestCase
281 from ubuntu_system_settings.utils.i18n import ugettext as _
282
283 from ubuntuuitoolkit import emulators as toolkit_emulators
284
285+
286 class CellularTestCase(UbuntuSystemSettingsOfonoTestCase):
287 """ Tests for cellular Page """
288
289 def navigate_to_manual(self):
290 selector = self.cellular_page.select_single(
291- toolkit_emulators.ItemSelector,
292- objectName="autoChooseCarrierSelector")
293+ toolkit_emulators.ItemSelector,
294+ objectName="autoChooseCarrierSelector"
295+ )
296 manual = selector.select_single('Label', text=_("Manually"))
297 self.pointer.click_object(manual)
298 choosecarrier = self.cellular_page.select_single(
299- objectName="chooseCarrier")
300+ objectName="chooseCarrier"
301+ )
302 self.pointer.click_object(choosecarrier)
303 self.assertThat(self.choose_page.title, Equals(_("Carrier")))
304
305@@ -40,8 +39,9 @@
306 """ Tests whether the current network is visible and selected """
307 self.navigate_to_manual()
308 carriers = self.choose_page.select_single(
309- toolkit_emulators.ItemSelector,
310- objectName="carrierSelector")
311+ toolkit_emulators.ItemSelector,
312+ objectName="carrierSelector"
313+ )
314 # TODO: Once there is a proper ItemSelector emulator, get the items
315 # from it and check 'fake.tel' is the selected one.
316 manual = carriers.select_single('Label', text="fake.tel")
317@@ -52,8 +52,9 @@
318 """ Tests whether an alternative available network is displayed """
319 self.navigate_to_manual()
320 carriers = self.choose_page.select_single(
321- toolkit_emulators.ItemSelector,
322- objectName="carrierSelector")
323+ toolkit_emulators.ItemSelector,
324+ objectName="carrierSelector"
325+ )
326 manual = carriers.select_single('Label', text="my.cool.telco")
327 self.assertThat(manual, NotEquals(None))
328
329@@ -61,7 +62,10 @@
330 """ Ensures that a forbidden network is not shown """
331 self.navigate_to_manual()
332 carriers = self.choose_page.select_single(
333- toolkit_emulators.ItemSelector,
334- objectName="carrierSelector")
335- self.assertThat(lambda: carriers.select_single('Label', text="my.bad.telco"),
336- raises(StateNotFoundError))
337+ toolkit_emulators.ItemSelector,
338+ objectName="carrierSelector"
339+ )
340+ self.assertThat(
341+ lambda: carriers.select_single('Label', text="my.bad.telco"),
342+ raises(StateNotFoundError)
343+ )
344
345=== modified file 'tests/autopilot/ubuntu_system_settings/tests/test_datetime.py'
346--- tests/autopilot/ubuntu_system_settings/tests/test_datetime.py 2014-01-30 16:42:51 +0000
347+++ tests/autopilot/ubuntu_system_settings/tests/test_datetime.py 2014-03-11 14:59:49 +0000
348@@ -5,12 +5,10 @@
349 # under the terms of the GNU General Public License version 3, as published
350 # by the Free Software Foundation.
351
352-import dbus
353 import dbusmock
354 import subprocess
355 from time import sleep
356
357-from autopilot.platform import model
358 from autopilot.matchers import Eventually
359 from testtools.matchers import Equals, NotEquals, GreaterThan
360
361@@ -19,6 +17,7 @@
362
363 from ubuntuuitoolkit import emulators as toolkit_emulators
364
365+
366 class TimeDateTestCase(UbuntuSystemSettingsTestCase,
367 dbusmock.DBusTestCase):
368 """ Tests for the Time & Date Page """
369@@ -27,8 +26,9 @@
370 def setUpClass(klass):
371 klass.start_system_bus()
372 klass.dbus_con = klass.get_dbus(True)
373- (klass.p_mock,klass.obj_timedate1) = klass.spawn_server_template(
374- 'timedated', {}, stdout=subprocess.PIPE)
375+ (klass.p_mock, klass.obj_timedate1) = klass.spawn_server_template(
376+ 'timedated', {}, stdout=subprocess.PIPE
377+ )
378
379 def setUp(self):
380 """ Go to Time & Date page """
381@@ -45,7 +45,9 @@
382
383 def click_tz_search_field(self):
384 self.scroll_to_and_click(self.tz_page)
385- text_field = self.main_view.select_single(objectName='selectTimeZoneField')
386+ text_field = self.main_view.select_single(
387+ objectName='selectTimeZoneField'
388+ )
389 self.pointer.move_to_object(text_field)
390
391 def test_time_date_page(self):
392@@ -56,14 +58,17 @@
393 def test_tz_list_initially_empty(self):
394 """ Checks that no list is displayed initially """
395 self.scroll_to_and_click(self.tz_page)
396- labelVisible = self.main_view.select_single(objectName='nothingLabel').visible
397+ labelVisible = self.main_view.select_single(
398+ objectName='nothingLabel').visible
399 self.assertThat(labelVisible, Equals(True))
400
401 def test_searching_tz(self):
402 """ Check that searching for a valid location shows something """
403 self.click_tz_search_field()
404 self.keyboard.type('London, United Kingdom')
405- listview = self.main_view.select_single(objectName='locationsListView')
406+ listview = self.main_view.select_single(
407+ objectName='locationsListView'
408+ )
409 self.assertThat(listview.count, GreaterThan(0))
410
411 def test_searching_tz_not_found(self):
412@@ -72,7 +77,8 @@
413 self.keyboard.type('Oh no you don\'t!')
414 listview = self.main_view.select_single(objectName='locationsListView')
415 self.assertThat(listview.count, Equals(0))
416- labelVisible = self.main_view.select_single(objectName='nothingLabel').visible
417+ labelVisible = self.main_view.select_single(
418+ objectName='nothingLabel').visible
419 self.assertThat(labelVisible, Equals(True))
420
421 def test_manual_tz_selection(self):
422@@ -87,8 +93,9 @@
423 self.assertThat(self.tz_page.text, Equals('Europe/London'))
424
425 def test_same_tz_selection(self):
426- """ Check that manually setting a timezone then setting the same one doesn't
427- take you back to the index """
428+ """Check that manually setting a timezone then setting the same one
429+ doesn't take you back to the index.
430+ """
431 self.test_manual_tz_selection()
432 self.click_tz_search_field()
433 # This is also in Europe/London
434
435=== modified file 'tests/autopilot/ubuntu_system_settings/tests/test_plugins.py'
436--- tests/autopilot/ubuntu_system_settings/tests/test_plugins.py 2014-01-21 17:23:50 +0000
437+++ tests/autopilot/ubuntu_system_settings/tests/test_plugins.py 2014-03-11 14:59:49 +0000
438@@ -5,17 +5,18 @@
439 # under the terms of the GNU General Public License version 3, as published
440 # by the Free Software Foundation.
441
442-from time import sleep
443-
444 from autopilot.introspection.dbus import StateNotFoundError
445 from autopilot.matchers import Eventually
446-from testtools.matchers import Contains, Equals, NotEquals, GreaterThan, raises
447+from testtools.matchers import Equals, NotEquals, raises
448
449-from ubuntu_system_settings.tests import (UbuntuSystemSettingsTestCase,
450- UbuntuSystemSettingsUpowerTestCase,
451- UbuntuSystemSettingsBatteryTestCase)
452+from ubuntu_system_settings.tests import (
453+ UbuntuSystemSettingsTestCase,
454+ UbuntuSystemSettingsUpowerTestCase,
455+ UbuntuSystemSettingsBatteryTestCase
456+)
457 from ubuntu_system_settings.utils.i18n import ugettext as _
458
459+
460 class SystemSettingsTestCases(UbuntuSystemSettingsTestCase):
461 """ Tests for Ubuntu System Settings """
462
463@@ -27,30 +28,40 @@
464 header = self.main_view.select_single(objectName='systemSettingsPage')
465 self.assertThat(header, NotEquals(None))
466 self.assertThat(header.title, Eventually(Equals(_('System Settings'))))
467-
468+
469 def test_search(self):
470 """ Checks whether the Search box is available """
471 search = self.main_view.select_single(objectName='searchTextField')
472 self.assertThat(search, NotEquals(None))
473-
474+
475 def test_network_category(self):
476 """ Checks whether the Network category is available """
477- category = self.main_view.select_single(objectName='categoryGrid-network')
478+ category = self.main_view.select_single(
479+ objectName='categoryGrid-network'
480+ )
481 self.assertThat(category, NotEquals(None))
482- self.assertThat(category.categoryName, Eventually(Equals(_('Network'))))
483-
484+ self.assertThat(
485+ category.categoryName, Eventually(Equals(_('Network')))
486+ )
487+
488 def test_personal_category(self):
489 """ Checks whether the Personal category is available """
490- category = self.main_view.select_single(objectName='categoryGrid-personal')
491+ category = self.main_view.select_single(
492+ objectName='categoryGrid-personal'
493+ )
494 self.assertThat(category, NotEquals(None))
495- self.assertThat(category.categoryName, Eventually(Equals(_('Personal'))))
496-
497+ self.assertThat(
498+ category.categoryName, Eventually(Equals(_('Personal')))
499+ )
500+
501 def test_system_category(self):
502 """ Checks whether the System category is available """
503- category = self.main_view.select_single(objectName='categoryGrid-system')
504+ category = self.main_view.select_single(
505+ objectName='categoryGrid-system'
506+ )
507 self.assertThat(category, NotEquals(None))
508 self.assertThat(category.categoryName, Eventually(Equals(_('System'))))
509-
510+
511 def test_wifi_plugin(self):
512 """ Checks whether the Wi-Fi plugin is available """
513 plugin = self.main_view.select_single(objectName='entryComponent-wifi')
514@@ -58,70 +69,97 @@
515
516 def test_cellular_plugin(self):
517 """ Checks whether the Cellunar plugin is available """
518- plugin = self.main_view.select_single(objectName='entryComponent-cellular')
519+ plugin = self.main_view.select_single(
520+ objectName='entryComponent-cellular'
521+ )
522 self.assertThat(plugin, NotEquals(None))
523
524 def test_bluetooth_plugin(self):
525 """ Checks whether the Bluetooth plugin is available """
526- plugin = self.main_view.select_single(objectName='entryComponent-bluetooth')
527+ plugin = self.main_view.select_single(
528+ objectName='entryComponent-bluetooth'
529+ )
530 self.assertThat(plugin, NotEquals(None))
531
532 def test_background_plugin(self):
533 """ Checks whether the Background plugin is available """
534- plugin = self.main_view.select_single(objectName='entryComponent-background')
535+ plugin = self.main_view.select_single(
536+ objectName='entryComponent-background'
537+ )
538 self.assertThat(plugin, NotEquals(None))
539
540 def test_sound_plugin(self):
541 """ Checks whether the Sound plugin is available """
542- plugin = self.main_view.select_single(objectName='entryComponent-sound')
543+ plugin = self.main_view.select_single(
544+ objectName='entryComponent-sound'
545+ )
546 self.assertThat(plugin, NotEquals(None))
547
548 def test_language_plugin(self):
549 """ Checks whether the Language plugin is available """
550- plugin = self.main_view.select_single(objectName='entryComponent-language')
551+ plugin = self.main_view.select_single(
552+ objectName='entryComponent-language'
553+ )
554 self.assertThat(plugin, NotEquals(None))
555
556 def test_accounts_plugin(self):
557 """ Checks whether the Accounts plugin is available """
558- plugin = self.main_view.select_single(objectName='entryComponent-online-accounts')
559+ plugin = self.main_view.select_single(
560+ objectName='entryComponent-online-accounts'
561+ )
562 self.assertThat(plugin, NotEquals(None))
563
564 def test_timedate_plugin(self):
565 """ Checks whether the Time & Date plugin is available """
566- plugin = self.main_view.select_single(objectName='entryComponent-time-date')
567+ plugin = self.main_view.select_single(
568+ objectName='entryComponent-time-date'
569+ )
570 self.assertThat(plugin, NotEquals(None))
571
572 def test_security_plugin(self):
573 """ Checks whether the Security plugin is available """
574- plugin = self.main_view.select_single(objectName='entryComponent-security-privacy')
575+ plugin = self.main_view.select_single(
576+ objectName='entryComponent-security-privacy'
577+ )
578 self.assertThat(plugin, NotEquals(None))
579
580 def test_updates_plugin(self):
581 """ Checks whether the Updates plugin is available """
582- plugin = self.main_view.select_single(objectName='entryComponent-system-update')
583+ plugin = self.main_view.select_single(
584+ objectName='entryComponent-system-update'
585+ )
586 self.assertThat(plugin, NotEquals(None))
587
588+
589 class SystemSettingsUpowerTestCases(UbuntuSystemSettingsUpowerTestCase):
590 def setUp(self):
591 super(SystemSettingsUpowerTestCases, self).setUp()
592
593 def test_no_battery_plugin_without_battery(self):
594- """ Checks whether the Battery plugin is not available as we have no battery """
595- self.assertThat(lambda: self.main_view.select_single(objectName='entryComponent-battery'),
596- raises(StateNotFoundError))
597+ """ Checks whether the Battery plugin is not available as we
598+ have no battery.
599+ """
600+ self.assertThat(lambda: self.main_view.select_single(
601+ objectName='entryComponent-battery'),
602+ raises(StateNotFoundError)
603+ )
604
605 def test_battery_plugin_battery_hotplugging(self):
606 """ Checks whether hotplugging a battery makes the panel visible """
607 self.add_mock_battery()
608- plugin = self.main_view.select_single(objectName='entryComponent-battery')
609+ plugin = self.main_view.select_single(
610+ objectName='entryComponent-battery'
611+ )
612 self.assertThat(plugin, NotEquals(None))
613
614+
615 class SystemSettingsBatteryTestCases(UbuntuSystemSettingsBatteryTestCase):
616 def setUp(self):
617 super(SystemSettingsBatteryTestCases, self).setUp()
618
619 def test_battery_plugin(self):
620 """ checks whether the Battery plugin is available """
621- plugin = self.main_view.select_single(objectName='entryComponent-battery')
622+ plugin = self.main_view.select_single(
623+ objectName='entryComponent-battery'
624+ )
625 self.assertThat(plugin, NotEquals(None))
626-
627
628=== modified file 'tests/autopilot/ubuntu_system_settings/tests/test_search.py'
629--- tests/autopilot/ubuntu_system_settings/tests/test_search.py 2014-01-17 10:15:31 +0000
630+++ tests/autopilot/ubuntu_system_settings/tests/test_search.py 2014-03-11 14:59:49 +0000
631@@ -5,12 +5,8 @@
632 # under the terms of the GNU General Public License version 3, as published
633 # by the Free Software Foundation.
634
635-from time import sleep
636-
637-from autopilot.matchers import Eventually
638 from autopilot.introspection.dbus import StateNotFoundError
639-from testtools.matchers import Contains, Equals, NotEquals, GreaterThan
640-from unittest import skip
641+from testtools.matchers import Equals, NotEquals
642
643 from ubuntu_system_settings.tests import UbuntuSystemSettingsTestCase
644 from ubuntu_system_settings.utils.i18n import ugettext as _
645@@ -18,6 +14,7 @@
646
647 """ Tests for Ubuntu System Settings """
648
649+
650 class SearchTestCases(UbuntuSystemSettingsTestCase):
651 """ Tests for Search """
652
653@@ -37,8 +34,9 @@
654 sound = self.main_view.select_single(objectName='entryComponent-sound')
655 self.assertThat(sound, NotEquals(None))
656 try:
657- background = self.main_view.select_single(objectName='entryComponent-background')
658+ background = self.main_view.select_single(
659+ objectName='entryComponent-background'
660+ )
661 except StateNotFoundError:
662 background = None
663 self.assertThat(background, Equals(None))
664-
665
666=== modified file 'tests/autopilot/ubuntu_system_settings/tests/test_system_updates.py'
667--- tests/autopilot/ubuntu_system_settings/tests/test_system_updates.py 2014-02-04 21:05:28 +0000
668+++ tests/autopilot/ubuntu_system_settings/tests/test_system_updates.py 2014-03-11 14:59:49 +0000
669@@ -5,15 +5,10 @@
670 # under the terms of the GNU General Public License version 3, as published
671 # by the Free Software Foundation.
672
673-from time import sleep
674-
675-from autopilot.matchers import Eventually
676 from autopilot.introspection.dbus import StateNotFoundError
677-from testtools.matchers import Contains, Equals, NotEquals, GreaterThan, raises
678-from unittest import skip
679+from testtools.matchers import NotEquals, raises
680
681 from ubuntu_system_settings.tests import SystemUpdatesBaseTestCase
682-from ubuntu_system_settings.utils.i18n import ugettext as _
683
684
685 """ Tests for Ubuntu System Settings """
686
687=== modified file 'tests/autopilot/ubuntu_system_settings/utils/i18n.py'
688--- tests/autopilot/ubuntu_system_settings/utils/i18n.py 2013-12-17 17:29:03 +0000
689+++ tests/autopilot/ubuntu_system_settings/utils/i18n.py 2014-03-11 14:59:49 +0000
690@@ -8,15 +8,17 @@
691 import locale
692 import gettext
693
694-APP_NAME='ubuntu-system-settings'
695-LOCALE_DIR='/usr/share/locale/'
696+APP_NAME = 'ubuntu-system-settings'
697+LOCALE_DIR = '/usr/share/locale/'
698
699 lc, encoding = locale.getdefaultlocale()
700
701 if not lc:
702 lc = 'C'
703
704-language = gettext.translation(APP_NAME, LOCALE_DIR, languages=[lc], fallback=True)
705+language = gettext.translation(
706+ APP_NAME, LOCALE_DIR, languages=[lc], fallback=True
707+)
708
709 # UTF-8
710 ugettext = language.ugettext
711
712=== added file 'tests/test_code.py'
713--- tests/test_code.py 1970-01-01 00:00:00 +0000
714+++ tests/test_code.py 2014-03-11 14:59:49 +0000
715@@ -0,0 +1,47 @@
716+#!/usr/bin/python
717+
718+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
719+# Copyright 2014 Canonical
720+#
721+# This program is free software: you can redistribute it and/or modify it
722+# under the terms of the GNU General Public License version 3, as published
723+# by the Free Software Foundation.
724+
725+import subprocess
726+import sys
727+import unittest
728+
729+
730+class StaticCodeTests(unittest.TestCase):
731+
732+ def _is_tool_installed(tool):
733+ return subprocess.call(['which', tool],
734+ stdout=subprocess.PIPE)
735+
736+ @unittest.skipIf(
737+ _is_tool_installed('pyflakes') != 0, 'pyflakes not installed'
738+ )
739+ def test_pyflakes(self):
740+ pyflakes = subprocess.Popen(
741+ ['pyflakes', '.'],
742+ stdout=subprocess.PIPE, universal_newlines=True
743+ )
744+ (out, err) = pyflakes.communicate()
745+ self.assertEqual(pyflakes.returncode, 0, out)
746+
747+ @unittest.skipIf(
748+ _is_tool_installed('pep8') != 0, 'pep8 not installed'
749+ )
750+ def test_pep8(self):
751+ pep8 = subprocess.Popen(
752+ ['pep8', '.'],
753+ stdout=subprocess.PIPE, universal_newlines=True
754+ )
755+ (out, err) = pep8.communicate()
756+ self.assertEqual(pep8.returncode, 0, out)
757+
758+
759+if __name__ == '__main__':
760+ unittest.main(
761+ testRunner=unittest.TextTestRunner(stream=sys.stdout, verbosity=2)
762+ )

Subscribers

People subscribed via source and target branches