on xenial help sign in
Fixed style and static python errors.
commitbe07744a177c745a42cef762bd8b90efc579464c authorLeo Arias <leo.arias@canonical.com> dateTue 17 Jun 2014, 19:52 (12 years ago) parentcbf1d54
8 files changed+116−60
tests/autopilot/unity8/process_helpers.py+3−2 tests/autopilot/unity8/shell/tests/disabled_test_hud.py+44−13 tests/autopilot/unity8/shell/tests/test_emulators.py−2 tests/autopilot/unity8/shell/tests/test_lock_screen.py+4−5 tests/autopilot/unity8/shell/tests/test_notifications.py+15−10 tests/autopilot/unity8/shell/tests/test_system_integration.py+10−5 tests/autopilot/unity8/shell/tests/test_upstart.py+20−11 tests/whitespace/check_whitespace.py+20−12
tests/autopilot/unity8/process_helpers.py+3−2
@@ -75,7 +75,7 @@ def unlock_unity(unity_proxy_obj=None):
7575 main_window_emulator.QQuickView)
7676
7777 greeter = main_window.get_greeter()
78− if greeter.created == False:
78+ if greeter.created is False:
7979 raise RuntimeWarning("Greeter appears to be already unlocked.")
8080
8181 # Because of potential input jerkiness under heavy load,
@@ -98,7 +98,8 @@ def unlock_unity(unity_proxy_obj=None):
9898
9999def lock_unity(unity_proxy_obj=None):
100100 """Helper function that attempts to lock the unity greeter."""
101− import evdev, time
101+ import evdev
102+ import time
102103 uinput = evdev.UInput(name='unity8-autopilot-power-button',
103104 devnode='/dev/autopilot-uinput')
104105 # One press and release to turn screen off (locking unity)
tests/autopilot/unity8/shell/tests/disabled_test_hud.py+44−13
@@ -20,12 +20,13 @@
2020from __future__ import absolute_import
2121
2222from unity8.process_helpers import unlock_unity
23−from unity8.shell import with_lightdm_mock, DragMixin
23+from unity8.shell import DragMixin
2424from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
2525
2626from testtools.matchers import Equals
2727from autopilot.matchers import Eventually
2828
29+
2930class TestHud(UnityTestCase, DragMixin):
3031
3132 """Tests the Shell HUD."""
@@ -33,10 +34,14 @@ class TestHud(UnityTestCase, DragMixin):
3334 scenarios = _get_device_emulation_scenarios()
3435
3536 def test_show_hud_button_appears(self):
36− """Swiping up while an app is active must show the 'show hud' button, following some behaviours.
37+ """Swiping up while an app is active must show the 'show hud' button.
38+
39+ It should follow some behaviours.
3740 The button must disappear not opening the HUD when releasing the
38− mouse again somewhere on the screen except on the button itself following a timeout.
39− The button must disappear when touching somewhere on the screen except the button itself.
41+ mouse again somewhere on the screen except on the button itself
42+ following a timeout.
43+ The button must disappear when touching somewhere on the screen
44+ except the button itself.
4045
4146 """
4247 unity_proxy = self.launch_unity()
@@ -55,29 +60,47 @@ class TestHud(UnityTestCase, DragMixin):
5560
5661 self.touch.press(swipe_coords.start_x, swipe_coords.start_y)
5762 self.addCleanup(self._maybe_release_finger)
58− self._drag(swipe_coords.start_x, swipe_coords.start_y, swipe_coords.start_x, swipe_coords.start_y - int(edge_drag_area.distanceThreshold) - 5)
63+ self._drag(
64+ swipe_coords.start_x,
65+ swipe_coords.start_y,
66+ swipe_coords.start_x,
67+ swipe_coords.start_y - int(edge_drag_area.distanceThreshold) - 5)
5968 self.assertThat(hud_show_button.opacity, Eventually(Equals(0.5)))
60− self.assertThat(hud_show_button.bottomMargin, Eventually(Equals(initialBottomMargin)))
61− self._drag(swipe_coords.start_x, swipe_coords.start_y - int(edge_drag_area.distanceThreshold) - 5, swipe_coords.end_x, swipe_coords.start_y - int(edge_drag_area.distanceThreshold) - int(edge_drag_area.commitDistance) - 5)
69+ self.assertThat(
70+ hud_show_button.bottomMargin,
71+ Eventually(Equals(initialBottomMargin)))
72+ self._drag(
73+ swipe_coords.start_x,
74+ swipe_coords.start_y - int(edge_drag_area.distanceThreshold) - 5,
75+ swipe_coords.end_x,
76+ swipe_coords.start_y - int(edge_drag_area.distanceThreshold) -
77+ int(edge_drag_area.commitDistance) - 5)
6278 self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
6379 self.assertThat(hud_show_button.bottomMargin, Eventually(Equals(0.0)))
64− self.touch.release();
80+ self.touch.release()
6581 self.assertThat(hud.shown, Equals(False))
6682 self.assertThat(hud_show_button.opacity, Eventually(Equals(0.0)))
6783
6884 self.touch.press(swipe_coords.start_x, swipe_coords.start_y)
69− self._drag(swipe_coords.start_x, swipe_coords.start_y, swipe_coords.start_x, swipe_coords.end_y - int(hud_show_button.height))
85+ self._drag(
86+ swipe_coords.start_x,
87+ swipe_coords.start_y,
88+ swipe_coords.start_x,
89+ swipe_coords.end_y - int(hud_show_button.height))
7090 self.assertThat(hud.shown, Equals(False))
7191 self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
7292 self.touch.release()
7393 self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
74− self.touch.tap(swipe_coords.end_x, swipe_coords.end_y - int(hud_show_button.height))
94+ self.touch.tap(
95+ swipe_coords.end_x,
96+ swipe_coords.end_y - int(hud_show_button.height))
7597 self.assertThat(hud.shown, Equals(False))
7698 self.assertThat(hud_show_button.opacity, Eventually(Equals(0.0)))
7799
78100 def test_show_hud_appears(self):
79101 """Releasing the touch on the 'show hud' button must display the hud.
80− Test that the hud button stays on screen and tapping it opens the hud.
102+ Test that the hud button stays on screen and tapping it opens the
103+ hud.
81104
82105 """
83106 unity_proxy = self.launch_unity()
@@ -94,7 +117,11 @@ class TestHud(UnityTestCase, DragMixin):
94117
95118 self.touch.press(swipe_coords.start_x, swipe_coords.start_y)
96119 self.addCleanup(self._maybe_release_finger)
97− self._drag(swipe_coords.start_x, swipe_coords.start_y, swipe_coords.start_x, swipe_coords.end_y)
120+ self._drag(
121+ swipe_coords.start_x,
122+ swipe_coords.start_y,
123+ swipe_coords.start_x,
124+ swipe_coords.end_y)
98125 self.assertThat(hud.shown, Eventually(Equals(False)))
99126 self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
100127 self.touch.release()
@@ -105,7 +132,11 @@ class TestHud(UnityTestCase, DragMixin):
105132 self.assertThat(hud.shown, Eventually(Equals(False)))
106133
107134 self.touch.press(swipe_coords.start_x, swipe_coords.start_y)
108− self._drag(swipe_coords.start_x, swipe_coords.start_y, swipe_coords.start_x, swipe_coords.end_y - int(hud_show_button.height))
135+ self._drag(
136+ swipe_coords.start_x,
137+ swipe_coords.start_y,
138+ swipe_coords.start_x,
139+ swipe_coords.end_y - int(hud_show_button.height))
109140 self.assertThat(hud.shown, Equals(False))
110141 self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
111142 self.touch.release()
tests/autopilot/unity8/shell/tests/test_emulators.py−2
@@ -32,8 +32,6 @@ try:
3232except ImportError:
3333 import mock
3434
35−from testtools.matchers import Contains, HasLength
36−
3735from unity8 import process_helpers
3836from unity8.shell import emulators, fixture_setup, tests
3937from unity8.shell.emulators import dash as dash_emulators
tests/autopilot/unity8/shell/tests/test_lock_screen.py+4−5
@@ -1,7 +1,7 @@
11# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
22#
33# Unity Autopilot Test Suite
4−# Copyright (C) 2012-2013 Canonical
4+# Copyright (C) 2012, 2013, 2014 Canonical
55#
66# This program is free software: you can redistribute it and/or modify
77# it under the terms of the GNU General Public License as published by
@@ -25,9 +25,7 @@ from unity8.shell import with_lightdm_mock
2525from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
2626
2727from autopilot.matchers import Eventually
28−from autopilot.platform import model
2928import sys
30−from testtools import skipUnless
3129from testtools.matchers import Equals
3230import logging
3331
@@ -133,7 +131,7 @@ class TestLockscreen(UnityTestCase):
133131 if not isinstance(code, basestring):
134132 raise TypeError(
135133 "'code' parameter must be a string, not %r."
136− % type(passphrase)
134+ % type(code)
137135 )
138136 for num in code:
139137 if not num.isdigit():
@@ -190,7 +188,8 @@ class TestLockscreen(UnityTestCase):
190188 current_text = prompt.text
191189 self.keyboard.type(character)
192190 try:
193− self.assertThat(prompt.text, Eventually(Equals(current_text + character)))
191+ self.assertThat(
192+ prompt.text, Eventually(Equals(current_text + character)))
194193 except AssertionError:
195194 if retries > 0:
196195 self._type_character(character, prompt, retries-1)
tests/autopilot/unity8/shell/tests/test_notifications.py+15−10
@@ -211,8 +211,8 @@ class InteractiveNotificationBase(NotificationsBase):
211211 self.touch.tap_object(notification.select_single(objectName="button4"))
212212 self.assert_notification_action_id_was_called("action_decline_4")
213213
214− def test_modal_sd_without_greeter (self):
215− """A snap-decision on a phone should block input to shell beneath it when there's no greeter."""
214+ def test_modal_sd_without_greeter(self):
215+ """Snap-decision should block input to shell without greeter."""
216216 unity_proxy = self.launch_unity()
217217 unlock_unity(unity_proxy)
218218
@@ -238,7 +238,8 @@ class InteractiveNotificationBase(NotificationsBase):
238238 hints
239239 )
240240
241− # verify that we cannot reveal the launcher (no longer interact with the shell)
241+ # verify that we cannot reveal the launcher (no longer interact with
242+ # the shell)
242243 time.sleep(1)
243244 self.main_window.show_dash_swiping()
244245 launcher = self.main_window.get_launcher()
@@ -249,13 +250,14 @@ class InteractiveNotificationBase(NotificationsBase):
249250 get_notification = lambda: notify_list.wait_select_single(
250251 'Notification', objectName='notification1')
251252 notification = get_notification()
252− self._assert_notification(notification, summary, body, True, False, 1.0)
253+ self._assert_notification(
254+ notification, summary, body, True, False, 1.0)
253255 self.touch.tap_object(notification.select_single(objectName="button0"))
254256 self.assert_notification_action_id_was_called("action_accept")
255257
256− def test_modal_sd_with_greeter (self):
257− """A snap-decision on a phone should not block input to the greeter beneath it."""
258− unity_proxy = self.launch_unity()
258+ def test_modal_sd_with_greeter(self):
259+ """A snap-decision should not block input to the greeter beneath it."""
260+ self.launch_unity()
259261
260262 summary = "Incoming file"
261263 body = "Frank would like to send you the file: essay.pdf"
@@ -290,7 +292,8 @@ class InteractiveNotificationBase(NotificationsBase):
290292 get_notification = lambda: notify_list.wait_select_single(
291293 'Notification', objectName='notification1')
292294 notification = get_notification()
293− self._assert_notification(notification, summary, body, True, False, 1.0)
295+ self._assert_notification(
296+ notification, summary, body, True, False, 1.0)
294297 self.touch.tap_object(notification.select_single(objectName="button0"))
295298 self.assert_notification_action_id_was_called("action_accept")
296299
@@ -663,7 +666,8 @@ class EphemeralNotificationsTests(NotificationsBase):
663666 icon_path = self._get_icon_path('avatars/amanda.png')
664667 notification.update(summary, body, icon_path)
665668 notification.show()
666− self._assert_notification(get_notification(), summary, body, True, False, 1.0)
669+ self._assert_notification(
670+ get_notification(), summary, body, True, False, 1.0)
667671
668672 def test_update_notification_layout_change(self):
669673 """Notification must allow updating its contents and layout while
@@ -710,7 +714,8 @@ class EphemeralNotificationsTests(NotificationsBase):
710714 notification.show()
711715
712716 self.assertThat(get_notification, Eventually(NotEquals(None)))
713− self._assert_notification(get_notification(), summary, body, False, False, 1.0)
717+ self._assert_notification(
718+ get_notification(), summary, body, False, False, 1.0)
714719
715720 def test_append_hint(self):
716721 """Notification has to accumulate body-text using append-hint."""
tests/autopilot/unity8/shell/tests/test_system_integration.py+10−5
@@ -23,19 +23,24 @@ import subprocess
2323import unittest
2424
2525from autopilot import platform
26−from unity8.shell.emulators import UnityEmulatorBase
2726from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
2827
29−from testtools.matchers._basic import Equals
3028
3129class SystemIntegrationTests(UnityTestCase):
3230
3331 scenarios = _get_device_emulation_scenarios()
3432
35− @unittest.skipIf(platform.model() == "Desktop", "Test is broken on otto, see bug 1281634.")
33+ @unittest.skipIf(
34+ platform.model() == "Desktop",
35+ "Test is broken on otto, see bug 1281634.")
3636 def test_networkmanager_integration(self):
3737 self.launch_unity()
3838
3939 # invoke policykit to check permissions
40− pid = subprocess.check_output(["pidof", "-s", "unity8"], universal_newlines=True)
41− subprocess.check_call("pkcheck --action-id org.freedesktop.NetworkManager.enable-disable-network --process " + pid, shell=True)
40+ pid = subprocess.check_output(
41+ ["pidof", "-s", "unity8"], universal_newlines=True)
42+ subprocess.check_call(
43+ "pkcheck --action-id "
44+ "org.freedesktop.NetworkManager.enable-disable-network "
45+ "--process " + pid,
46+ shell=True)
tests/autopilot/unity8/shell/tests/test_upstart.py+20−11
@@ -1,7 +1,7 @@
11# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
22#
33# Unity Autopilot Test Suite
4−# Copyright (C) 2013 Canonical
4+# Copyright (C) 2013, 2014 Canonical
55#
66# This program is free software: you can redistribute it and/or modify
77# it under the terms of the GNU General Public License as published by
@@ -42,19 +42,24 @@ import sys
4242if sys.version_info < (3,):
4343 range = xrange
4444
45+
4546class UpstartIntegrationTests(UnityTestCase):
4647
4748 scenarios = _get_device_emulation_scenarios()
4849
4950 def _get_status(self):
50− pid, status = os.waitpid(self.process.pid, os.WUNTRACED | os.WCONTINUED | os.WNOHANG)
51− logger.debug("Got status: {0}; stopped: {1}; continued: {2}"\
52− .format(status, os.WIFSTOPPED(status), os.WIFCONTINUED(status)))
51+ pid, status = os.waitpid(
52+ self.process.pid, os.WUNTRACED | os.WCONTINUED | os.WNOHANG)
53+ logger.debug(
54+ "Got status: {0}; stopped: {1}; continued: {2}".format(
55+ status, os.WIFSTOPPED(status), os.WIFCONTINUED(status)))
5356 return status
5457
5558 def _launch_unity(self):
5659 self.patch_environment("QT_LOAD_TESTABILITY", "1")
57− self.process = subprocess.Popen([get_binary_path()] + self.unity_geometry_args)
60+ self.process = subprocess.Popen(
61+ [get_binary_path()] + self.unity_geometry_args)
62+
5863 def ensure_stopped():
5964 self.process.terminate()
6065 for i in range(10):
@@ -76,10 +81,10 @@ class UpstartIntegrationTests(UnityTestCase):
7681 self.addCleanup(ensure_stopped)
7782
7883 def _set_proxy(self):
79− super(UpstartIntegrationTests, self)._set_proxy(get_proxy_object_for_existing_process(
80− pid=self.process.pid,
81− emulator_base=UnityEmulatorBase,
82− ))
84+ super(UpstartIntegrationTests, self)._set_proxy(
85+ get_proxy_object_for_existing_process(
86+ pid=self.process.pid,
87+ emulator_base=UnityEmulatorBase,))
8388
8489 def test_no_sigstop(self):
8590 self.patch_environment("UNITY_MIR_EMITS_SIGSTOP", "")
@@ -93,10 +98,14 @@ class UpstartIntegrationTests(UnityTestCase):
9398 def test_expect_sigstop(self):
9499 self.patch_environment("UNITY_MIR_EMITS_SIGSTOP", "1")
95100 self._launch_unity()
96− self.assertThat(lambda: os.WIFSTOPPED(self._get_status()), Eventually(Equals(True)), "Unity8 should raise SIGSTOP when ready")
101+ self.assertThat(
102+ lambda: os.WIFSTOPPED(self._get_status()),
103+ Eventually(Equals(True)), "Unity8 should raise SIGSTOP when ready")
97104
98105 self.process.send_signal(signal.SIGCONT)
99− self.assertThat(lambda: os.WIFCONTINUED(self._get_status()), Eventually(Equals(True)), "Unity8 should have resumed")
106+ self.assertThat(
107+ lambda: os.WIFCONTINUED(self._get_status()),
108+ Eventually(Equals(True)), "Unity8 should have resumed")
100109
101110 logger.debug("Unity started, waiting for it to be ready.")
102111 self._set_proxy()
tests/whitespace/check_whitespace.py+20−12
@@ -1,7 +1,7 @@
11#! /usr/bin/env python3
22
33#
4−# Copyright (C) 2013 Canonical Ltd
4+# Copyright (C) 2013, 2014 Canonical Ltd
55#
66# This program is free software: you can redistribute it and/or modify
77# it under the terms of the GNU General Public License version 3 as
@@ -19,8 +19,8 @@
1919#
2020
2121#
22−# Little helper program to test that source files do not contain trailing whitespace
23−# or tab indentation.
22+# Little helper program to test that source files do not contain trailing
23+# whitespace or tab indentation.
2424#
2525# Usage: check_whitespace.py directory [ignore_prefix]
2626#
@@ -36,13 +36,13 @@ import os
3636import re
3737import sys
3838
39−# Print msg on stderr, preceded by program name and followed by newline
4039
40+# Print msg on stderr, preceded by program name and followed by newline
4141def error(msg):
4242 print(os.path.basename(sys.argv[0]) + ": " + msg, file=sys.stderr)
4343
44−# Function to raise errors encountered by os.walk
4544
45+# Function to raise errors encountered by os.walk
4646def raise_error(e):
4747 raise e
4848
@@ -52,6 +52,7 @@ def raise_error(e):
5252whitespace_pat = re.compile(r'.*[ \t]$')
5353tab_indent_pat = re.compile(r'^ *\t')
5454
55+
5556def scan_for_bad_whitespace(file_path):
5657 global tab_indent_pat, whitespace_pat
5758 errors = []
@@ -69,7 +70,9 @@ def scan_for_bad_whitespace(file_path):
6970 plural = 's'
7071 else:
7172 plural = ''
72− print("%s: bad whitespace in line%s %s" % (file_path, plural, ", ".join((str(i) for i in errors))))
73+ print(
74+ "%s: bad whitespace in line%s %s" % (
75+ file_path, plural, ", ".join((str(i) for i in errors))))
7376 elif errors:
7477 print("%s: bad whitespace in multiple lines" % file_path)
7578 if newlines_at_end:
@@ -78,15 +81,20 @@ def scan_for_bad_whitespace(file_path):
7881
7982# Parse args
8083
81−parser = argparse.ArgumentParser(description = 'Test that source files do not contain trailing whitespace.')
82−parser.add_argument('dir', nargs = 1, help = 'The directory to (recursively) search for source files')
83−parser.add_argument('ignore_prefix', nargs = '?', default=None,
84− help = 'Ignore source files with a path that starts with the given prefix.')
84+parser = argparse.ArgumentParser(
85+ description='Test that source files do not contain trailing whitespace.')
86+parser.add_argument(
87+ 'dir', nargs=1,
88+ help='The directory to (recursively) search for source files')
89+parser.add_argument(
90+ 'ignore_prefix', nargs='?', default=None,
91+ help='Ignore source files with a path that starts with the given prefix.')
8592args = parser.parse_args()
8693
8794# Files we want to check for trailing whitespace.
8895
89−file_pat = r'(.*\.(c|cpp|h|hpp|hh|in|install|js|py|qml|sh)$)|(.*CMakeLists\.txt$)'
96+file_pat = (
97+ r'(.*\.(c|cpp|h|hpp|hh|in|install|js|py|qml|sh)$)|(.*CMakeLists\.txt$)')
9098pat = re.compile(file_pat)
9199
92100# Find all the files with matching file extension in the specified
@@ -97,7 +105,7 @@ ignore = args.ignore_prefix and os.path.abspath(args.ignore_prefix) or None
97105
98106found_whitespace = False
99107try:
100− for root, dirs, files in os.walk(directory, onerror = raise_error):
108+ for root, dirs, files in os.walk(directory, onerror=raise_error):
101109 for file in files:
102110 path = os.path.join(root, file)
103111 if not (ignore and path.startswith(ignore)) and pat.match(file):