~sil/ubuntu-keyboard/numbers-on-top-row

« back to all changes in this revision

Viewing changes to tests/autopilot/ubuntu_keyboard/tests/test_keyboard.py

  • Committer: Tarmac
  • Author(s): Christopher Lee
  • Date: 2013-11-07 16:07:36 UTC
  • mfrom: (101.2.8 fix_restart_maliit)
  • Revision ID: tarmac-20131107160736-1q8dneqehndxt61b
Updating the tests and emulators so so they run without interference.

Approved by PS Jenkins bot, Łukasz Zemczak.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import os
21
21
import subprocess
22
22
 
 
23
from testtools import skip
23
24
from testtools.matchers import Equals
24
25
import tempfile
25
26
from textwrap import dedent
27
28
 
28
29
from autopilot.testcase import AutopilotTestCase
29
30
from autopilot.input import Pointer, Touch
 
31
from autopilot.introspection import get_proxy_object_for_existing_process
30
32
from autopilot.matchers import Eventually
31
33
from autopilot.platform import model
 
34
from unity8 import process_helpers
 
35
from unity8.shell.emulators.dash import Dash
 
36
from unity8.shell.emulators import UnityEmulatorBase
32
37
from ubuntuuitoolkit import base
33
38
 
34
39
from ubuntu_keyboard.emulators.keyboard import Keyboard
40
45
logger = logging.getLogger(__name__)
41
46
 
42
47
 
43
 
def _get_maliit_server_status():
44
 
    try:
45
 
        return subprocess.check_output([
46
 
            'initctl',
47
 
            'status',
48
 
            'maliit-server'
49
 
        ])
50
 
    except subprocess.CalledProcessError as e:
51
 
        e.args += ("maliit-server appears to be an unknown service.", )
52
 
        raise
53
 
 
54
 
 
55
 
def _stop_maliit_server():
56
 
    status = _get_maliit_server_status()
 
48
def _stop_unity8():
 
49
    status = process_helpers._get_unity_status()
57
50
    if "start/" in status:
58
51
        try:
59
 
            logger.debug("Stopping maliit server")
60
 
            subprocess.check_call(['initctl', 'stop', 'maliit-server'])
 
52
            logger.debug("Stopping unity8")
 
53
            subprocess.check_call(['initctl', 'stop', 'unity8'])
61
54
        except subprocess.CalledProcessError as e:
62
 
            e.args += ("Unable to stop mallit server",)
 
55
            e.args += ("Unable to stop unity8",)
63
56
            raise
64
57
    else:
65
 
        logger.debug("No need to stop server.")
66
 
 
67
 
 
68
 
def _start_maliit_server(args):
69
 
    status = _get_maliit_server_status()
 
58
        logger.debug("No need to stop unity.")
 
59
 
 
60
 
 
61
def _start_unity8():
 
62
    status = process_helpers._get_unity_status()
70
63
    if "stop/" in status:
71
64
        try:
72
 
            logger.debug(
73
 
                "Starting maliit-server with the args: '%s'" % ",".join(args)
74
 
            )
75
 
            subprocess.check_call(
76
 
                ['initctl', 'start', 'maliit-server'] + args
77
 
            )
 
65
            logger.debug("Starting unity8")
 
66
            subprocess.check_call(['initctl', 'start', 'unity8'])
78
67
        except subprocess.CalledProcessError as e:
79
 
            e.args += ("Unable to start mallit server",)
 
68
            e.args += ("Unable to start unity8",)
80
69
            raise
81
70
    else:
82
71
        raise RuntimeError(
83
 
            "Unable to start maliit-server: server is currently running."
84
 
        )
85
 
 
86
 
 
87
 
def _restart_maliit_server(args=None):
88
 
    if args is None:
89
 
        args = []
90
 
    _stop_maliit_server()
91
 
    _start_maliit_server(args)
 
72
            "Unable to start unity8: server is currently running."
 
73
        )
 
74
 
 
75
 
 
76
def _assertUnityReady():
 
77
        unity_pid = process_helpers._get_unity_pid()
 
78
        unity = get_proxy_object_for_existing_process(
 
79
            pid=unity_pid,
 
80
            emulator_base=UnityEmulatorBase,
 
81
        )
 
82
        dash = unity.wait_select_single(Dash)
 
83
        home_scope = dash.get_scope('home')
 
84
 
 
85
        home_scope.isLoaded.wait_for(True)
 
86
        home_scope.isCurrent.wait_for(True)
 
87
 
 
88
 
 
89
def _restart_unity8():
 
90
    _stop_unity8()
 
91
    _start_unity8()
92
92
 
93
93
 
94
94
class UbuntuKeyboardTests(AutopilotTestCase):
 
95
    maliit_override_file = os.path.expanduser(
 
96
        "~/.config/upstart/maliit-server.override"
 
97
    )
 
98
 
95
99
    @classmethod
96
100
    def setUpClass(cls):
97
 
        _restart_maliit_server(['QT_LOAD_TESTABILITY=1'])
 
101
        try:
 
102
            logger.debug("Creating the override file.")
 
103
            with open(
 
104
                UbuntuKeyboardTests.maliit_override_file, 'w'
 
105
            ) as override_file:
 
106
                override_file.write("exec maliit-server -testability")
 
107
 
 
108
            process_helpers.restart_unity_with_testability()
 
109
            _assertUnityReady()
 
110
            #### FIXME: This is a work around re: lp:1238417 ####
 
111
            if model() != "Desktop":
 
112
                from autopilot.input import _uinput
 
113
                _uinput._touch_device = _uinput.create_touch_device()
 
114
            ####
 
115
 
 
116
            #### FIXME: Workaround re: lp:1248902 and lp:1248913
 
117
            logger.debug("Waiting for maliit-server to be ready")
 
118
            sleep(10)
 
119
            ####
 
120
 
 
121
        except IOError as e:
 
122
            e.args += (
 
123
                "Failed attempting to write override file to {file}".format(
 
124
                    file=UbuntuKeyboardTests.maliit_override_file
 
125
                ),
 
126
            )
 
127
            raise
98
128
 
99
129
    @classmethod
100
130
    def tearDownClass(cls):
101
 
        _restart_maliit_server()
 
131
        try:
 
132
            os.remove(UbuntuKeyboardTests.maliit_override_file)
 
133
        except OSError:
 
134
            logger.warning("Attempted to remove non-existent override file")
 
135
        _restart_unity8()
102
136
 
103
137
    def setUp(self):
104
138
        if model() == "Desktop":
246
280
            # \u201d
247
281
            'punctuation',
248
282
            dict(
249
 
                label="Puncuation",
 
283
                label="Punctuation",
250
284
                input=u'`~!@#$%^&*()_-+={}[]|\\:;\'<>,.?/\u201c'
251
285
            )
252
286
        )
431
465
    ]
432
466
 
433
467
    # Note: based on UX design doc
 
468
    @skip("Unable to determine LayoutId re: bug lp:1248796")
434
469
    def test_keyboard_layout(self):
435
470
        """The Keyboard must respond to the input type and change to be the
436
471
        correct state.