1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# -*- coding: utf-8 -*-
import codecs
import os
import sys
import unittest
from nose.plugins.capture import Capture
from nose.plugins.xunit import Xunit
from nose.plugins.skip import Skip
from nose.plugins import PluginTester
support = os.path.join(os.path.dirname(__file__), 'support')
xml_results_filename = os.path.join(support, "xunit.xml")
# the plugin is tested better in unit tests.
# this is just here for a sanity check
class TestXUnitPlugin(PluginTester, unittest.TestCase):
activate = '--with-xunit'
args = ['-v','--xunit-file=%s' % xml_results_filename]
plugins = [Xunit(), Skip()]
suitepath = os.path.join(support, 'xunit')
def runTest(self):
print str(self.output)
assert "ERROR: test_error" in self.output
assert "FAIL: test_fail" in self.output
assert "test_skip (test_xunit_as_suite.TestForXunit) ... SKIP: skipit" in self.output
assert "XML: %s" % xml_results_filename in self.output
f = codecs.open(xml_results_filename,'r', encoding='utf8')
result = f.read()
f.close()
print result.encode('utf8', 'replace')
assert '<?xml version="1.0" encoding="UTF-8"?>' in result
assert '<testsuite name="nosetests" tests="6" errors="2" failures="1" skip="1">' in result
assert '<testcase classname="test_xunit_as_suite.TestForXunit" name="test_error" time="' in result
# TODO(Kumar) think of better x-platform code here that
# does not confuse 2to3
if sys.version_info[0:2] >= (3,0):
assert ('<error type="%s.Exception" message="日本">' % (Exception.__module__,)) in result
else:
assert ('<error type="%s.Exception" message="日本">' % (Exception.__module__,)).decode('utf8') in result
assert '</testcase>' in result
assert '</testsuite>' in result
class TestIssue134(PluginTester, unittest.TestCase):
activate = '--with-xunit'
args = ['-v','--xunit-file=%s' % xml_results_filename]
plugins = [Capture(), Xunit()]
suitepath = os.path.join(support, 'issue134')
def runTest(self):
print str(self.output)
f = open(xml_results_filename,'r')
result = f.read()
f.close()
print result
assert 'raise IOError(42, "test")' in result
assert 'tests="1" errors="1" failures="0" skip="0"' in result
class TestIssue279(PluginTester, unittest.TestCase):
activate = '--with-xunit'
args = ['-v','--xunit-file=%s' % xml_results_filename]
plugins = [Xunit(), Skip()]
suitepath = os.path.join(support, 'issue279')
def runTest(self):
print str(self.output)
f = open(xml_results_filename,'r')
result = f.read()
f.close()
print result
assert 'tests="1" errors="1" failures="0" skip="0"' in result
assert "Exception: I would prefer not to" in result
class TestIssue680(PluginTester, unittest.TestCase):
activate = '--with-xunit'
args = ['-v','--xunit-file=%s' % xml_results_filename]
plugins = [Xunit(), Skip()]
suitepath = os.path.join(support, 'issue680')
def runTest(self):
print str(self.output)
f = open(xml_results_filename,'rb')
result = f.read().decode('utf-8')
f.close()
print result
assert 'tests="1" errors="0" failures="0" skip="0"' in result
class TestIssue700(PluginTester, unittest.TestCase):
activate = '--with-xunit'
args = ['-v','--xunit-file=%s' % xml_results_filename]
plugins = [Xunit(), Skip()]
suitepath = os.path.join(support, 'issue700')
def runTest(self):
print str(self.output)
f = open(xml_results_filename,'r')
result = f.read()
f.close()
print result
assert 'tests="1" errors="0" failures="0" skip="0"' in result
assert 'line1\n' in result
assert 'line2\n' in result
class TestIssue859(PluginTester, unittest.TestCase):
activate = '--with-xunit'
testsuite_name = "TestIssue859"
args = ['-v', '--xunit-file=%s' % xml_results_filename, '--xunit-testsuite-name=%s' % testsuite_name]
plugins = [Xunit(), Skip()]
suitepath = os.path.join(support, 'issue859')
def runTest(self):
print str(self.output)
f = open(xml_results_filename, 'r')
result = f.read()
f.close()
print result
assert 'tests="1" errors="0" failures="0" skip="0"' in result
assert 'testsuite name="TestIssue859"' in result
|