1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3
# Copyright (C) 2013, 2014 Canonical Ltd
5
# This program is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License version 3 as
7
# published by the Free Software Foundation.
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 General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
"""Calculator app autopilot tests."""
23
import ubuntu_calculator_app
25
from autopilot.testcase import AutopilotTestCase
26
from autopilot import logging as autopilot_logging
28
import ubuntuuitoolkit
29
from ubuntuuitoolkit import base
31
logger = logging.getLogger(__name__)
34
class CalculatorAppTestCase(AutopilotTestCase):
35
"""A common test case class that provides several useful methods for
36
the ubuntu-calculator-app tests.
40
local_location = os.path.dirname(os.path.dirname(os.getcwd()))
42
local_location_qml = os.path.join(local_location,
43
'ubuntu-calculator-app.qml')
45
installed_location_qml = os.path.join('/usr/share/ubuntu-calculator-app/',
46
'ubuntu-calculator-app.qml')
48
def get_launcher_and_type(self):
49
if os.path.exists(self.local_location_qml):
50
launcher = self.launch_test_local
52
elif os.path.exists(self.installed_location_qml):
53
launcher = self.launch_test_installed
56
launcher = self.launch_test_click
58
return launcher, test_type
61
super(CalculatorAppTestCase, self).setUp()
62
self.clear_calculator_database()
63
self.launcher, self.test_type = self.get_launcher_and_type()
65
# Unset the current locale to ensure locale-specific data
66
# (day and month names, first day of the week, …) doesn’t get
67
# in the way of test expectations.
68
self.patch_environment('LC_ALL', 'C')
69
self.app = ubuntu_calculator_app.CalculatorApp(self.launcher(),
72
@autopilot_logging.log_action(logger.info)
73
def launch_test_local(self):
74
return self.launch_test_application(
75
base.get_qmlscene_launch_command(),
76
self.local_location_qml,
78
emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
80
@autopilot_logging.log_action(logger.info)
81
def launch_test_installed(self):
82
return self.launch_test_application(
83
base.get_qmlscene_launch_command(),
84
self.installed_location_qml,
86
emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
88
@autopilot_logging.log_action(logger.info)
89
def launch_test_click(self):
90
return self.launch_click_package(
91
"com.ubuntu.calculator",
92
emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
94
def clear_calculator_database(self):
95
calculator_database_path = os.path.join(
96
os.path.expanduser('~'),
99
'com.ubuntu.calculator'
102
if os.path.exists(calculator_database_path):
103
shutil.rmtree(calculator_database_path)
104
lambda: os.path.exists(calculator_database_path).wait_for(False)