blob: eb05303c308f5032ba743cb395f41ce777a20b1b [file] [log] [blame]
Steven Bethardae42f332008-03-18 17:26:10 +00001import unittest
Brett Cannon977eb022008-03-19 17:37:43 +00002import sys
Benjamin Petersonbec087f2009-03-26 21:10:30 +00003from test.test_support import check_warnings, CleanImport, run_unittest
Steven Bethardae42f332008-03-18 17:26:10 +00004import warnings
5
Benjamin Petersona6864e02008-07-14 17:42:17 +00006from contextlib import nested
7
Brett Cannon977eb022008-03-19 17:37:43 +00008if not sys.py3kwarning:
Benjamin Petersonbec087f2009-03-26 21:10:30 +00009 raise unittest.SkipTest('%s must be run with the -3 flag' % __name__)
Brett Cannon977eb022008-03-19 17:37:43 +000010
Nick Coghland2e09382008-09-11 12:11:06 +000011def reset_module_registry(module):
12 try:
13 registry = module.__warningregistry__
14 except AttributeError:
15 pass
16 else:
17 registry.clear()
Steven Bethardae42f332008-03-18 17:26:10 +000018
19class TestPy3KWarnings(unittest.TestCase):
20
Nick Coghlan48361f52008-08-11 15:45:58 +000021 def assertWarning(self, _, warning, expected_message):
Nick Coghland2e09382008-09-11 12:11:06 +000022 self.assertEqual(str(warning.message), expected_message)
Nick Coghlan48361f52008-08-11 15:45:58 +000023
Benjamin Peterson1bf47652009-07-02 17:06:17 +000024 def assertNoWarning(self, _, recorder):
25 self.assertEqual(len(recorder.warnings), 0)
26
Benjamin Peterson2fe3ef82008-06-08 02:05:33 +000027 def test_backquote(self):
28 expected = 'backquote not supported in 3.x; use repr()'
Nick Coghland2e09382008-09-11 12:11:06 +000029 with check_warnings() as w:
Benjamin Peterson2fe3ef82008-06-08 02:05:33 +000030 exec "`2`" in {}
31 self.assertWarning(None, w, expected)
32
Benjamin Peterson399b1fe2008-10-25 02:53:28 +000033 def test_forbidden_names(self):
Benjamin Petersond5efd202008-06-08 22:52:37 +000034 # So we don't screw up our globals
35 def safe_exec(expr):
36 def f(**kwargs): pass
37 exec expr in {'f' : f}
38
Benjamin Peterson399b1fe2008-10-25 02:53:28 +000039 tests = [("True", "assignment to True or False is forbidden in 3.x"),
40 ("False", "assignment to True or False is forbidden in 3.x"),
41 ("nonlocal", "nonlocal is a keyword in 3.x")]
Nick Coghland2e09382008-09-11 12:11:06 +000042 with check_warnings() as w:
Benjamin Peterson399b1fe2008-10-25 02:53:28 +000043 for keyword, expected in tests:
44 safe_exec("{0} = False".format(keyword))
45 self.assertWarning(None, w, expected)
46 w.reset()
47 try:
48 safe_exec("obj.{0} = True".format(keyword))
49 except NameError:
50 pass
51 self.assertWarning(None, w, expected)
52 w.reset()
53 safe_exec("def {0}(): pass".format(keyword))
54 self.assertWarning(None, w, expected)
55 w.reset()
56 safe_exec("class {0}: pass".format(keyword))
57 self.assertWarning(None, w, expected)
58 w.reset()
59 safe_exec("def f({0}=43): pass".format(keyword))
60 self.assertWarning(None, w, expected)
61 w.reset()
Benjamin Petersond5efd202008-06-08 22:52:37 +000062
63
Steven Bethardae42f332008-03-18 17:26:10 +000064 def test_type_inequality_comparisons(self):
Georg Brandld5b635f2008-03-25 08:29:14 +000065 expected = 'type inequality comparisons not supported in 3.x'
Nick Coghland2e09382008-09-11 12:11:06 +000066 with check_warnings() as w:
Steven Bethardae42f332008-03-18 17:26:10 +000067 self.assertWarning(int < str, w, expected)
Nick Coghland2e09382008-09-11 12:11:06 +000068 w.reset()
Steven Bethardae42f332008-03-18 17:26:10 +000069 self.assertWarning(type < object, w, expected)
70
71 def test_object_inequality_comparisons(self):
Georg Brandld5b635f2008-03-25 08:29:14 +000072 expected = 'comparing unequal types not supported in 3.x'
Nick Coghland2e09382008-09-11 12:11:06 +000073 with check_warnings() as w:
Steven Bethardae42f332008-03-18 17:26:10 +000074 self.assertWarning(str < [], w, expected)
Nick Coghland2e09382008-09-11 12:11:06 +000075 w.reset()
Steven Bethardae42f332008-03-18 17:26:10 +000076 self.assertWarning(object() < (1, 2), w, expected)
77
78 def test_dict_inequality_comparisons(self):
Georg Brandld5b635f2008-03-25 08:29:14 +000079 expected = 'dict inequality comparisons not supported in 3.x'
Nick Coghland2e09382008-09-11 12:11:06 +000080 with check_warnings() as w:
Steven Bethardae42f332008-03-18 17:26:10 +000081 self.assertWarning({} < {2:3}, w, expected)
Nick Coghland2e09382008-09-11 12:11:06 +000082 w.reset()
Steven Bethardae42f332008-03-18 17:26:10 +000083 self.assertWarning({} <= {}, w, expected)
Nick Coghland2e09382008-09-11 12:11:06 +000084 w.reset()
Steven Bethardae42f332008-03-18 17:26:10 +000085 self.assertWarning({} > {2:3}, w, expected)
Nick Coghland2e09382008-09-11 12:11:06 +000086 w.reset()
Steven Bethardae42f332008-03-18 17:26:10 +000087 self.assertWarning({2:3} >= {}, w, expected)
88
89 def test_cell_inequality_comparisons(self):
Georg Brandld5b635f2008-03-25 08:29:14 +000090 expected = 'cell comparisons not supported in 3.x'
Steven Bethardae42f332008-03-18 17:26:10 +000091 def f(x):
92 def g():
93 return x
94 return g
95 cell0, = f(0).func_closure
96 cell1, = f(1).func_closure
Nick Coghland2e09382008-09-11 12:11:06 +000097 with check_warnings() as w:
Steven Bethardae42f332008-03-18 17:26:10 +000098 self.assertWarning(cell0 == cell1, w, expected)
Nick Coghland2e09382008-09-11 12:11:06 +000099 w.reset()
Steven Bethardae42f332008-03-18 17:26:10 +0000100 self.assertWarning(cell0 < cell1, w, expected)
101
Steven Bethard6a644f92008-03-18 22:08:20 +0000102 def test_code_inequality_comparisons(self):
Georg Brandld5b635f2008-03-25 08:29:14 +0000103 expected = 'code inequality comparisons not supported in 3.x'
Steven Bethard6a644f92008-03-18 22:08:20 +0000104 def f(x):
105 pass
106 def g(x):
107 pass
Nick Coghland2e09382008-09-11 12:11:06 +0000108 with check_warnings() as w:
Steven Bethard6a644f92008-03-18 22:08:20 +0000109 self.assertWarning(f.func_code < g.func_code, w, expected)
Nick Coghland2e09382008-09-11 12:11:06 +0000110 w.reset()
Steven Bethard6a644f92008-03-18 22:08:20 +0000111 self.assertWarning(f.func_code <= g.func_code, w, expected)
Nick Coghland2e09382008-09-11 12:11:06 +0000112 w.reset()
Steven Bethard6a644f92008-03-18 22:08:20 +0000113 self.assertWarning(f.func_code >= g.func_code, w, expected)
Nick Coghland2e09382008-09-11 12:11:06 +0000114 w.reset()
Steven Bethard6a644f92008-03-18 22:08:20 +0000115 self.assertWarning(f.func_code > g.func_code, w, expected)
116
117 def test_builtin_function_or_method_comparisons(self):
118 expected = ('builtin_function_or_method '
Benjamin Peterson1bf47652009-07-02 17:06:17 +0000119 'order comparisons not supported in 3.x')
Steven Bethard6a644f92008-03-18 22:08:20 +0000120 func = eval
121 meth = {}.get
Nick Coghland2e09382008-09-11 12:11:06 +0000122 with check_warnings() as w:
Steven Bethard6a644f92008-03-18 22:08:20 +0000123 self.assertWarning(func < meth, w, expected)
Nick Coghland2e09382008-09-11 12:11:06 +0000124 w.reset()
Steven Bethard6a644f92008-03-18 22:08:20 +0000125 self.assertWarning(func > meth, w, expected)
Nick Coghland2e09382008-09-11 12:11:06 +0000126 w.reset()
Steven Bethard6a644f92008-03-18 22:08:20 +0000127 self.assertWarning(meth <= func, w, expected)
Nick Coghland2e09382008-09-11 12:11:06 +0000128 w.reset()
Steven Bethard6a644f92008-03-18 22:08:20 +0000129 self.assertWarning(meth >= func, w, expected)
Benjamin Peterson1bf47652009-07-02 17:06:17 +0000130 w.reset()
131 self.assertNoWarning(meth == func, w)
132 self.assertNoWarning(meth != func, w)
133 lam = lambda x: x
134 self.assertNoWarning(lam == func, w)
135 self.assertNoWarning(lam != func, w)
Steven Bethard6a644f92008-03-18 22:08:20 +0000136
Benjamin Petersonf09925d2008-12-22 20:16:25 +0000137 def test_frame_attributes(self):
138 template = "%s has been removed in 3.x"
139 f = sys._getframe(0)
140 for attr in ("f_exc_traceback", "f_exc_value", "f_exc_type"):
141 expected = template % attr
142 with check_warnings() as w:
143 self.assertWarning(getattr(f, attr), w, expected)
144 w.reset()
145 self.assertWarning(setattr(f, attr, None), w, expected)
146
Raymond Hettinger05387862008-03-19 17:45:19 +0000147 def test_sort_cmp_arg(self):
Georg Brandld5b635f2008-03-25 08:29:14 +0000148 expected = "the cmp argument is not supported in 3.x"
Raymond Hettinger05387862008-03-19 17:45:19 +0000149 lst = range(5)
150 cmp = lambda x,y: -1
151
Nick Coghland2e09382008-09-11 12:11:06 +0000152 with check_warnings() as w:
Raymond Hettinger05387862008-03-19 17:45:19 +0000153 self.assertWarning(lst.sort(cmp=cmp), w, expected)
Nick Coghland2e09382008-09-11 12:11:06 +0000154 w.reset()
Raymond Hettinger05387862008-03-19 17:45:19 +0000155 self.assertWarning(sorted(lst, cmp=cmp), w, expected)
Nick Coghland2e09382008-09-11 12:11:06 +0000156 w.reset()
Raymond Hettinger05387862008-03-19 17:45:19 +0000157 self.assertWarning(lst.sort(cmp), w, expected)
Nick Coghland2e09382008-09-11 12:11:06 +0000158 w.reset()
Raymond Hettinger05387862008-03-19 17:45:19 +0000159 self.assertWarning(sorted(lst, cmp), w, expected)
160
Georg Brandl5a444242008-03-21 20:11:46 +0000161 def test_sys_exc_clear(self):
Georg Brandld5b635f2008-03-25 08:29:14 +0000162 expected = 'sys.exc_clear() not supported in 3.x; use except clauses'
Nick Coghland2e09382008-09-11 12:11:06 +0000163 with check_warnings() as w:
Georg Brandl5a444242008-03-21 20:11:46 +0000164 self.assertWarning(sys.exc_clear(), w, expected)
165
Georg Brandl07e56812008-03-21 20:21:46 +0000166 def test_methods_members(self):
167 expected = '__members__ and __methods__ not supported in 3.x'
168 class C:
169 __methods__ = ['a']
170 __members__ = ['b']
171 c = C()
Nick Coghland2e09382008-09-11 12:11:06 +0000172 with check_warnings() as w:
Georg Brandl07e56812008-03-21 20:21:46 +0000173 self.assertWarning(dir(c), w, expected)
174
Georg Brandl65bb42d2008-03-21 20:38:24 +0000175 def test_softspace(self):
176 expected = 'file.softspace not supported in 3.x'
177 with file(__file__) as f:
Nick Coghland2e09382008-09-11 12:11:06 +0000178 with check_warnings() as w:
Georg Brandl65bb42d2008-03-21 20:38:24 +0000179 self.assertWarning(f.softspace, w, expected)
180 def set():
181 f.softspace = 0
Nick Coghland2e09382008-09-11 12:11:06 +0000182 with check_warnings() as w:
Georg Brandl65bb42d2008-03-21 20:38:24 +0000183 self.assertWarning(set(), w, expected)
184
Benjamin Peterson712ee922008-08-24 18:10:20 +0000185 def test_slice_methods(self):
186 class Spam(object):
187 def __getslice__(self, i, j): pass
188 def __setslice__(self, i, j, what): pass
189 def __delslice__(self, i, j): pass
190 class Egg:
191 def __getslice__(self, i, h): pass
192 def __setslice__(self, i, j, what): pass
193 def __delslice__(self, i, j): pass
194
195 expected = "in 3.x, __{0}slice__ has been removed; use __{0}item__"
196
197 for obj in (Spam(), Egg()):
Nick Coghland2e09382008-09-11 12:11:06 +0000198 with check_warnings() as w:
Benjamin Peterson712ee922008-08-24 18:10:20 +0000199 self.assertWarning(obj[1:2], w, expected.format('get'))
Nick Coghland2e09382008-09-11 12:11:06 +0000200 w.reset()
Benjamin Peterson712ee922008-08-24 18:10:20 +0000201 del obj[3:4]
202 self.assertWarning(None, w, expected.format('del'))
Nick Coghland2e09382008-09-11 12:11:06 +0000203 w.reset()
Benjamin Peterson712ee922008-08-24 18:10:20 +0000204 obj[4:5] = "eggs"
205 self.assertWarning(None, w, expected.format('set'))
206
Benjamin Petersonf4fcdb62008-06-08 23:00:00 +0000207 def test_tuple_parameter_unpacking(self):
208 expected = "tuple parameter unpacking has been removed in 3.x"
Nick Coghland2e09382008-09-11 12:11:06 +0000209 with check_warnings() as w:
Benjamin Petersonf4fcdb62008-06-08 23:00:00 +0000210 exec "def f((a, b)): pass"
211 self.assertWarning(None, w, expected)
212
Georg Brandl80055f62008-03-25 07:56:27 +0000213 def test_buffer(self):
Nick Coghlan48361f52008-08-11 15:45:58 +0000214 expected = 'buffer() not supported in 3.x'
Nick Coghland2e09382008-09-11 12:11:06 +0000215 with check_warnings() as w:
Georg Brandl80055f62008-03-25 07:56:27 +0000216 self.assertWarning(buffer('a'), w, expected)
217
Georg Brandla9916b52008-05-17 22:11:54 +0000218 def test_file_xreadlines(self):
219 expected = ("f.xreadlines() not supported in 3.x, "
220 "try 'for line in f' instead")
221 with file(__file__) as f:
Nick Coghland2e09382008-09-11 12:11:06 +0000222 with check_warnings() as w:
Georg Brandla9916b52008-05-17 22:11:54 +0000223 self.assertWarning(f.xreadlines(), w, expected)
224
Nick Coghlan48361f52008-08-11 15:45:58 +0000225 def test_hash_inheritance(self):
Nick Coghland2e09382008-09-11 12:11:06 +0000226 with check_warnings() as w:
Nick Coghlan48361f52008-08-11 15:45:58 +0000227 # With object as the base class
228 class WarnOnlyCmp(object):
229 def __cmp__(self, other): pass
Nick Coghland2e09382008-09-11 12:11:06 +0000230 self.assertEqual(len(w.warnings), 1)
Nick Coghlan48361f52008-08-11 15:45:58 +0000231 self.assertWarning(None, w,
232 "Overriding __cmp__ blocks inheritance of __hash__ in 3.x")
Nick Coghland2e09382008-09-11 12:11:06 +0000233 w.reset()
Nick Coghlan48361f52008-08-11 15:45:58 +0000234 class WarnOnlyEq(object):
235 def __eq__(self, other): pass
Nick Coghland2e09382008-09-11 12:11:06 +0000236 self.assertEqual(len(w.warnings), 1)
Nick Coghlan48361f52008-08-11 15:45:58 +0000237 self.assertWarning(None, w,
238 "Overriding __eq__ blocks inheritance of __hash__ in 3.x")
Nick Coghland2e09382008-09-11 12:11:06 +0000239 w.reset()
Nick Coghlan48361f52008-08-11 15:45:58 +0000240 class WarnCmpAndEq(object):
241 def __cmp__(self, other): pass
242 def __eq__(self, other): pass
Nick Coghland2e09382008-09-11 12:11:06 +0000243 self.assertEqual(len(w.warnings), 2)
244 self.assertWarning(None, w.warnings[0],
Nick Coghlan48361f52008-08-11 15:45:58 +0000245 "Overriding __cmp__ blocks inheritance of __hash__ in 3.x")
246 self.assertWarning(None, w,
247 "Overriding __eq__ blocks inheritance of __hash__ in 3.x")
Nick Coghland2e09382008-09-11 12:11:06 +0000248 w.reset()
Nick Coghlan48361f52008-08-11 15:45:58 +0000249 class NoWarningOnlyHash(object):
250 def __hash__(self): pass
Nick Coghland2e09382008-09-11 12:11:06 +0000251 self.assertEqual(len(w.warnings), 0)
Nick Coghlan48361f52008-08-11 15:45:58 +0000252 # With an intermediate class in the heirarchy
253 class DefinesAllThree(object):
254 def __cmp__(self, other): pass
255 def __eq__(self, other): pass
256 def __hash__(self): pass
257 class WarnOnlyCmp(DefinesAllThree):
258 def __cmp__(self, other): pass
Nick Coghland2e09382008-09-11 12:11:06 +0000259 self.assertEqual(len(w.warnings), 1)
Nick Coghlan48361f52008-08-11 15:45:58 +0000260 self.assertWarning(None, w,
261 "Overriding __cmp__ blocks inheritance of __hash__ in 3.x")
Nick Coghland2e09382008-09-11 12:11:06 +0000262 w.reset()
Nick Coghlan48361f52008-08-11 15:45:58 +0000263 class WarnOnlyEq(DefinesAllThree):
264 def __eq__(self, other): pass
Nick Coghland2e09382008-09-11 12:11:06 +0000265 self.assertEqual(len(w.warnings), 1)
Nick Coghlan48361f52008-08-11 15:45:58 +0000266 self.assertWarning(None, w,
267 "Overriding __eq__ blocks inheritance of __hash__ in 3.x")
Nick Coghland2e09382008-09-11 12:11:06 +0000268 w.reset()
Nick Coghlan48361f52008-08-11 15:45:58 +0000269 class WarnCmpAndEq(DefinesAllThree):
270 def __cmp__(self, other): pass
271 def __eq__(self, other): pass
Nick Coghland2e09382008-09-11 12:11:06 +0000272 self.assertEqual(len(w.warnings), 2)
273 self.assertWarning(None, w.warnings[0],
Nick Coghlan48361f52008-08-11 15:45:58 +0000274 "Overriding __cmp__ blocks inheritance of __hash__ in 3.x")
275 self.assertWarning(None, w,
276 "Overriding __eq__ blocks inheritance of __hash__ in 3.x")
Nick Coghland2e09382008-09-11 12:11:06 +0000277 w.reset()
Nick Coghlan48361f52008-08-11 15:45:58 +0000278 class NoWarningOnlyHash(DefinesAllThree):
279 def __hash__(self): pass
Nick Coghland2e09382008-09-11 12:11:06 +0000280 self.assertEqual(len(w.warnings), 0)
Nick Coghlan48361f52008-08-11 15:45:58 +0000281
Georg Brandl07e56812008-03-21 20:21:46 +0000282
Brett Cannone5d2cba2008-05-06 23:23:34 +0000283class TestStdlibRemovals(unittest.TestCase):
284
Brett Cannon3c759142008-05-09 05:25:37 +0000285 # test.testall not tested as it executes all unit tests as an
286 # import side-effect.
Brett Cannon4c1f8812008-05-10 02:27:04 +0000287 all_platforms = ('audiodev', 'imputil', 'mutex', 'user', 'new', 'rexec',
Brett Cannon1e8fba72008-07-18 19:30:22 +0000288 'Bastion', 'compiler', 'dircache', 'mimetools',
289 'fpformat', 'ihooks', 'mhlib', 'statvfs', 'htmllib',
290 'sgmllib', 'rfc822', 'sunaudio')
Brett Cannon54c77aa2008-05-14 21:08:41 +0000291 inclusive_platforms = {'irix' : ('pure', 'AL', 'al', 'CD', 'cd', 'cddb',
Brett Cannon044616a2008-05-15 02:33:55 +0000292 'cdplayer', 'CL', 'cl', 'DEVICE', 'GL',
Brett Cannon75ba4652008-05-15 03:23:17 +0000293 'gl', 'ERRNO', 'FILE', 'FL', 'flp', 'fl',
Brett Cannond8c41ec2008-05-15 03:41:55 +0000294 'fm', 'GET', 'GLWS', 'imgfile', 'IN',
Brett Cannoncd2de082008-05-15 03:51:21 +0000295 'IOCTL', 'jpeg', 'panel', 'panelparser',
Brett Cannon74a596c2008-05-15 04:17:35 +0000296 'readcd', 'SV', 'torgb', 'WAIT'),
Benjamin Peterson23681932008-05-12 21:42:13 +0000297 'darwin' : ('autoGIL', 'Carbon', 'OSATerminology',
Brett Cannonea785fb2008-05-14 01:09:40 +0000298 'icglue', 'Nav', 'MacOS', 'aepack',
299 'aetools', 'aetypes', 'applesingle',
300 'appletrawmain', 'appletrunner',
301 'argvemulator', 'bgenlocations',
Benjamin Peterson23681932008-05-12 21:42:13 +0000302 'EasyDialogs', 'macerrors', 'macostools',
303 'findertools', 'FrameWork', 'ic',
304 'gensuitemodule', 'icopen', 'macresource',
305 'MiniAEFrame', 'pimp', 'PixMapWrapper',
Brett Cannonea785fb2008-05-14 01:09:40 +0000306 'terminalcommand', 'videoreader',
307 '_builtinSuites', 'CodeWarrior',
308 'Explorer', 'Finder', 'Netscape',
309 'StdSuites', 'SystemEvents', 'Terminal',
310 'cfmfile', 'bundlebuilder', 'buildtools',
Benjamin Petersona6864e02008-07-14 17:42:17 +0000311 'ColorPicker', 'Audio_mac'),
Brett Cannon22248172008-05-16 00:10:24 +0000312 'sunos5' : ('sunaudiodev', 'SUNAUDIODEV'),
313 }
Brett Cannonac861b52008-05-12 03:45:59 +0000314 optional_modules = ('bsddb185', 'Canvas', 'dl', 'linuxaudiodev', 'imageop',
Brett Cannon32476fc2008-09-05 18:33:51 +0000315 'sv', 'cPickle', 'bsddb', 'dbhash')
Brett Cannone5d2cba2008-05-06 23:23:34 +0000316
Brett Cannon9ac39742008-05-09 22:51:58 +0000317 def check_removal(self, module_name, optional=False):
Brett Cannone5d2cba2008-05-06 23:23:34 +0000318 """Make sure the specified module, when imported, raises a
319 DeprecationWarning and specifies itself in the message."""
Brett Cannon672237d2008-09-09 00:49:16 +0000320 with nested(CleanImport(module_name), warnings.catch_warnings()):
Nick Coghland2e09382008-09-11 12:11:06 +0000321 # XXX: This is not quite enough for extension modules - those
322 # won't rerun their init code even with CleanImport.
323 # You can see this easily by running the whole test suite with -3
Benjamin Petersona6864e02008-07-14 17:42:17 +0000324 warnings.filterwarnings("error", ".+ removed",
325 DeprecationWarning, __name__)
326 try:
327 __import__(module_name, level=0)
328 except DeprecationWarning as exc:
Benjamin Peterson5c8da862009-06-30 22:57:08 +0000329 self.assertTrue(module_name in exc.args[0],
Benjamin Petersona6864e02008-07-14 17:42:17 +0000330 "%s warning didn't contain module name"
331 % module_name)
332 except ImportError:
333 if not optional:
334 self.fail("Non-optional module {0} raised an "
335 "ImportError.".format(module_name))
336 else:
337 self.fail("DeprecationWarning not raised for {0}"
338 .format(module_name))
Brett Cannone5d2cba2008-05-06 23:23:34 +0000339
340 def test_platform_independent_removals(self):
341 # Make sure that the modules that are available on all platforms raise
342 # the proper DeprecationWarning.
343 for module_name in self.all_platforms:
344 self.check_removal(module_name)
345
Brett Cannon9ac39742008-05-09 22:51:58 +0000346 def test_platform_specific_removals(self):
347 # Test the removal of platform-specific modules.
348 for module_name in self.inclusive_platforms.get(sys.platform, []):
349 self.check_removal(module_name, optional=True)
350
Brett Cannon768d44f2008-05-10 02:47:54 +0000351 def test_optional_module_removals(self):
352 # Test the removal of modules that may or may not be built.
353 for module_name in self.optional_modules:
354 self.check_removal(module_name, optional=True)
355
Benjamin Peterson0893a0a2008-05-09 00:27:01 +0000356 def test_os_path_walk(self):
357 msg = "In 3.x, os.path.walk is removed in favor of os.walk."
358 def dumbo(where, names, args): pass
359 for path_mod in ("ntpath", "macpath", "os2emxpath", "posixpath"):
360 mod = __import__(path_mod)
Nick Coghland2e09382008-09-11 12:11:06 +0000361 reset_module_registry(mod)
362 with check_warnings() as w:
Benjamin Peterson1d310232008-05-27 01:42:29 +0000363 mod.walk("crashers", dumbo, None)
Nick Coghland2e09382008-09-11 12:11:06 +0000364 self.assertEquals(str(w.message), msg)
Benjamin Peterson0893a0a2008-05-09 00:27:01 +0000365
Benjamin Peterson541f7da2008-08-18 02:12:23 +0000366 def test_reduce_move(self):
367 from operator import add
Nick Coghland2e09382008-09-11 12:11:06 +0000368 # reduce tests may have already triggered this warning
369 reset_module_registry(unittest)
Brett Cannon672237d2008-09-09 00:49:16 +0000370 with warnings.catch_warnings():
Benjamin Peterson541f7da2008-08-18 02:12:23 +0000371 warnings.filterwarnings("error", "reduce")
372 self.assertRaises(DeprecationWarning, reduce, add, range(10))
373
Brett Cannonabb34fe2008-05-29 05:08:50 +0000374 def test_mutablestring_removal(self):
375 # UserString.MutableString has been removed in 3.0.
376 import UserString
Nick Coghland2e09382008-09-11 12:11:06 +0000377 # UserString tests may have already triggered this warning
378 reset_module_registry(UserString)
Brett Cannon672237d2008-09-09 00:49:16 +0000379 with warnings.catch_warnings():
Brett Cannonabb34fe2008-05-29 05:08:50 +0000380 warnings.filterwarnings("error", ".*MutableString",
381 DeprecationWarning)
382 self.assertRaises(DeprecationWarning, UserString.MutableString)
383
Brett Cannone5d2cba2008-05-06 23:23:34 +0000384
Steven Bethardae42f332008-03-18 17:26:10 +0000385def test_main():
Nick Coghland2e09382008-09-11 12:11:06 +0000386 with check_warnings():
Benjamin Peterson1d310232008-05-27 01:42:29 +0000387 warnings.simplefilter("always")
388 run_unittest(TestPy3KWarnings,
389 TestStdlibRemovals)
Steven Bethardae42f332008-03-18 17:26:10 +0000390
391if __name__ == '__main__':
392 test_main()