| 1 |
# |
| 2 |
# subunit: extensions to python unittest to get test results from subprocesses. |
| 3 |
# Copyright (C) 2005 Robert Collins <[email protected]> |
| 4 |
# |
| 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. |
| 9 |
# |
| 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. |
| 15 |
# |
| 16 |
|
| 17 |
"""Tests for subunit.TestResultStats.""" |
| 18 |
|
| 19 |
import unittest |
| 20 |
from io import BytesIO, StringIO |
| 21 |
|
| 22 |
|
| 23 |
import subunit |
| 24 |
|
| 25 |
|
| 26 |
class TestTestResultStats(unittest.TestCase): |
| 27 |
"""Test for TestResultStats, a TestResult object that generates stats.""" |
| 28 |
|
| 29 |
def setUp(self): |
| 30 |
self.output = StringIO() |
| 31 |
self.result = subunit.TestResultStats(self.output) |
| 32 |
self.input_stream = BytesIO() |
| 33 |
self.test = subunit.ProtocolTestCase(self.input_stream) |
| 34 |
|
| 35 |
def test_stats_empty(self): |
| 36 |
self.test.run(self.result) |
| 37 |
self.assertEqual(0, self.result.total_tests) |
| 38 |
self.assertEqual(0, self.result.passed_tests) |
| 39 |
self.assertEqual(0, self.result.failed_tests) |
| 40 |
self.assertEqual(set(), self.result.seen_tags) |
| 41 |
|
| 42 |
def setUpUsedStream(self): |
| 43 |
self.input_stream.write( |
| 44 |
b"""tags: global |
| 45 |
test passed |
| 46 |
success passed |
| 47 |
test failed |
| 48 |
tags: local |
| 49 |
failure failed |
| 50 |
test error |
| 51 |
error error |
| 52 |
test skipped |
| 53 |
skip skipped |
| 54 |
test todo |
| 55 |
xfail todo |
| 56 |
""" |
| 57 |
) |
| 58 |
self.input_stream.seek(0) |
| 59 |
self.test.run(self.result) |
| 60 |
|
| 61 |
def test_stats_smoke_everything(self): |
| 62 |
# Statistics are calculated usefully. |
| 63 |
self.setUpUsedStream() |
| 64 |
self.assertEqual(5, self.result.total_tests) |
| 65 |
self.assertEqual(2, self.result.passed_tests) |
| 66 |
self.assertEqual(2, self.result.failed_tests) |
| 67 |
self.assertEqual(1, self.result.skipped_tests) |
| 68 |
self.assertEqual({"global", "local"}, self.result.seen_tags) |
| 69 |
|
| 70 |
def test_stat_formatting(self): |
| 71 |
expected = ( |
| 72 |
""" |
| 73 |
Total tests: 5 |
| 74 |
Passed tests: 2 |
| 75 |
Failed tests: 2 |
| 76 |
Skipped tests: 1 |
| 77 |
Seen tags: global, local |
| 78 |
""" |
| 79 |
)[1:] |
| 80 |
self.setUpUsedStream() |
| 81 |
self.result.formatStats() |
| 82 |
self.assertEqual(expected, self.output.getvalue()) |