1
# Copyright (C) 2009 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
17
"""Tests run per UIFactory.
19
Testing UIFactories is a bit interesting because we require they all support a
20
common interface, but the way they implement it can vary very widely. Between
21
text, batch-mode, graphical and other potential UIFactories, the requirements
22
to set up a factory, to make it respond to requests, and to simulate user
26
# This may seem like a complicated way to test it compared to just having
27
# tests for each implementation, but it's supposed to help make sure that all
28
# new methods added to the UIFactory interface are tested by default, rather
29
# than forgotten. At least there should be an explicit decision (eg with
30
# TestSkipped) that it's not possible to test them automatically.
32
# For each UIFactory we have a UIFactoryFitting
35
from cStringIO import StringIO
45
class TestUIFactory(tests.TestCase):
48
tests.TestCase.setUp(self)
49
self.fitting = self.fitting_class()
51
def test_construction(self):
52
factory = self.fitting.make_factory()
55
self.fitting.check_note("a note to the user")
58
class BaseUIFactoryFitting(object):
63
class TextUIFactoryFitting(BaseUIFactoryFitting):
65
def make_factory(self):
66
self.stdin = StringIO()
67
self.stdout = StringIO()
68
self.stderr = StringIO()
69
self.factory = ui.text.TextUIFactory(self.stdin, self.stdout,
73
def check_note(self, note_text):
74
factory = self.make_factory()
75
factory.note(note_text)
76
# XXX: This should be assertEquals but this isn't a TestCase
77
# self.assertEquals("%s\n" % note_text,
78
# self.stdout.getvalue())
81
# NB: There's no registry of UIFactories at the moment so we just define the
82
# scenarios here. Plugins that provide custom UIFactories might like to add
83
# their factories and suitable fittings.
85
('text', dict(fitting_class=TextUIFactoryFitting))
89
def load_tests(base_test_suite, module, loader):
90
to_test_suite = unittest.TestSuite()
91
tests.multiply_tests(base_test_suite, scenarios, to_test_suite)