123
123
with catch_warning() as w:
124
124
self.assertWarning(buffer('a'), w, expected)
126
def test_file_xreadlines(self):
127
expected = ("f.xreadlines() not supported in 3.x, "
128
"try 'for line in f' instead")
129
with file(__file__) as f:
130
with catch_warning() as w:
131
self.assertWarning(f.xreadlines(), w, expected)
134
class TestStdlibRemovals(unittest.TestCase):
136
# test.testall not tested as it executes all unit tests as an
137
# import side-effect.
138
all_platforms = ('audiodev', 'imputil', 'mutex', 'user', 'new', 'rexec',
139
'Bastion', 'compiler', 'dircache', 'fpformat',
140
'ihooks', 'mhlib', 'statvfs')
141
inclusive_platforms = {'irix' : ('pure', 'AL', 'al', 'CD', 'cd', 'cddb',
142
'cdplayer', 'CL', 'cl', 'DEVICE', 'GL',
143
'gl', 'ERRNO', 'FILE', 'FL', 'flp', 'fl',
144
'fm', 'GET', 'GLWS', 'imgfile', 'IN',
145
'IOCTL', 'jpeg', 'panel', 'panelparser',
146
'readcd', 'SV', 'torgb', 'WAIT'),
147
'darwin' : ('autoGIL', 'Carbon', 'OSATerminology',
148
'icglue', 'Nav', 'MacOS', 'aepack',
149
'aetools', 'aetypes', 'applesingle',
150
'appletrawmain', 'appletrunner',
151
'argvemulator', 'bgenlocations',
152
'EasyDialogs', 'macerrors', 'macostools',
153
'findertools', 'FrameWork', 'ic',
154
'gensuitemodule', 'icopen', 'macresource',
155
'MiniAEFrame', 'pimp', 'PixMapWrapper',
156
'terminalcommand', 'videoreader',
157
'_builtinSuites', 'CodeWarrior',
158
'Explorer', 'Finder', 'Netscape',
159
'StdSuites', 'SystemEvents', 'Terminal',
160
'cfmfile', 'bundlebuilder', 'buildtools',
162
'sunos5' : ('sunaudiodev', 'SUNAUDIODEV'),
164
optional_modules = ('bsddb185', 'Canvas', 'dl', 'linuxaudiodev', 'imageop',
167
def check_removal(self, module_name, optional=False):
168
"""Make sure the specified module, when imported, raises a
169
DeprecationWarning and specifies itself in the message."""
170
with CleanImport(module_name):
171
with catch_warning(record=False) as w:
172
warnings.filterwarnings("error", ".+ removed",
175
__import__(module_name, level=0)
176
except DeprecationWarning as exc:
177
self.assert_(module_name in exc.args[0],
178
"%s warning didn't contain module name"
182
self.fail("Non-optional module {0} raised an "
183
"ImportError.".format(module_name))
185
self.fail("DeprecationWarning not raised for {0}"
186
.format(module_name))
188
def test_platform_independent_removals(self):
189
# Make sure that the modules that are available on all platforms raise
190
# the proper DeprecationWarning.
191
for module_name in self.all_platforms:
192
self.check_removal(module_name)
194
def test_platform_specific_removals(self):
195
# Test the removal of platform-specific modules.
196
for module_name in self.inclusive_platforms.get(sys.platform, []):
197
self.check_removal(module_name, optional=True)
199
def test_optional_module_removals(self):
200
# Test the removal of modules that may or may not be built.
201
for module_name in self.optional_modules:
202
self.check_removal(module_name, optional=True)
204
def test_os_path_walk(self):
205
msg = "In 3.x, os.path.walk is removed in favor of os.walk."
206
def dumbo(where, names, args): pass
207
for path_mod in ("ntpath", "macpath", "os2emxpath", "posixpath"):
208
mod = __import__(path_mod)
209
with catch_warning() as w:
210
# Since os3exmpath just imports it from ntpath
211
warnings.simplefilter("always")
212
mod.walk(".", dumbo, None)
213
self.assertEquals(str(w.message), msg)
216
class TestStdlibRenames(unittest.TestCase):
218
renames = {'Queue': 'queue',
219
'SocketServer': 'socketserver',
220
'ConfigParser': 'configparser',
223
def check_rename(self, module_name, new_module_name):
225
- A DeprecationWarning is raised when importing using the
227
- The module can be imported using the new 3.x name.
228
- The warning message specify both names.
230
with CleanImport(module_name):
231
with catch_warning(record=False) as w:
232
warnings.filterwarnings("error", ".+ renamed to",
235
__import__(module_name, level=0)
236
except DeprecationWarning as exc:
237
self.assert_(module_name in exc.args[0])
238
self.assert_(new_module_name in exc.args[0])
240
self.fail("DeprecationWarning not raised for %s" %
242
with CleanImport(new_module_name):
244
__import__(new_module_name, level=0)
246
self.fail("cannot import %s with its 3.x name, %s" %
247
module_name, new_module_name)
248
except DeprecationWarning:
249
self.fail("unexpected DeprecationWarning raised for %s" %
252
def test_module_renames(self):
253
for module_name, new_module_name in self.renames.items():
254
self.check_rename(module_name, new_module_name)
128
run_unittest(TestPy3KWarnings)
258
run_unittest(TestPy3KWarnings,
130
262
if __name__ == '__main__':