2
from twisted.trial import unittest
5
from twisted.trial import unittest
7
class FooTest(unittest.TestCase):
12
dosModule = testModule.replace('\n', '\r\n')
16
'''This module is used by test_loader to test the Trial test loading
17
functionality. Do NOT change the number of tests in this module.
18
Do NOT change the names the tests in this module.
21
import unittest as pyunit
22
from twisted.trial import unittest
24
class FooTest(unittest.TestCase):
32
class PyunitTest(pyunit.TestCase):
40
class NotATest(object):
45
class AlphabetTest(unittest.TestCase):
57
class PackageTest(unittest.TestCase):
59
('badpackage/__init__.py', 'frotz\n'),
60
('badpackage/test_module.py', ''),
61
('package2/__init__.py', ''),
62
('package2/test_module.py', 'import frotz\n'),
63
('package/__init__.py', ''),
64
('package/frotz.py', 'frotz\n'),
65
('package/test_bad_module.py',
66
'raise ZeroDivisionError("fake error")'),
67
('package/test_dos_module.py', dosModule),
68
('package/test_import_module.py', 'import frotz'),
69
('package/test_module.py', testModule),
70
('goodpackage/__init__.py', ''),
71
('goodpackage/test_sample.py', testSample),
72
('goodpackage/sub/__init__.py', ''),
73
('goodpackage/sub/test_sample.py', testSample)
76
def _toModuleName(self, filename):
77
name = os.path.splitext(filename)[0]
78
segs = name.split('/')
79
if segs[-1] == '__init__':
84
return map(self._toModuleName, zip(*self.files)[0])
86
def cleanUpModules(self):
87
modules = self.getModules()
90
for module in modules:
92
del sys.modules[module]
96
def createFiles(self, files, parentDir='.'):
97
for filename, contents in self.files:
98
filename = os.path.join(parentDir, filename)
99
self._createDirectory(filename)
100
fd = open(filename, 'w')
104
def _createDirectory(self, filename):
105
directory = os.path.dirname(filename)
106
if not os.path.exists(directory):
107
os.makedirs(directory)
109
def setUp(self, parentDir=None):
110
if parentDir is None:
111
parentDir = self.mktemp()
112
self.parent = parentDir
113
self.createFiles(self.files, parentDir)
116
self.cleanUpModules()
118
class SysPathManglingTest(PackageTest):
119
def setUp(self, parent=None):
120
self.oldPath = sys.path[:]
121
self.newPath = sys.path[:]
123
parent = self.mktemp()
124
PackageTest.setUp(self, parent)
125
self.newPath.append(self.parent)
126
self.mangleSysPath(self.newPath)
129
PackageTest.tearDown(self)
130
self.mangleSysPath(self.oldPath)
132
def mangleSysPath(self, pathVar):
133
sys.path[:] = pathVar