Merge lp:~veebers/ubuntu-keyboard/restarting-maliit-for-tests into lp:ubuntu-keyboard

Proposed by Christopher Lee
Status: Merged
Approved by: Thomas Moenicke
Approved revision: 70
Merged at revision: 96
Proposed branch: lp:~veebers/ubuntu-keyboard/restarting-maliit-for-tests
Merge into: lp:ubuntu-keyboard
Prerequisite: lp:~veebers/ubuntu-keyboard/autopilot-emulator-update
Diff against target: 84 lines (+65/-0)
1 file modified
tests/autopilot/ubuntu_keyboard/tests/test_keyboard.py (+65/-0)
To merge this branch: bzr merge lp:~veebers/ubuntu-keyboard/restarting-maliit-for-tests
Reviewer Review Type Date Requested Status
Thomas Moenicke (community) Approve
PS Jenkins bot continuous-integration Approve
Thomi Richards (community) Needs Fixing
Review via email: mp+190005@code.launchpad.net

Commit message

For ease of testing the ubuntu-keyboard testsuite takes care of restarting maliit-server with testability for the duration of the tests.

Description of the change

For ease of testing the ubuntu-keyboard testsuite takes care of restarting maliit-server with testability for the duration of the tests.

To post a comment you must log in.
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

Hi,

You should be aware that doing this:

66 + open(UbuntuKeyboardTests.maliit_override_file, 'w').write(
67 + "exec maliit-server -testability"
68 + )

Will probably work in CPython, but does not do what you think it does in any other python implementation (CPython is the *only* python implementation that uses reference counting to control object lifetimes). A better way is like:

with open(UbuntuKeyboardTests.maliit_override_file, 'w') as override_file:
    override_file.write("exec maliit-server -testability")

Otherwise, looks good, although a better solution would be to use a test fixture.

review: Needs Fixing
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
67. By Christopher Lee

Merge trunk.

68. By Christopher Lee

Cleanup, no longer need to write to file.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
69. By Christopher Lee

Merge trunk

70. By Christopher Lee

Remove un-needed config string

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Thomas Moenicke (thomas-moenicke) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/autopilot/ubuntu_keyboard/tests/test_keyboard.py'
2--- tests/autopilot/ubuntu_keyboard/tests/test_keyboard.py 2013-10-14 04:55:00 +0000
3+++ tests/autopilot/ubuntu_keyboard/tests/test_keyboard.py 2013-11-04 09:00:10 +0000
4@@ -18,6 +18,7 @@
5 #
6
7 import os
8+import subprocess
9
10 from testtools.matchers import Equals
11 import tempfile
12@@ -31,8 +32,72 @@
13 from ubuntu_keyboard.emulators.keyboard import Keyboard
14 from ubuntu_keyboard.emulators.keypad import KeyPadState
15
16+import logging
17+
18+
19+logger = logging.getLogger(__name__)
20+
21+
22+def _get_maliit_server_status():
23+ try:
24+ return subprocess.check_output([
25+ 'initctl',
26+ 'status',
27+ 'maliit-server'
28+ ])
29+ except subprocess.CalledProcessError as e:
30+ e.args += ("maliit-server appears to be an unknown service.", )
31+ raise
32+
33+
34+def _stop_maliit_server():
35+ status = _get_maliit_server_status()
36+ if "start/" in status:
37+ try:
38+ logger.debug("Stopping maliit server")
39+ subprocess.check_call(['initctl', 'stop', 'maliit-server'])
40+ except subprocess.CalledProcessError as e:
41+ e.args += ("Unable to stop mallit server",)
42+ raise
43+ else:
44+ logger.debug("No need to stop server.")
45+
46+
47+def _start_maliit_server(args):
48+ status = _get_maliit_server_status()
49+ if "stop/" in status:
50+ try:
51+ logger.debug(
52+ "Starting maliit-server with the args: '%s'" % ",".join(args)
53+ )
54+ subprocess.check_call(
55+ ['initctl', 'start', 'maliit-server'] + args
56+ )
57+ except subprocess.CalledProcessError as e:
58+ e.args += ("Unable to start mallit server",)
59+ raise
60+ else:
61+ raise RuntimeError(
62+ "Unable to start maliit-server: server is currently running."
63+ )
64+
65+
66+def _restart_maliit_server(args=None):
67+ if args is None:
68+ args = []
69+ _stop_maliit_server()
70+ _start_maliit_server(args)
71+
72
73 class UbuntuKeyboardTests(AutopilotTestCase):
74+ @classmethod
75+ def setUpClass(cls):
76+ _restart_maliit_server(['QT_LOAD_TESTABILITY=1'])
77+
78+ @classmethod
79+ def tearDownClass(cls):
80+ _restart_maliit_server()
81+
82 def setUp(self):
83 super(UbuntuKeyboardTests, self).setUp()
84 self.pointer = Pointer(Touch.create())

Subscribers

People subscribed via source and target branches