Debian Codegraph @

tests/autopilot/lomiriuitoolkit/base.py

raw
1 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2 #
3 # Copyright (C) 2013, 2014, 2015 Canonical Ltd.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU Lesser General Public License as published by
7 # the Free Software Foundation; version 3.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 """Base classes for Autopilot tests using the Lomiri UI Toolkit."""
18
19 import logging
20
21 import os
22 import subprocess
23 import lomiriuitoolkit
24 from autopilot.introspection import dbus
25 from autopilot.matchers import Eventually
26 from testtools.matchers import Equals
27
28 from autopilot import (
29 input,
30 platform,
31 testcase
32 )
33
34
35 logger = logging.getLogger(__name__)
36
37
38 def get_host_multiarch():
39 if 'deb_host_multiarch' not in os.environ:
40 # Discard errors: the one known message is "GCC not installed"
41 os.environ['deb_host_multiarch'] = subprocess.check_output(
42 ["dpkg-architecture", "-qDEB_HOST_MULTIARCH"],
43 universal_newlines=True, stderr=subprocess.PIPE).strip()
44 return os.environ['deb_host_multiarch']
45
46
47 def get_qmlscene_launch_command():
48 """Return the command to launch qmlscene for autopilot tests.
49
50 This function is deprecated. Use get_toolkit_launcher_command() instead.
51 """
52 logger.warn('This function is deprecated. '
53 'Use get_toolkit_launcher_command() instead.')
54 # We need to specify qt5 because qtchooser doesn't have a default
55 # configuration on devices and it seems the environment variable
56 # QT_SELECT=qt5 doesn't work for autopilot tests. --Mirv - 2013-10-03
57 arch = get_host_multiarch()
58 return '/usr/lib/{}/qt5/bin/qmlscene'.format(arch)
59
60
61 def get_toolkit_launcher_command():
62 root = lomiriuitoolkit.tests.get_path_to_build_root()
63 path_to_local_launcher = os.path.join(
64 root, 'lomiri-ui-toolkit-launcher', 'lomiri-ui-toolkit-launcher')
65 if os.path.exists(path_to_local_launcher):
66 return path_to_local_launcher
67 else:
68 path_to_installed_launcher = os.path.join(
69 '/', 'usr', 'bin', 'lomiri-ui-toolkit-launcher')
70 return path_to_installed_launcher
71
72
73 class LomiriUIToolkitAppTestCase(testcase.AutopilotTestCase):
74 """Autopilot test case for applications using the Lomiri UI Toolkit."""
75
76 def setUp(self):
77 super().setUp()
78 self.input_device_class = self._get_input_device_class()
79
80 def _get_input_device_class(self):
81 if platform.model() == 'Desktop':
82 return input.Mouse
83 else:
84 return input.Touch
85
86 def _assert_not_visible(self, type_name='*', **kwargs):
87 """Confirm that an object is hidden.
88
89 Internally this means asserting that selecting the object fails.
90 """
91 try:
92 object = self.main_view.select_single(type_name, **kwargs)
93 # object.visible is always True if the select succeeds
94 self.assertThat(object.visible, Eventually(Equals(False)))
95 except dbus.StateNotFoundError:
96 # Caret can't be selected because it's hidden
97 pass