2
# subunit: extensions to python unittest to get test results from subprocesses.
3
# Copyright (C) 2005 Robert Collins <robertc@robertcollins.net>
5
# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
6
# license at the users choice. A copy of both licenses are available in the
7
# project source as Apache-2.0 and BSD. You may not use this file except in
8
# compliance with one of these two licences.
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
12
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
# license you chose for the specific language governing permissions and
14
# limitations under that license.
17
"""Tests for subunit.TestResultStats."""
20
from StringIO import StringIO
25
class TestTestResultStats(unittest.TestCase):
26
"""Test for TestResultStats, a TestResult object that generates stats."""
29
self.output = StringIO()
30
self.result = subunit.TestResultStats(self.output)
31
self.input_stream = StringIO()
32
self.test = subunit.ProtocolTestCase(self.input_stream)
34
def test_stats_empty(self):
35
self.test.run(self.result)
36
self.assertEqual(0, self.result.total_tests)
37
self.assertEqual(0, self.result.passed_tests)
38
self.assertEqual(0, self.result.failed_tests)
39
self.assertEqual(set(), self.result.seen_tags)
41
def setUpUsedStream(self):
42
self.input_stream.write("""tags: global
55
self.input_stream.seek(0)
56
self.test.run(self.result)
58
def test_stats_smoke_everything(self):
59
# Statistics are calculated usefully.
60
self.setUpUsedStream()
61
self.assertEqual(5, self.result.total_tests)
62
self.assertEqual(2, self.result.passed_tests)
63
self.assertEqual(2, self.result.failed_tests)
64
self.assertEqual(1, self.result.skipped_tests)
65
self.assertEqual(set(["global", "local"]), self.result.seen_tags)
67
def test_stat_formatting(self):
73
Seen tags: global, local
75
self.setUpUsedStream()
76
self.result.formatStats()
77
self.assertEqual(expected, self.output.getvalue())
81
loader = subunit.tests.TestUtil.TestLoader()
82
result = loader.loadTestsFromName(__name__)