~unity-team/+junk/dashboard-playground

« back to all changes in this revision

Viewing changes to tests/autopilot/unity8/tests/__init__.py

  • Committer: Michał Sawicz
  • Date: 2013-06-05 22:03:08 UTC
  • Revision ID: michal.sawicz@canonical.com-20130605220308-yny8fv3futtr04fg
Inital unity8 commit.

Previous history can be found at https://code.launchpad.net/~unity-team/unity/phablet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
 
2
# Copyright 2013 Canonical
 
3
#
 
4
# This program is free software: you can redistribute it and/or modify it
 
5
# under the terms of the GNU General Public License version 3, as published
 
6
# by the Free Software Foundation.
 
7
 
 
8
"""unity8 autopilot tests."""
 
9
 
 
10
import os.path
 
11
 
 
12
from autopilot.testcase import AutopilotTestCase
 
13
from autopilot.matchers import Eventually
 
14
from autopilot.platform import model
 
15
from testtools.matchers import Equals
 
16
 
 
17
from unity8.emulators.main_window import MainWindow
 
18
 
 
19
class FormFactors(object):
 
20
    Phone, Tablet, Desktop = range(3)
 
21
 
 
22
class ShellTestCase(AutopilotTestCase):
 
23
 
 
24
    """A common test case class that provides several useful methods for shell tests."""
 
25
 
 
26
    lightdm_mock = "full"
 
27
 
 
28
    def setUp(self, geometry, grid_size):
 
29
        super(ShellTestCase, self).setUp()
 
30
        # Lets assume we are installed system wide if this file is somewhere in /usr
 
31
        if grid_size != "0":
 
32
            os.environ['GRID_UNIT_PX'] = grid_size
 
33
            self.grid_size = int(grid_size)
 
34
        else:
 
35
            self.grid_size = int(os.environ['GRID_UNIT_PX'])
 
36
        if os.path.realpath(__file__).startswith("/usr/"):
 
37
            self.launch_test_installed(geometry)
 
38
        else:
 
39
            self.launch_test_local(geometry)
 
40
 
 
41
    def launch_test_local(self, geometry):
 
42
        os.environ['LD_LIBRARY_PATH'] = "../../../unity_build/build/lib:../../builddir/tests/mocks/LightDM/" + self.lightdm_mock
 
43
        os.environ['QML2_IMPORT_PATH'] = "../../builddir/tests/mocks:../../builddir/plugins"
 
44
        if geometry != "0x0":
 
45
            self.app = self.launch_test_application(
 
46
                "../../builddir/unity8", "-geometry", geometry, "-frameless", app_type='qt')
 
47
        else:
 
48
            self.app = self.launch_test_application(
 
49
                "../../builddir/unity8", "-fullscreen", app_type='qt')
 
50
 
 
51
    def launch_test_installed(self, geometry):
 
52
        os.environ['LD_LIBRARY_PATH'] = "/usr/share/unity8/plugins/mocks/LightDM/" + self.lightdm_mock
 
53
        os.environ['QML2_IMPORT_PATH'] = "/usr/share/unity8/plugins/mocks:/usr/share/unity8/plugins"
 
54
        if model() == 'Desktop' and geometry != "0x0":
 
55
            self.app = self.launch_test_application(
 
56
               "unity8", "-geometry", geometry, "-frameless", app_type='qt')
 
57
        else:
 
58
            self.app = self.launch_test_application(
 
59
               "unity8", "-fullscreen", app_type='qt')
 
60
 
 
61
    def skipWrapper(*args, **kwargs):
 
62
        pass
 
63
 
 
64
    def form_factor(self):
 
65
        return FormFactors.Desktop
 
66
 
 
67
    def __getattribute__(self, attr_name):
 
68
        attr = object.__getattribute__(self, attr_name);
 
69
        if attr_name.startswith("test_"):
 
70
            try:
 
71
                if self.form_factor() in attr.blacklist:
 
72
                    return self.skipWrapper
 
73
            except:
 
74
                pass
 
75
        return attr
 
76
 
 
77
    @property
 
78
    def main_window(self):
 
79
        return MainWindow(self.app)