1
# Copyright (C) 2010 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
print """nose is required. Install the package python-nose.
27
from mago.application import TestApplication
28
from mago.config import get_config
30
# Available Nose plugins
31
from mago.noseplugins.maybe import Maybe # Just a test plugin
32
from mago.noseplugins.magoxml import MagoXML
33
PLUGINS = [ Maybe(), MagoXML() ]
35
# Global configuration
36
# defaults to ~/.magorc (defined in config.py)
39
# Global Configuration
40
magoConfig = get_config()
42
from inspect import getfile, getmodule
44
class TestCase(testtools.TestCase):
45
"""Base class for desktop testing"""
48
# Set it static because LDTP can run only one app at once.
51
# Class and Test Configuration
52
# This configuration is specific to the run and different from the
53
# global configuration.
54
# By default the name $(basename MODULEFILEPATH).ini
57
def __init__(self, methodName = 'testMethod'):
58
"""Construct a TestCase instance
60
Loads the configuration for the application and the test
62
super(TestCase, self).__init__(methodName)
63
#self.magoConfig = get_config()
65
moduleFile = getfile(getmodule(self))
66
classConfigFile = '.'.join(moduleFile.split('.')[:-1]) + ".ini"
67
self.testConfig = get_config(classConfigFile)
74
Called once for all the tests in a TestCase.
75
set setupOnce to True to activate it.
76
This is used if you want to launch the application to test only once
77
at the beginning of the test session or want to do some extensive setup
79
super(TestCase, self).setUpClass()
84
Launch the application when setupOnce is set to False
86
super(TestCase, self).setUp()
88
if not hasattr(TestCase, 'application'):
89
TestCase.application = None
91
application = TestCase.application
92
# Check mandatory propertys, launcher, launcher_args and window_name
95
TestCase.application =\
96
TestApplication(self.launcher, window_name = self.window_name)
97
#TestCase.application.launch()
99
if not application.isRunning:
100
TestCase.application.launch()
103
def tearDownClass(self):
106
Called once at the end of the class to close the application and
107
cleanup the environment and destroy the application.
108
Only called if setupOnce is set to True.
110
super(TestCase, self).tearDownClass()
111
if self.setupOnce and TestCase.application:
112
del TestCase.application
117
Called once at the end of the test to close the application and
118
cleanup the environment and destroy the application.
119
Only called if setupOnce is set to False.
121
super(TestCase, self).tearDown()
122
if not self.setupOnce and TestCase.application:
123
del TestCase.application
125
def getapplication(self):
126
return self.application
129
class TestResult(testtools.TestResult):
131
def __init__(self, stream=sys.stderr, descriptions=True, verbosity=1):
132
super(TestResult, self).__init__()
133
print "TestResult::__init__"
135
self.descriptions = descriptions
137
def getDescription(self, test):
138
doc_first_line = test.shortDescription()
139
if self.descriptions and doc_first_line:
140
return '\n'.join((str(test), doc_first_line))
144
def startTest(self, test):
145
super(TestResult, self).startTest(test)
147
self.stream.write(self.getDescription(test))
148
self.stream.write(" ... ")
151
def addSuccess(self, test):
152
super(TestResult, self).addSuccess(test)
154
self.stream.write(self.getDescription(test))
155
self.stream.write(" Success ")
159
class TextTestRunner(unittest.TextTestRunner):
160
resultclass = TestResult
162
#def __init__(self, stream=sys.stderr, descriptions=True, verbosity=1, resultclass=None):
163
# super(TextTestRunner, self).__init__(stream, descriptions, verbosity, resultclass)
164
# print "TestRunner::__init__"
171
nose.main(addplugins = PLUGINS)
174
if __name__ == '__main__':