1
# -*- coding: utf-8 -*-
3
# Author: Manuel de la Pena <manuel@canonical.com>
5
# Copyright 2009-2010 Canonical Ltd.
7
# This program is free software: you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License version 3, as published
9
# by the Free Software Foundation.
11
# This program is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranties of
13
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14
# PURPOSE. See the GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License along
17
# with this program. If not, see <http://www.gnu.org/licenses/>.
18
"""Test the skip decorators."""
21
from twisted.trial.runner import LoggedSuite
22
from twisted.trial.reporter import TestResult
24
from ubuntuone.devtools import testcase
25
from ubuntuone.devtools.testcase import BaseTestCase
33
class TestSkipBasicDecorators(BaseTestCase):
34
"""Test skipping decorators."""
36
def test_skip_decorators(self):
37
"""Test the decorators that skip tests."""
40
(False, "False condition"),
41
(True, "True condition")),
43
(OTHER_PLATFORM[sys.platform], "skipIf other platform"),
44
(sys.platform, "skipIf this platform")),
45
(testcase.skipIfNotOS,
46
(sys.platform, "skipIfNot this platform"),
47
(OTHER_PLATFORM[sys.platform],
48
"skipIfNot other platform")))
49
for deco, dont_skip, do_skip in operations_table:
51
class Foo(BaseTestCase):
52
"""Dummy test case used for the decorators testing."""
53
@deco(do_skip[0], do_skip[1])
58
@deco(dont_skip[0], dont_skip[1])
59
def test_dont_skip(self):
60
"""Test not to skip."""
63
test_do_skip = Foo("test_skip")
64
test_dont_skip = Foo("test_dont_skip")
65
suite = LoggedSuite([test_do_skip, test_dont_skip])
68
self.assertEqual(len(result.skips), 1)
69
self.assertEqual(result.successes, 1)
70
self.assertEqual(result.skips,
71
[(test_do_skip, do_skip[1])])
73
def test_skip_class(self):
74
"""Test skipping a full test class."""
75
class Foo(BaseTestCase):
76
"""Test class to be skipped."""
79
"""First test to skip."""
83
"""Second test to skip."""
87
# pylint: disable=C0103
88
Foo = testcase.skipTest("testing")(Foo)
89
# pylint: enable=C0103
93
suite = LoggedSuite([test])
95
self.assertEqual(result.skips, [(test, "testing")])
96
self.assertEqual(record, [])