1
# Copyright (c) 2008 Twisted Matrix Laboratories.
2
# See LICENSE for details.
5
Tests for the output generated by trial.
10
from twisted.scripts import trial
11
from twisted.trial import runner
12
from twisted.trial.test import packages
16
from twisted.trial import reporter
17
config = trial.Options()
18
config.parseOptions(args)
19
output = StringIO.StringIO()
20
myRunner = runner.TrialRunner(
21
reporter.VerboseTextReporter,
23
workingDirectory=config['temp-directory'])
24
suite = trial._getSuite(config)
25
result = myRunner.run(suite)
26
return output.getvalue()
29
class TestImportErrors(packages.SysPathManglingTest):
30
"""Actually run trial as if on the command line and check that the output
35
parent = "_testImportErrors"
36
def runTrial(self, *args):
37
return runTrial('--temp-directory', self.mktemp(), *args)
39
def _print(self, stuff):
43
def failUnlessIn(self, container, containee, *args, **kwargs):
44
# redefined to be useful in callbacks
45
super(TestImportErrors, self).failUnlessIn(
46
containee, container, *args, **kwargs)
49
def failIfIn(self, container, containee, *args, **kwargs):
50
# redefined to be useful in callbacks
51
super(TestImportErrors, self).failIfIn(
52
containee, container, *args, **kwargs)
55
def test_trialRun(self):
58
def test_nonexistentModule(self):
59
d = self.runTrial('twisted.doesntexist')
60
self.failUnlessIn(d, '[ERROR]')
61
self.failUnlessIn(d, 'twisted.doesntexist')
64
def test_nonexistentPackage(self):
65
d = self.runTrial('doesntexist')
66
self.failUnlessIn(d, 'doesntexist')
67
self.failUnlessIn(d, 'ModuleNotFound')
68
self.failUnlessIn(d, '[ERROR]')
71
def test_nonexistentPackageWithModule(self):
72
d = self.runTrial('doesntexist.barney')
73
self.failUnlessIn(d, 'doesntexist.barney')
74
self.failUnlessIn(d, 'ObjectNotFound')
75
self.failUnlessIn(d, '[ERROR]')
78
def test_badpackage(self):
79
d = self.runTrial('badpackage')
80
self.failUnlessIn(d, '[ERROR]')
81
self.failUnlessIn(d, 'badpackage')
82
self.failIfIn(d, 'IOError')
85
def test_moduleInBadpackage(self):
86
d = self.runTrial('badpackage.test_module')
87
self.failUnlessIn(d, "[ERROR]")
88
self.failUnlessIn(d, "badpackage.test_module")
89
self.failIfIn(d, 'IOError')
92
def test_badmodule(self):
93
d = self.runTrial('package.test_bad_module')
94
self.failUnlessIn(d, '[ERROR]')
95
self.failUnlessIn(d, 'package.test_bad_module')
96
self.failIfIn(d, 'IOError')
97
self.failIfIn(d, '<module ')
100
def test_badimport(self):
101
d = self.runTrial('package.test_import_module')
102
self.failUnlessIn(d, '[ERROR]')
103
self.failUnlessIn(d, 'package.test_import_module')
104
self.failIfIn(d, 'IOError')
105
self.failIfIn(d, '<module ')
108
def test_recurseImport(self):
109
d = self.runTrial('package')
110
self.failUnlessIn(d, '[ERROR]')
111
self.failUnlessIn(d, 'test_bad_module')
112
self.failUnlessIn(d, 'test_import_module')
113
self.failIfIn(d, '<module ')
114
self.failIfIn(d, 'IOError')
117
def test_recurseImportErrors(self):
118
d = self.runTrial('package2')
119
self.failUnlessIn(d, '[ERROR]')
120
self.failUnlessIn(d, 'package2')
121
self.failUnlessIn(d, 'test_module')
122
self.failUnlessIn(d, "No module named frotz")
123
self.failIfIn(d, '<module ')
124
self.failIfIn(d, 'IOError')
127
def test_nonRecurseImportErrors(self):
128
d = self.runTrial('-N', 'package2')
129
self.failUnlessIn(d, '[ERROR]')
130
self.failUnlessIn(d, "No module named frotz")
131
self.failIfIn(d, '<module ')
134
def test_regularRun(self):
135
d = self.runTrial('package.test_module')
136
self.failIfIn(d, '[ERROR]')
137
self.failIfIn(d, 'IOError')
138
self.failUnlessIn(d, 'OK')
139
self.failUnlessIn(d, 'PASSED (successes=1)')
142
def test_filename(self):
143
self.mangleSysPath(self.oldPath)
145
os.path.join(self.parent, 'package', 'test_module.py'))
146
self.failIfIn(d, '[ERROR]')
147
self.failIfIn(d, 'IOError')
148
self.failUnlessIn(d, 'OK')
149
self.failUnlessIn(d, 'PASSED (successes=1)')
152
def test_dosFile(self):
153
## XXX -- not really an output test, more of a script test
154
self.mangleSysPath(self.oldPath)
156
os.path.join(self.parent,
157
'package', 'test_dos_module.py'))
158
self.failIfIn(d, '[ERROR]')
159
self.failIfIn(d, 'IOError')
160
self.failUnlessIn(d, 'OK')
161
self.failUnlessIn(d, 'PASSED (successes=1)')