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
=== modified file 'debian/control'
--- debian/control 2014-03-03 17:03:21 +0000
+++ debian/control 2014-03-11 14:59:49 +0000
@@ -24,6 +24,8 @@
24 libapt-pkg-dev,24 libapt-pkg-dev,
25 xvfb,25 xvfb,
26 cmake,26 cmake,
27 pep8,
28 pyflakes,
27Standards-Version: 3.9.429Standards-Version: 3.9.4
28Homepage: https://launchpad.net/ubuntu-system-settings30Homepage: https://launchpad.net/ubuntu-system-settings
29# If you aren't a member of ~system-settings-touch but need to upload packaging31# If you aren't a member of ~system-settings-touch but need to upload packaging
3032
=== modified file 'debian/rules'
--- debian/rules 2014-03-03 17:03:21 +0000
+++ debian/rules 2014-03-11 14:59:49 +0000
@@ -21,3 +21,6 @@
2121
22%:22%:
23 dh $@ --fail-missing --with python2,migrations23 dh $@ --fail-missing --with python2,migrations
24
25override_dh_auto_test:
26 python tests/test_code.py
2427
=== modified file 'debian/ubuntu-system-settings-sound-gsettings-to-accountsservice.py' (properties changed: -x to +x)
--- debian/ubuntu-system-settings-sound-gsettings-to-accountsservice.py 2014-01-09 13:02:44 +0000
+++ debian/ubuntu-system-settings-sound-gsettings-to-accountsservice.py 2014-03-11 14:59:49 +0000
@@ -20,9 +20,12 @@
2020
21# Migrate ubuntu-system-settings sound panel settings from GSettings to21# Migrate ubuntu-system-settings sound panel settings from GSettings to
22# AccountsService22# AccountsService
23 23
24from __future__ import print_function
25
24import dbus26import dbus
25import os27import os
28import sys
2629
27from gi.repository import Gio30from gi.repository import Gio
2831
@@ -30,20 +33,27 @@
30manager_proxy = system_bus.get_object('org.freedesktop.Accounts',33manager_proxy = system_bus.get_object('org.freedesktop.Accounts',
31 '/org/freedesktop/Accounts')34 '/org/freedesktop/Accounts')
32object_path = manager_proxy.FindUserById(35object_path = manager_proxy.FindUserById(
33 os.getuid(), dbus_interface='org.freedesktop.Accounts')36 os.getuid(), dbus_interface='org.freedesktop.Accounts'
37)
34user_proxy = system_bus.get_object('org.freedesktop.Accounts', object_path)38user_proxy = system_bus.get_object('org.freedesktop.Accounts', object_path)
3539
36gsettings = Gio.Settings(schema="com.ubuntu.touch.sound")40gsettings = Gio.Settings(schema="com.ubuntu.touch.sound")
3741
42
38def get_string(key):43def get_string(key):
39 return gsettings.get_string(key)44 return gsettings.get_string(key)
4045
46
41def get_bool(key):47def get_bool(key):
42 return gsettings.get_boolean(key)48 return gsettings.get_boolean(key)
4349
50
44def set_as_setting(interface, setting, value):51def set_as_setting(interface, setting, value):
45 user_proxy.Set(interface, setting, value, 52 try:
46 dbus_interface=dbus.PROPERTIES_IFACE)53 user_proxy.Set(interface, setting, value,
54 dbus_interface=dbus.PROPERTIES_IFACE)
55 except dbus.exceptions.DBusException as e:
56 print("Couldn't update %s: %s" % (setting, e), file=sys.stderr)
4757
48# (gsettings key, accountsservice key, function to retrieve from gsettings)58# (gsettings key, accountsservice key, function to retrieve from gsettings)
49keys = [('silent-mode', 'SilentMode', get_bool),59keys = [('silent-mode', 'SilentMode', get_bool),
5060
=== modified file 'tests/autopilot/ubuntu_system_settings/tests/__init__.py'
--- tests/autopilot/ubuntu_system_settings/tests/__init__.py 2014-02-18 15:42:24 +0000
+++ tests/autopilot/ubuntu_system_settings/tests/__init__.py 2014-03-11 14:59:49 +0000
@@ -13,7 +13,6 @@
1313
14from autopilot.input import Mouse, Touch, Pointer14from autopilot.input import Mouse, Touch, Pointer
15from autopilot.platform import model15from autopilot.platform import model
16from autopilot.testcase import AutopilotTestCase
17from autopilot.matchers import Eventually16from autopilot.matchers import Eventually
18from testtools.matchers import Equals, NotEquals, GreaterThan17from testtools.matchers import Equals, NotEquals, GreaterThan
1918
@@ -25,12 +24,13 @@
25import subprocess24import subprocess
26from time import sleep25from time import sleep
2726
27
28class UbuntuSystemSettingsTestCase(UbuntuUIToolkitAppTestCase):28class UbuntuSystemSettingsTestCase(UbuntuUIToolkitAppTestCase):
29 """ Base class for Ubuntu System Settings """29 """ Base class for Ubuntu System Settings """
30 if model() == 'Desktop':30 if model() == 'Desktop':
31 scenarios = [ ('with mouse', dict(input_device_class=Mouse)) ]31 scenarios = [('with mouse', dict(input_device_class=Mouse))]
32 else:32 else:
33 scenarios = [ ('with touch', dict(input_device_class=Touch)) ]33 scenarios = [('with touch', dict(input_device_class=Touch))]
3434
35 def setUp(self, panel=None):35 def setUp(self, panel=None):
36 super(UbuntuSystemSettingsTestCase, self).setUp()36 super(UbuntuSystemSettingsTestCase, self).setUp()
@@ -40,7 +40,8 @@
40 def launch_system_settings(self, panel=None):40 def launch_system_settings(self, panel=None):
41 params = ['/usr/bin/system-settings']41 params = ['/usr/bin/system-settings']
42 if (model() != 'Desktop'):42 if (model() != 'Desktop'):
43 params.append('--desktop_file_hint=/usr/share/applications/ubuntu-system-settings.desktop')43 params.append('--desktop_file_hint=/usr/share/applications/'
44 'ubuntu-system-settings.desktop')
4445
45 # Launch to a specific panel46 # Launch to a specific panel
46 if panel is not None:47 if panel is not None:
@@ -69,8 +70,8 @@
69 page_center_x = int(page_right / 2)70 page_center_x = int(page_right / 2)
70 page_center_y = int(page_bottom / 2)71 page_center_y = int(page_bottom / 2)
71 while obj.globalRect[1] + obj.height > page_bottom:72 while obj.globalRect[1] + obj.height > page_bottom:
72 self.pointer.drag(page_center_x, page_center_y, 73 self.pointer.drag(page_center_x, page_center_y,
73 page_center_x, page_center_y - obj.height * 2)74 page_center_x, page_center_y - obj.height * 2)
74 # avoid a flick75 # avoid a flick
75 sleep(0.5)76 sleep(0.5)
7677
@@ -96,7 +97,9 @@
9697
97 def add_mock_battery(self):98 def add_mock_battery(self):
98 """ Make sure we have a battery """99 """ Make sure we have a battery """
99 self.dbusmock.AddDischargingBattery('mock_BATTERY', 'Battery', 50.0, 10)100 self.dbusmock.AddDischargingBattery(
101 'mock_BATTERY', 'Battery', 50.0, 10
102 )
100103
101104
102class UbuntuSystemSettingsBatteryTestCase(UbuntuSystemSettingsUpowerTestCase):105class UbuntuSystemSettingsBatteryTestCase(UbuntuSystemSettingsUpowerTestCase):
@@ -123,37 +126,39 @@
123 def setUp(self, panel=None):126 def setUp(self, panel=None):
124 self.obj_ofono.Reset()127 self.obj_ofono.Reset()
125 # Add an available carrier128 # Add an available carrier
126 self.dbusmock.AddObject('/ril_0/operator/op2',129 self.dbusmock.AddObject(
127 'org.ofono.NetworkOperator',130 '/ril_0/operator/op2',
128 {131 'org.ofono.NetworkOperator',
129 'Name': 'my.cool.telco',132 {
130 'Status': 'available',133 'Name': 'my.cool.telco',
131 'MobileCountryCode': '777',134 'Status': 'available',
132 'MobileNetworkCode': '22',135 'MobileCountryCode': '777',
133 'Technologies': ['gsm'],136 'MobileNetworkCode': '22',
134 },137 'Technologies': ['gsm'],
135 [138 },
136 ('GetProperties', '', 'a{sv}',139 [
137 'ret = self.GetAll("org.ofono.NetworkOperator")'),140 ('GetProperties', '', 'a{sv}',
138 ('Register', '', '', ''),141 'ret = self.GetAll("org.ofono.NetworkOperator")'),
139 ]142 ('Register', '', '', ''),
140 )143 ]
144 )
141 # Add a forbidden carrier145 # Add a forbidden carrier
142 self.dbusmock.AddObject('/ril_0/operator/op3',146 self.dbusmock.AddObject(
143 'org.ofono.NetworkOperator',147 '/ril_0/operator/op3',
144 {148 'org.ofono.NetworkOperator',
145 'Name': 'my.bad.telco',149 {
146 'Status': 'forbidden',150 'Name': 'my.bad.telco',
147 'MobileCountryCode': '777',151 'Status': 'forbidden',
148 'MobileNetworkCode': '22',152 'MobileCountryCode': '777',
149 'Technologies': ['gsm'],153 'MobileNetworkCode': '22',
150 },154 'Technologies': ['gsm'],
151 [155 },
152 ('GetProperties', '', 'a{sv}',156 [
153 'ret = self.GetAll("org.ofono.NetworkOperator")'),157 ('GetProperties', '', 'a{sv}',
154 ('Register', '', '', ''),158 'ret = self.GetAll("org.ofono.NetworkOperator")'),
155 ]159 ('Register', '', '', ''),
156 )160 ]
161 )
157 super(UbuntuSystemSettingsOfonoTestCase, self).setUp('cellular')162 super(UbuntuSystemSettingsOfonoTestCase, self).setUp('cellular')
158163
159 @property164 @property
@@ -194,8 +199,7 @@
194 """ Checks whether an space item exists and returns a value """199 """ Checks whether an space item exists and returns a value """
195 item = self.storage_page.select_single(objectName=object_name)200 item = self.storage_page.select_single(objectName=object_name)
196 self.assertThat(item, NotEquals(None))201 self.assertThat(item, NotEquals(None))
197 label = item.label # Label202 label = item.label # Label
198 space = item.value # Disk space (bytes)
199 self.assertThat(label, Equals(text))203 self.assertThat(label, Equals(text))
200 # Get item's label204 # Get item's label
201 size_label = item.select_single(objectName='sizeLabel')205 size_label = item.select_single(objectName='sizeLabel')
202206
=== modified file 'tests/autopilot/ubuntu_system_settings/tests/test_about.py'
--- tests/autopilot/ubuntu_system_settings/tests/test_about.py 2014-01-27 16:17:57 +0000
+++ tests/autopilot/ubuntu_system_settings/tests/test_about.py 2014-03-11 14:59:49 +0000
@@ -8,13 +8,17 @@
8from time import sleep8from time import sleep
99
10from autopilot.platform import model10from autopilot.platform import model
11from autopilot.matchers import Eventually
12from testtools.matchers import Equals, NotEquals, GreaterThan11from testtools.matchers import Equals, NotEquals, GreaterThan
13from unittest import expectedFailure12from unittest import expectedFailure
1413
15from ubuntu_system_settings.tests import AboutBaseTestCase, StorageBaseTestCase, LicenseBaseTestCase14from ubuntu_system_settings.tests import (
15 AboutBaseTestCase,
16 StorageBaseTestCase,
17 LicenseBaseTestCase
18)
16from ubuntu_system_settings.utils.i18n import ugettext as _19from ubuntu_system_settings.utils.i18n import ugettext as _
1720
21
18class AboutTestCase(AboutBaseTestCase):22class AboutTestCase(AboutBaseTestCase):
19 """ Tests for About this phone Page """23 """ Tests for About this phone Page """
2024
@@ -96,7 +100,7 @@
96 """ Tests for Storage """100 """ Tests for Storage """
97101
98 def test_storage_page(self):102 def test_storage_page(self):
99 """ Check whether Storage page is available """ 103 """ Check whether Storage page is available """
100 self.assertThat(self.storage_page, NotEquals(None))104 self.assertThat(self.storage_page, NotEquals(None))
101105
102 def test_disk(self):106 def test_disk(self):
@@ -136,7 +140,9 @@
136140
137 def test_installed_apps(self):141 def test_installed_apps(self):
138 """ Checks whether Installed Apps list is available """142 """ Checks whether Installed Apps list is available """
139 installed_apps_list_view = self.storage_page.select_single(objectName='installedAppsListView')143 installed_apps_list_view = self.storage_page.select_single(
144 objectName='installedAppsListView'
145 )
140 self.assertThat(installed_apps_list_view, NotEquals(None))146 self.assertThat(installed_apps_list_view, NotEquals(None))
141147
142148
@@ -145,6 +151,5 @@
145151
146 @expectedFailure152 @expectedFailure
147 def test_licenses_page(self):153 def test_licenses_page(self):
148 """ Check whether Storage page is available """ 154 """ Check whether Storage page is available """
149 self.assertThat(self.licenses_page, NotEquals(None))155 self.assertThat(self.licenses_page, NotEquals(None))
150
151156
=== modified file 'tests/autopilot/ubuntu_system_settings/tests/test_cellular.py'
--- tests/autopilot/ubuntu_system_settings/tests/test_cellular.py 2014-02-18 12:16:22 +0000
+++ tests/autopilot/ubuntu_system_settings/tests/test_cellular.py 2014-03-11 14:59:49 +0000
@@ -5,29 +5,28 @@
5# under the terms of the GNU General Public License version 3, as published5# under the terms of the GNU General Public License version 3, as published
6# by the Free Software Foundation.6# by the Free Software Foundation.
77
8from time import sleep
9
10from autopilot.introspection.dbus import StateNotFoundError8from autopilot.introspection.dbus import StateNotFoundError
11from autopilot.matchers import Eventually
12from testtools.matchers import Equals, NotEquals, raises9from testtools.matchers import Equals, NotEquals, raises
13from unittest import expectedFailure
1410
15from ubuntu_system_settings.tests import UbuntuSystemSettingsOfonoTestCase11from ubuntu_system_settings.tests import UbuntuSystemSettingsOfonoTestCase
16from ubuntu_system_settings.utils.i18n import ugettext as _12from ubuntu_system_settings.utils.i18n import ugettext as _
1713
18from ubuntuuitoolkit import emulators as toolkit_emulators14from ubuntuuitoolkit import emulators as toolkit_emulators
1915
16
20class CellularTestCase(UbuntuSystemSettingsOfonoTestCase):17class CellularTestCase(UbuntuSystemSettingsOfonoTestCase):
21 """ Tests for cellular Page """18 """ Tests for cellular Page """
2219
23 def navigate_to_manual(self):20 def navigate_to_manual(self):
24 selector = self.cellular_page.select_single(21 selector = self.cellular_page.select_single(
25 toolkit_emulators.ItemSelector,22 toolkit_emulators.ItemSelector,
26 objectName="autoChooseCarrierSelector")23 objectName="autoChooseCarrierSelector"
24 )
27 manual = selector.select_single('Label', text=_("Manually"))25 manual = selector.select_single('Label', text=_("Manually"))
28 self.pointer.click_object(manual)26 self.pointer.click_object(manual)
29 choosecarrier = self.cellular_page.select_single(27 choosecarrier = self.cellular_page.select_single(
30 objectName="chooseCarrier")28 objectName="chooseCarrier"
29 )
31 self.pointer.click_object(choosecarrier)30 self.pointer.click_object(choosecarrier)
32 self.assertThat(self.choose_page.title, Equals(_("Carrier")))31 self.assertThat(self.choose_page.title, Equals(_("Carrier")))
3332
@@ -40,8 +39,9 @@
40 """ Tests whether the current network is visible and selected """39 """ Tests whether the current network is visible and selected """
41 self.navigate_to_manual()40 self.navigate_to_manual()
42 carriers = self.choose_page.select_single(41 carriers = self.choose_page.select_single(
43 toolkit_emulators.ItemSelector,42 toolkit_emulators.ItemSelector,
44 objectName="carrierSelector")43 objectName="carrierSelector"
44 )
45 # TODO: Once there is a proper ItemSelector emulator, get the items45 # TODO: Once there is a proper ItemSelector emulator, get the items
46 # from it and check 'fake.tel' is the selected one.46 # from it and check 'fake.tel' is the selected one.
47 manual = carriers.select_single('Label', text="fake.tel")47 manual = carriers.select_single('Label', text="fake.tel")
@@ -52,8 +52,9 @@
52 """ Tests whether an alternative available network is displayed """52 """ Tests whether an alternative available network is displayed """
53 self.navigate_to_manual()53 self.navigate_to_manual()
54 carriers = self.choose_page.select_single(54 carriers = self.choose_page.select_single(
55 toolkit_emulators.ItemSelector,55 toolkit_emulators.ItemSelector,
56 objectName="carrierSelector")56 objectName="carrierSelector"
57 )
57 manual = carriers.select_single('Label', text="my.cool.telco")58 manual = carriers.select_single('Label', text="my.cool.telco")
58 self.assertThat(manual, NotEquals(None))59 self.assertThat(manual, NotEquals(None))
5960
@@ -61,7 +62,10 @@
61 """ Ensures that a forbidden network is not shown """62 """ Ensures that a forbidden network is not shown """
62 self.navigate_to_manual()63 self.navigate_to_manual()
63 carriers = self.choose_page.select_single(64 carriers = self.choose_page.select_single(
64 toolkit_emulators.ItemSelector,65 toolkit_emulators.ItemSelector,
65 objectName="carrierSelector")66 objectName="carrierSelector"
66 self.assertThat(lambda: carriers.select_single('Label', text="my.bad.telco"),67 )
67 raises(StateNotFoundError))68 self.assertThat(
69 lambda: carriers.select_single('Label', text="my.bad.telco"),
70 raises(StateNotFoundError)
71 )
6872
=== modified file 'tests/autopilot/ubuntu_system_settings/tests/test_datetime.py'
--- tests/autopilot/ubuntu_system_settings/tests/test_datetime.py 2014-01-30 16:42:51 +0000
+++ tests/autopilot/ubuntu_system_settings/tests/test_datetime.py 2014-03-11 14:59:49 +0000
@@ -5,12 +5,10 @@
5# under the terms of the GNU General Public License version 3, as published5# under the terms of the GNU General Public License version 3, as published
6# by the Free Software Foundation.6# by the Free Software Foundation.
77
8import dbus
9import dbusmock8import dbusmock
10import subprocess9import subprocess
11from time import sleep10from time import sleep
1211
13from autopilot.platform import model
14from autopilot.matchers import Eventually12from autopilot.matchers import Eventually
15from testtools.matchers import Equals, NotEquals, GreaterThan13from testtools.matchers import Equals, NotEquals, GreaterThan
1614
@@ -19,6 +17,7 @@
1917
20from ubuntuuitoolkit import emulators as toolkit_emulators18from ubuntuuitoolkit import emulators as toolkit_emulators
2119
20
22class TimeDateTestCase(UbuntuSystemSettingsTestCase,21class TimeDateTestCase(UbuntuSystemSettingsTestCase,
23 dbusmock.DBusTestCase):22 dbusmock.DBusTestCase):
24 """ Tests for the Time & Date Page """23 """ Tests for the Time & Date Page """
@@ -27,8 +26,9 @@
27 def setUpClass(klass):26 def setUpClass(klass):
28 klass.start_system_bus()27 klass.start_system_bus()
29 klass.dbus_con = klass.get_dbus(True)28 klass.dbus_con = klass.get_dbus(True)
30 (klass.p_mock,klass.obj_timedate1) = klass.spawn_server_template(29 (klass.p_mock, klass.obj_timedate1) = klass.spawn_server_template(
31 'timedated', {}, stdout=subprocess.PIPE)30 'timedated', {}, stdout=subprocess.PIPE
31 )
3232
33 def setUp(self):33 def setUp(self):
34 """ Go to Time & Date page """34 """ Go to Time & Date page """
@@ -45,7 +45,9 @@
4545
46 def click_tz_search_field(self):46 def click_tz_search_field(self):
47 self.scroll_to_and_click(self.tz_page)47 self.scroll_to_and_click(self.tz_page)
48 text_field = self.main_view.select_single(objectName='selectTimeZoneField')48 text_field = self.main_view.select_single(
49 objectName='selectTimeZoneField'
50 )
49 self.pointer.move_to_object(text_field)51 self.pointer.move_to_object(text_field)
5052
51 def test_time_date_page(self):53 def test_time_date_page(self):
@@ -56,14 +58,17 @@
56 def test_tz_list_initially_empty(self):58 def test_tz_list_initially_empty(self):
57 """ Checks that no list is displayed initially """59 """ Checks that no list is displayed initially """
58 self.scroll_to_and_click(self.tz_page)60 self.scroll_to_and_click(self.tz_page)
59 labelVisible = self.main_view.select_single(objectName='nothingLabel').visible61 labelVisible = self.main_view.select_single(
62 objectName='nothingLabel').visible
60 self.assertThat(labelVisible, Equals(True))63 self.assertThat(labelVisible, Equals(True))
6164
62 def test_searching_tz(self):65 def test_searching_tz(self):
63 """ Check that searching for a valid location shows something """66 """ Check that searching for a valid location shows something """
64 self.click_tz_search_field()67 self.click_tz_search_field()
65 self.keyboard.type('London, United Kingdom')68 self.keyboard.type('London, United Kingdom')
66 listview = self.main_view.select_single(objectName='locationsListView')69 listview = self.main_view.select_single(
70 objectName='locationsListView'
71 )
67 self.assertThat(listview.count, GreaterThan(0))72 self.assertThat(listview.count, GreaterThan(0))
6873
69 def test_searching_tz_not_found(self):74 def test_searching_tz_not_found(self):
@@ -72,7 +77,8 @@
72 self.keyboard.type('Oh no you don\'t!')77 self.keyboard.type('Oh no you don\'t!')
73 listview = self.main_view.select_single(objectName='locationsListView')78 listview = self.main_view.select_single(objectName='locationsListView')
74 self.assertThat(listview.count, Equals(0))79 self.assertThat(listview.count, Equals(0))
75 labelVisible = self.main_view.select_single(objectName='nothingLabel').visible80 labelVisible = self.main_view.select_single(
81 objectName='nothingLabel').visible
76 self.assertThat(labelVisible, Equals(True))82 self.assertThat(labelVisible, Equals(True))
7783
78 def test_manual_tz_selection(self):84 def test_manual_tz_selection(self):
@@ -87,8 +93,9 @@
87 self.assertThat(self.tz_page.text, Equals('Europe/London'))93 self.assertThat(self.tz_page.text, Equals('Europe/London'))
8894
89 def test_same_tz_selection(self):95 def test_same_tz_selection(self):
90 """ Check that manually setting a timezone then setting the same one doesn't96 """Check that manually setting a timezone then setting the same one
91 take you back to the index """97 doesn't take you back to the index.
98 """
92 self.test_manual_tz_selection()99 self.test_manual_tz_selection()
93 self.click_tz_search_field()100 self.click_tz_search_field()
94 # This is also in Europe/London101 # This is also in Europe/London
95102
=== modified file 'tests/autopilot/ubuntu_system_settings/tests/test_plugins.py'
--- tests/autopilot/ubuntu_system_settings/tests/test_plugins.py 2014-01-21 17:23:50 +0000
+++ tests/autopilot/ubuntu_system_settings/tests/test_plugins.py 2014-03-11 14:59:49 +0000
@@ -5,17 +5,18 @@
5# under the terms of the GNU General Public License version 3, as published5# under the terms of the GNU General Public License version 3, as published
6# by the Free Software Foundation.6# by the Free Software Foundation.
77
8from time import sleep
9
10from autopilot.introspection.dbus import StateNotFoundError8from autopilot.introspection.dbus import StateNotFoundError
11from autopilot.matchers import Eventually9from autopilot.matchers import Eventually
12from testtools.matchers import Contains, Equals, NotEquals, GreaterThan, raises10from testtools.matchers import Equals, NotEquals, raises
1311
14from ubuntu_system_settings.tests import (UbuntuSystemSettingsTestCase,12from ubuntu_system_settings.tests import (
15 UbuntuSystemSettingsUpowerTestCase,13 UbuntuSystemSettingsTestCase,
16 UbuntuSystemSettingsBatteryTestCase)14 UbuntuSystemSettingsUpowerTestCase,
15 UbuntuSystemSettingsBatteryTestCase
16)
17from ubuntu_system_settings.utils.i18n import ugettext as _17from ubuntu_system_settings.utils.i18n import ugettext as _
1818
19
19class SystemSettingsTestCases(UbuntuSystemSettingsTestCase):20class SystemSettingsTestCases(UbuntuSystemSettingsTestCase):
20 """ Tests for Ubuntu System Settings """21 """ Tests for Ubuntu System Settings """
2122
@@ -27,30 +28,40 @@
27 header = self.main_view.select_single(objectName='systemSettingsPage')28 header = self.main_view.select_single(objectName='systemSettingsPage')
28 self.assertThat(header, NotEquals(None))29 self.assertThat(header, NotEquals(None))
29 self.assertThat(header.title, Eventually(Equals(_('System Settings'))))30 self.assertThat(header.title, Eventually(Equals(_('System Settings'))))
30 31
31 def test_search(self):32 def test_search(self):
32 """ Checks whether the Search box is available """33 """ Checks whether the Search box is available """
33 search = self.main_view.select_single(objectName='searchTextField')34 search = self.main_view.select_single(objectName='searchTextField')
34 self.assertThat(search, NotEquals(None))35 self.assertThat(search, NotEquals(None))
35 36
36 def test_network_category(self):37 def test_network_category(self):
37 """ Checks whether the Network category is available """38 """ Checks whether the Network category is available """
38 category = self.main_view.select_single(objectName='categoryGrid-network')39 category = self.main_view.select_single(
40 objectName='categoryGrid-network'
41 )
39 self.assertThat(category, NotEquals(None))42 self.assertThat(category, NotEquals(None))
40 self.assertThat(category.categoryName, Eventually(Equals(_('Network'))))43 self.assertThat(
41 44 category.categoryName, Eventually(Equals(_('Network')))
45 )
46
42 def test_personal_category(self):47 def test_personal_category(self):
43 """ Checks whether the Personal category is available """48 """ Checks whether the Personal category is available """
44 category = self.main_view.select_single(objectName='categoryGrid-personal')49 category = self.main_view.select_single(
50 objectName='categoryGrid-personal'
51 )
45 self.assertThat(category, NotEquals(None))52 self.assertThat(category, NotEquals(None))
46 self.assertThat(category.categoryName, Eventually(Equals(_('Personal'))))53 self.assertThat(
47 54 category.categoryName, Eventually(Equals(_('Personal')))
55 )
56
48 def test_system_category(self):57 def test_system_category(self):
49 """ Checks whether the System category is available """58 """ Checks whether the System category is available """
50 category = self.main_view.select_single(objectName='categoryGrid-system')59 category = self.main_view.select_single(
60 objectName='categoryGrid-system'
61 )
51 self.assertThat(category, NotEquals(None))62 self.assertThat(category, NotEquals(None))
52 self.assertThat(category.categoryName, Eventually(Equals(_('System'))))63 self.assertThat(category.categoryName, Eventually(Equals(_('System'))))
53 64
54 def test_wifi_plugin(self):65 def test_wifi_plugin(self):
55 """ Checks whether the Wi-Fi plugin is available """66 """ Checks whether the Wi-Fi plugin is available """
56 plugin = self.main_view.select_single(objectName='entryComponent-wifi')67 plugin = self.main_view.select_single(objectName='entryComponent-wifi')
@@ -58,70 +69,97 @@
5869
59 def test_cellular_plugin(self):70 def test_cellular_plugin(self):
60 """ Checks whether the Cellunar plugin is available """71 """ Checks whether the Cellunar plugin is available """
61 plugin = self.main_view.select_single(objectName='entryComponent-cellular')72 plugin = self.main_view.select_single(
73 objectName='entryComponent-cellular'
74 )
62 self.assertThat(plugin, NotEquals(None))75 self.assertThat(plugin, NotEquals(None))
6376
64 def test_bluetooth_plugin(self):77 def test_bluetooth_plugin(self):
65 """ Checks whether the Bluetooth plugin is available """78 """ Checks whether the Bluetooth plugin is available """
66 plugin = self.main_view.select_single(objectName='entryComponent-bluetooth')79 plugin = self.main_view.select_single(
80 objectName='entryComponent-bluetooth'
81 )
67 self.assertThat(plugin, NotEquals(None))82 self.assertThat(plugin, NotEquals(None))
6883
69 def test_background_plugin(self):84 def test_background_plugin(self):
70 """ Checks whether the Background plugin is available """85 """ Checks whether the Background plugin is available """
71 plugin = self.main_view.select_single(objectName='entryComponent-background')86 plugin = self.main_view.select_single(
87 objectName='entryComponent-background'
88 )
72 self.assertThat(plugin, NotEquals(None))89 self.assertThat(plugin, NotEquals(None))
7390
74 def test_sound_plugin(self):91 def test_sound_plugin(self):
75 """ Checks whether the Sound plugin is available """92 """ Checks whether the Sound plugin is available """
76 plugin = self.main_view.select_single(objectName='entryComponent-sound')93 plugin = self.main_view.select_single(
94 objectName='entryComponent-sound'
95 )
77 self.assertThat(plugin, NotEquals(None))96 self.assertThat(plugin, NotEquals(None))
7897
79 def test_language_plugin(self):98 def test_language_plugin(self):
80 """ Checks whether the Language plugin is available """99 """ Checks whether the Language plugin is available """
81 plugin = self.main_view.select_single(objectName='entryComponent-language')100 plugin = self.main_view.select_single(
101 objectName='entryComponent-language'
102 )
82 self.assertThat(plugin, NotEquals(None))103 self.assertThat(plugin, NotEquals(None))
83104
84 def test_accounts_plugin(self):105 def test_accounts_plugin(self):
85 """ Checks whether the Accounts plugin is available """106 """ Checks whether the Accounts plugin is available """
86 plugin = self.main_view.select_single(objectName='entryComponent-online-accounts')107 plugin = self.main_view.select_single(
108 objectName='entryComponent-online-accounts'
109 )
87 self.assertThat(plugin, NotEquals(None))110 self.assertThat(plugin, NotEquals(None))
88111
89 def test_timedate_plugin(self):112 def test_timedate_plugin(self):
90 """ Checks whether the Time & Date plugin is available """113 """ Checks whether the Time & Date plugin is available """
91 plugin = self.main_view.select_single(objectName='entryComponent-time-date')114 plugin = self.main_view.select_single(
115 objectName='entryComponent-time-date'
116 )
92 self.assertThat(plugin, NotEquals(None))117 self.assertThat(plugin, NotEquals(None))
93118
94 def test_security_plugin(self):119 def test_security_plugin(self):
95 """ Checks whether the Security plugin is available """120 """ Checks whether the Security plugin is available """
96 plugin = self.main_view.select_single(objectName='entryComponent-security-privacy')121 plugin = self.main_view.select_single(
122 objectName='entryComponent-security-privacy'
123 )
97 self.assertThat(plugin, NotEquals(None))124 self.assertThat(plugin, NotEquals(None))
98125
99 def test_updates_plugin(self):126 def test_updates_plugin(self):
100 """ Checks whether the Updates plugin is available """127 """ Checks whether the Updates plugin is available """
101 plugin = self.main_view.select_single(objectName='entryComponent-system-update')128 plugin = self.main_view.select_single(
129 objectName='entryComponent-system-update'
130 )
102 self.assertThat(plugin, NotEquals(None))131 self.assertThat(plugin, NotEquals(None))
103132
133
104class SystemSettingsUpowerTestCases(UbuntuSystemSettingsUpowerTestCase):134class SystemSettingsUpowerTestCases(UbuntuSystemSettingsUpowerTestCase):
105 def setUp(self):135 def setUp(self):
106 super(SystemSettingsUpowerTestCases, self).setUp()136 super(SystemSettingsUpowerTestCases, self).setUp()
107137
108 def test_no_battery_plugin_without_battery(self):138 def test_no_battery_plugin_without_battery(self):
109 """ Checks whether the Battery plugin is not available as we have no battery """139 """ Checks whether the Battery plugin is not available as we
110 self.assertThat(lambda: self.main_view.select_single(objectName='entryComponent-battery'),140 have no battery.
111 raises(StateNotFoundError))141 """
142 self.assertThat(lambda: self.main_view.select_single(
143 objectName='entryComponent-battery'),
144 raises(StateNotFoundError)
145 )
112146
113 def test_battery_plugin_battery_hotplugging(self):147 def test_battery_plugin_battery_hotplugging(self):
114 """ Checks whether hotplugging a battery makes the panel visible """148 """ Checks whether hotplugging a battery makes the panel visible """
115 self.add_mock_battery()149 self.add_mock_battery()
116 plugin = self.main_view.select_single(objectName='entryComponent-battery')150 plugin = self.main_view.select_single(
151 objectName='entryComponent-battery'
152 )
117 self.assertThat(plugin, NotEquals(None))153 self.assertThat(plugin, NotEquals(None))
118154
155
119class SystemSettingsBatteryTestCases(UbuntuSystemSettingsBatteryTestCase):156class SystemSettingsBatteryTestCases(UbuntuSystemSettingsBatteryTestCase):
120 def setUp(self):157 def setUp(self):
121 super(SystemSettingsBatteryTestCases, self).setUp()158 super(SystemSettingsBatteryTestCases, self).setUp()
122159
123 def test_battery_plugin(self):160 def test_battery_plugin(self):
124 """ checks whether the Battery plugin is available """161 """ checks whether the Battery plugin is available """
125 plugin = self.main_view.select_single(objectName='entryComponent-battery')162 plugin = self.main_view.select_single(
163 objectName='entryComponent-battery'
164 )
126 self.assertThat(plugin, NotEquals(None))165 self.assertThat(plugin, NotEquals(None))
127
128166
=== modified file 'tests/autopilot/ubuntu_system_settings/tests/test_search.py'
--- tests/autopilot/ubuntu_system_settings/tests/test_search.py 2014-01-17 10:15:31 +0000
+++ tests/autopilot/ubuntu_system_settings/tests/test_search.py 2014-03-11 14:59:49 +0000
@@ -5,12 +5,8 @@
5# under the terms of the GNU General Public License version 3, as published5# under the terms of the GNU General Public License version 3, as published
6# by the Free Software Foundation.6# by the Free Software Foundation.
77
8from time import sleep
9
10from autopilot.matchers import Eventually
11from autopilot.introspection.dbus import StateNotFoundError8from autopilot.introspection.dbus import StateNotFoundError
12from testtools.matchers import Contains, Equals, NotEquals, GreaterThan9from testtools.matchers import Equals, NotEquals
13from unittest import skip
1410
15from ubuntu_system_settings.tests import UbuntuSystemSettingsTestCase11from ubuntu_system_settings.tests import UbuntuSystemSettingsTestCase
16from ubuntu_system_settings.utils.i18n import ugettext as _12from ubuntu_system_settings.utils.i18n import ugettext as _
@@ -18,6 +14,7 @@
1814
19""" Tests for Ubuntu System Settings """15""" Tests for Ubuntu System Settings """
2016
17
21class SearchTestCases(UbuntuSystemSettingsTestCase):18class SearchTestCases(UbuntuSystemSettingsTestCase):
22 """ Tests for Search """19 """ Tests for Search """
2320
@@ -37,8 +34,9 @@
37 sound = self.main_view.select_single(objectName='entryComponent-sound')34 sound = self.main_view.select_single(objectName='entryComponent-sound')
38 self.assertThat(sound, NotEquals(None))35 self.assertThat(sound, NotEquals(None))
39 try:36 try:
40 background = self.main_view.select_single(objectName='entryComponent-background')37 background = self.main_view.select_single(
38 objectName='entryComponent-background'
39 )
41 except StateNotFoundError:40 except StateNotFoundError:
42 background = None41 background = None
43 self.assertThat(background, Equals(None))42 self.assertThat(background, Equals(None))
44
4543
=== modified file 'tests/autopilot/ubuntu_system_settings/tests/test_system_updates.py'
--- tests/autopilot/ubuntu_system_settings/tests/test_system_updates.py 2014-02-04 21:05:28 +0000
+++ tests/autopilot/ubuntu_system_settings/tests/test_system_updates.py 2014-03-11 14:59:49 +0000
@@ -5,15 +5,10 @@
5# under the terms of the GNU General Public License version 3, as published5# under the terms of the GNU General Public License version 3, as published
6# by the Free Software Foundation.6# by the Free Software Foundation.
77
8from time import sleep
9
10from autopilot.matchers import Eventually
11from autopilot.introspection.dbus import StateNotFoundError8from autopilot.introspection.dbus import StateNotFoundError
12from testtools.matchers import Contains, Equals, NotEquals, GreaterThan, raises9from testtools.matchers import NotEquals, raises
13from unittest import skip
1410
15from ubuntu_system_settings.tests import SystemUpdatesBaseTestCase11from ubuntu_system_settings.tests import SystemUpdatesBaseTestCase
16from ubuntu_system_settings.utils.i18n import ugettext as _
1712
1813
19""" Tests for Ubuntu System Settings """14""" Tests for Ubuntu System Settings """
2015
=== modified file 'tests/autopilot/ubuntu_system_settings/utils/i18n.py'
--- tests/autopilot/ubuntu_system_settings/utils/i18n.py 2013-12-17 17:29:03 +0000
+++ tests/autopilot/ubuntu_system_settings/utils/i18n.py 2014-03-11 14:59:49 +0000
@@ -8,15 +8,17 @@
8import locale8import locale
9import gettext9import gettext
1010
11APP_NAME='ubuntu-system-settings'11APP_NAME = 'ubuntu-system-settings'
12LOCALE_DIR='/usr/share/locale/'12LOCALE_DIR = '/usr/share/locale/'
1313
14lc, encoding = locale.getdefaultlocale()14lc, encoding = locale.getdefaultlocale()
1515
16if not lc:16if not lc:
17 lc = 'C'17 lc = 'C'
1818
19language = gettext.translation(APP_NAME, LOCALE_DIR, languages=[lc], fallback=True)19language = gettext.translation(
20 APP_NAME, LOCALE_DIR, languages=[lc], fallback=True
21)
2022
21# UTF-823# UTF-8
22ugettext = language.ugettext24ugettext = language.ugettext
2325
=== added file 'tests/test_code.py'
--- tests/test_code.py 1970-01-01 00:00:00 +0000
+++ tests/test_code.py 2014-03-11 14:59:49 +0000
@@ -0,0 +1,47 @@
1#!/usr/bin/python
2
3# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
4# Copyright 2014 Canonical
5#
6# This program is free software: you can redistribute it and/or modify it
7# under the terms of the GNU General Public License version 3, as published
8# by the Free Software Foundation.
9
10import subprocess
11import sys
12import unittest
13
14
15class StaticCodeTests(unittest.TestCase):
16
17 def _is_tool_installed(tool):
18 return subprocess.call(['which', tool],
19 stdout=subprocess.PIPE)
20
21 @unittest.skipIf(
22 _is_tool_installed('pyflakes') != 0, 'pyflakes not installed'
23 )
24 def test_pyflakes(self):
25 pyflakes = subprocess.Popen(
26 ['pyflakes', '.'],
27 stdout=subprocess.PIPE, universal_newlines=True
28 )
29 (out, err) = pyflakes.communicate()
30 self.assertEqual(pyflakes.returncode, 0, out)
31
32 @unittest.skipIf(
33 _is_tool_installed('pep8') != 0, 'pep8 not installed'
34 )
35 def test_pep8(self):
36 pep8 = subprocess.Popen(
37 ['pep8', '.'],
38 stdout=subprocess.PIPE, universal_newlines=True
39 )
40 (out, err) = pep8.communicate()
41 self.assertEqual(pep8.returncode, 0, out)
42
43
44if __name__ == '__main__':
45 unittest.main(
46 testRunner=unittest.TextTestRunner(stream=sys.stdout, verbosity=2)
47 )

Subscribers

People subscribed via source and target branches