File: base.py

package info (click to toggle)
lomiri-ui-toolkit 1.3.5110%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 26,436 kB
  • sloc: cpp: 85,830; python: 5,537; sh: 1,344; javascript: 919; ansic: 573; makefile: 204
file content (97 lines) | stat: -rw-r--r-- 3,461 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
#
# Copyright (C) 2013, 2014, 2015 Canonical Ltd.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""Base classes for Autopilot tests using the Lomiri UI Toolkit."""

import logging

import os
import subprocess
import lomiriuitoolkit
from autopilot.introspection import dbus
from autopilot.matchers import Eventually
from testtools.matchers import Equals

from autopilot import (
    input,
    platform,
    testcase
)


logger = logging.getLogger(__name__)


def get_host_multiarch():
    if 'deb_host_multiarch' not in os.environ:
        # Discard errors: the one known message is "GCC not installed"
        os.environ['deb_host_multiarch'] = subprocess.check_output(
            ["dpkg-architecture", "-qDEB_HOST_MULTIARCH"],
            universal_newlines=True, stderr=subprocess.PIPE).strip()
    return os.environ['deb_host_multiarch']


def get_qmlscene_launch_command():
    """Return the command to launch qmlscene for autopilot tests.

    This function is deprecated. Use get_toolkit_launcher_command() instead.
    """
    logger.warn('This function is deprecated. '
                'Use get_toolkit_launcher_command() instead.')
    # We need to specify qt5 because qtchooser doesn't have a default
    # configuration on devices and it seems the environment variable
    # QT_SELECT=qt5 doesn't work for autopilot tests. --Mirv - 2013-10-03
    arch = get_host_multiarch()
    return '/usr/lib/{}/qt5/bin/qmlscene'.format(arch)


def get_toolkit_launcher_command():
    root = lomiriuitoolkit.tests.get_path_to_build_root()
    path_to_local_launcher = os.path.join(
        root, 'lomiri-ui-toolkit-launcher', 'lomiri-ui-toolkit-launcher')
    if os.path.exists(path_to_local_launcher):
        return path_to_local_launcher
    else:
        path_to_installed_launcher = os.path.join(
            '/', 'usr', 'bin', 'lomiri-ui-toolkit-launcher')
    return path_to_installed_launcher


class LomiriUIToolkitAppTestCase(testcase.AutopilotTestCase):
    """Autopilot test case for applications using the Lomiri UI Toolkit."""

    def setUp(self):
        super().setUp()
        self.input_device_class = self._get_input_device_class()

    def _get_input_device_class(self):
        if platform.model() == 'Desktop':
            return input.Mouse
        else:
            return input.Touch

    def _assert_not_visible(self, type_name='*', **kwargs):
        """Confirm that an object is hidden.

        Internally this means asserting that selecting the object fails.
        """
        try:
            object = self.main_view.select_single(type_name, **kwargs)
            # object.visible is always True if the select succeeds
            self.assertThat(object.visible, Eventually(Equals(False)))
        except dbus.StateNotFoundError:
            # Caret can't be selected because it's hidden
            pass