~aacid/ubuntu-ui-toolkit/save_stat_loading_already_loaded_image

« back to all changes in this revision

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

  • Committer: Juhapekka Piiroinen
  • Date: 2012-09-21 09:42:51 UTC
  • mto: (74.2.2 autopilot-tests-2)
  • mto: This revision was merged to the branch mainline in revision 85.
  • Revision ID: juhapekka.piiroinen@canonical.com-20120921094251-poyhyytiijfke43m
Added autopilot test template

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 2012 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
"""Tavastia autopilot tests."""
 
9
 
 
10
from os import remove
 
11
import os.path
 
12
from tempfile import mktemp
 
13
 
 
14
from autopilot.introspection.qt import QtIntrospectionTestMixin
 
15
from autopilot.testcase import AutopilotTestCase
 
16
 
 
17
 
 
18
def get_module_include_path():
 
19
    return os.path.abspath(
 
20
        os.path.join(
 
21
            os.path.dirname(__file__),
 
22
            '..',
 
23
            '..',
 
24
            '..',
 
25
            'modules')
 
26
        )
 
27
 
 
28
 
 
29
class TavastiaTestCase(AutopilotTestCase, QtIntrospectionTestMixin):
 
30
 
 
31
    """A common test case class that provides several useful methods for SDK tests."""
 
32
 
 
33
    def setUp(self):
 
34
        super(TavastiaTestCase, self).setUp()
 
35
        self.launch_test_qml()
 
36
 
 
37
    def launch_test_qml(self):
 
38
        # If the test class has defined a 'test_qml' class attribute then we
 
39
        # write it to disk and launch it inside the Qml Viewer. If not, then we
 
40
        # silently do nothing (presumably the test has something else planned).
 
41
        if hasattr(self, 'test_qml') and isinstance(self.test_qml, basestring):
 
42
            qml_path = mktemp(suffix='.qml')
 
43
            open(qml_path, 'w').write(self.test_qml)
 
44
            self.addCleanup(remove, qml_path)
 
45
 
 
46
            self.app = self.launch_test_application(
 
47
                "qmlviewer",
 
48
                "-opengl",
 
49
                "-I", get_module_include_path(),
 
50
                qml_path)