blob: c695daacf4a7da764a377118c8e8badbad4658b0 [file] [log] [blame]
Steven Bethardae42f332008-03-18 17:26:10 +00001import unittest
Brett Cannon977eb022008-03-19 17:37:43 +00002import sys
Nick Coghland2e09382008-09-11 12:11:06 +00003from test.test_support import (check_warnings, CleanImport,
4 TestSkipped, run_unittest)
Steven Bethardae42f332008-03-18 17:26:10 +00005import warnings
6
Benjamin Petersona6864e02008-07-14 17:42:17 +00007from contextlib import nested
8
Brett Cannon977eb022008-03-19 17:37:43 +00009if not sys.py3kwarning:
10 raise TestSkipped('%s must be run with the -3 flag' % __name__)
11
Nick Coghland2e09382008-09-11 12:11:06 +000012def reset_module_registry(module):
13 try:
14 registry = module.__warningregistry__
15 except AttributeError:
16 pass
17 else:
18 registry.clear()
Steven Bethardae42f332008-03-18 17:26:10 +000019
20class TestPy3KWarnings(unittest.TestCase):
21
Nick Coghlan48361f52008-08-11 15:45:58 +000022 def assertWarning(self, _, warning, expected_message):
Nick Coghland2e09382008-09-11 12:11:06 +000023 self.assertEqual(str(warning.message), expected_message)
Nick Coghlan48361f52008-08-11 15:45:58 +000024
Benjamin Peterson2fe3ef82008-06-08 02:05:33 +000025 def test_backquote(self):
26 expected = 'backquote not supported in 3.x; use repr()'
Nick Coghland2e09382008-09-11 12:11:06 +000027 with check_warnings() as w:
Benjamin Peterson2fe3ef82008-06-08 02:05:33 +000028 exec "`2`" in {}
29 self.assertWarning(None, w, expected)
30
Benjamin Peterson399b1fe2008-10-25 02:53:28 +000031 def test_forbidden_names(self):
Benjamin Petersond5efd202008-06-08 22:52:37 +000032 # So we don't screw up our globals
33 def safe_exec(expr):
34 def f(**kwargs): pass
35 exec expr in {'f' : f}
36
Benjamin Peterson399b1fe2008-10-25 02:53:28 +000037 tests = [("True", "assignment to True or False is forbidden in 3.x"),
38 ("False", "assignment to True or False is forbidden in 3.x"),
39 ("nonlocal", "nonlocal is a keyword in 3.x")]
Nick Coghland2e09382008-09-11 12:11:06 +000040 with check_warnings() as w:
Benjamin Peterson399b1fe2008-10-25 02:53:28 +000041 for keyword, expected in tests:
42 safe_exec("{0} = False".format(keyword))
43 self.assertWarning(None, w, expected)
44 w.reset()
45 try:
46 safe_exec("obj.{0} = True".format(keyword))
47 except NameError:
48 pass
49 self.assertWarning(None, w, expected)
50 w.reset()
51 safe_exec("def {0}(): pass".format(keyword))
52 self.assertWarning(None, w, expected)
53 w.reset()
54 safe_exec("class {0}: pass".format(keyword))
55 self.assertWarning(None, w, expected)
56 w.reset()
57 safe_exec("def f({0}=43): pass".format(keyword))
58 self.assertWarning(None, w, expected)
59 w.reset()
Benjamin Petersond5efd202008-06-08 22:52:37 +000060
61
Steven Bethardae42f332008-03-18 17:26:10 +000062 def test_type_inequality_comparisons(self):
Georg Brandld5b635f2008-03-25 08:29:14 +000063 expected = 'type inequality comparisons not supported in 3.x'
Nick Coghland2e09382008-09-11 12:11:06 +000064 with check_warnings() as w:
Steven Bethardae42f332008-03-18 17:26:10 +000065 self.assertWarning(int < str, w, expected)
Nick Coghland2e09382008-09-11 12:11:06 +000066 w.reset()
Steven Bethardae42f332008-03-18 17:26:10 +000067 self.assertWarning(type < object, w, expected)
68
69 def test_object_inequality_comparisons(self):
Georg Brandld5b635f2008-03-25 08:29:14 +000070 expected = 'comparing unequal types not supported in 3.x'
Nick Coghland2e09382008-09-11 12:11:06 +000071 with check_warnings() as w:
Steven Bethardae42f332008-03-18 17:26:10 +000072 self.assertWarning(str < [], w, expected)
Nick Coghland2e09382008-09-11 12:11:06 +000073 w.reset()
Steven Bethardae42f332008-03-18 17:26:10 +000074 self.assertWarning(object() < (1, 2), w, expected)
75
76 def test_dict_inequality_comparisons(self):
Georg Brandld5b635f2008-03-25 08:29:14 +000077 expected = 'dict inequality comparisons not supported in 3.x'
Nick Coghland2e09382008-09-11 12:11:06 +000078 with check_warnings() as w:
Steven Bethardae42f332008-03-18 17:26:10 +000079 self.assertWarning({} < {2:3}, w, expected)
Nick Coghland2e09382008-09-11 12:11:06 +000080 w.reset()
Steven Bethardae42f332008-03-18 17:26:10 +000081 self.assertWarning({} <= {}, w, expected)
Nick Coghland2e09382008-09-11 12:11:06 +000082 w.reset()
Steven Bethardae42f332008-03-18 17:26:10 +000083 self.assertWarning({} > {2:3}, 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)
86
87 def test_cell_inequality_comparisons(self):
Georg Brandld5b635f2008-03-25 08:29:14 +000088 expected = 'cell comparisons not supported in 3.x'
Steven Bethardae42f332008-03-18 17:26:10 +000089 def f(x):
90 def g():
91 return x
92 return g
93 cell0, = f(0).func_closure
94 cell1, = f(1).func_closure
Nick Coghland2e09382008-09-11 12:11:06 +000095 with check_warnings() as w:
Steven Bethardae42f332008-03-18 17:26:10 +000096 self.assertWarning(cell0 == cell1, w, expected)
Nick Coghland2e09382008-09-11 12:11:06 +000097 w.reset()
Steven Bethardae42f332008-03-18 17:26:10 +000098 self.assertWarning(cell0 < cell1, w, expected)
99
Steven Bethard6a644f92008-03-18 22:08:20 +0000100 def test_code_inequality_comparisons(self):
Georg Brandld5b635f2008-03-25 08:29:14 +0000101 expected = 'code inequality comparisons not supported in 3.x'
Steven Bethard6a644f92008-03-18 22:08:20 +0000102 def f(x):
103 pass
104 def g(x):
105 pass
Nick Coghland2e09382008-09-11 12:11:06 +0000106 with check_warnings() as w:
Steven Bethard6a644f92008-03-18 22:08:20 +0000107 self.assertWarning(f.func_code < g.func_code, w, expected)
Nick Coghland2e09382008-09-11 12:11:06 +0000108 w.reset()
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)
114
115 def test_builtin_function_or_method_comparisons(self):
116 expected = ('builtin_function_or_method '
Georg Brandld5b635f2008-03-25 08:29:14 +0000117 'inequality comparisons not supported in 3.x')
Steven Bethard6a644f92008-03-18 22:08:20 +0000118 func = eval
119 meth = {}.get
Nick Coghland2e09382008-09-11 12:11:06 +0000120 with check_warnings() as w:
Steven Bethard6a644f92008-03-18 22:08:20 +0000121 self.assertWarning(func < meth, w, expected)
Nick Coghland2e09382008-09-11 12:11:06 +0000122 w.reset()
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(meth <= func, 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)
128
Raymond Hettinger05387862008-03-19 17:45:19 +0000129 def test_sort_cmp_arg(self):
Georg Brandld5b635f2008-03-25 08:29:14 +0000130 expected = "the cmp argument is not supported in 3.x"
Raymond Hettinger05387862008-03-19 17:45:19 +0000131 lst = range(5)
132 cmp = lambda x,y: -1
133
Nick Coghland2e09382008-09-11 12:11:06 +0000134 with check_warnings() as w:
Raymond Hettinger05387862008-03-19 17:45:19 +0000135 self.assertWarning(lst.sort(cmp=cmp), w, expected)
Nick Coghland2e09382008-09-11 12:11:06 +0000136 w.reset()
Raymond Hettinger05387862008-03-19 17:45:19 +0000137 self.assertWarning(sorted(lst, cmp=cmp), w, expected)
Nick Coghland2e09382008-09-11 12:11:06 +0000138 w.reset()
Raymond Hettinger05387862008-03-19 17:45:19 +0000139 self.assertWarning(lst.sort(cmp), w, expected)
Nick Coghland2e09382008-09-11 12:11:06 +0000140 w.reset()
Raymond Hettinger05387862008-03-19 17:45:19 +0000141 self.assertWarning(sorted(lst, cmp), w, expected)
142
Georg Brandl5a444242008-03-21 20:11:46 +0000143 def test_sys_exc_clear(self):
Georg Brandld5b635f2008-03-25 08:29:14 +0000144 expected = 'sys.exc_clear() not supported in 3.x; use except clauses'
Nick Coghland2e09382008-09-11 12:11:06 +0000145 with check_warnings() as w:
Georg Brandl5a444242008-03-21 20:11:46 +0000146 self.assertWarning(sys.exc_clear(), w, expected)
147
Georg Brandl07e56812008-03-21 20:21:46 +0000148 def test_methods_members(self):
149 expected = '__members__ and __methods__ not supported in 3.x'
150 class C:
151 __methods__ = ['a']
152 __members__ = ['b']
153 c = C()
Nick Coghland2e09382008-09-11 12:11:06 +0000154 with check_warnings() as w:
Georg Brandl07e56812008-03-21 20:21:46 +0000155 self.assertWarning(dir(c), w, expected)
156
Georg Brandl65bb42d2008-03-21 20:38:24 +0000157 def test_softspace(self):
158 expected = 'file.softspace not supported in 3.x'
159 with file(__file__) as f:
Nick Coghland2e09382008-09-11 12:11:06 +0000160 with check_warnings() as w:
Georg Brandl65bb42d2008-03-21 20:38:24 +0000161 self.assertWarning(f.softspace, w, expected)
162 def set():
163 f.softspace = 0
Nick Coghland2e09382008-09-11 12:11:06 +0000164 with check_warnings() as w:
Georg Brandl65bb42d2008-03-21 20:38:24 +0000165 self.assertWarning(set(), w, expected)
166
Benjamin Peterson712ee922008-08-24 18:10:20 +0000167 def test_slice_methods(self):
168 class Spam(object):
169 def __getslice__(self, i, j): pass
170 def __setslice__(self, i, j, what): pass
171 def __delslice__(self, i, j): pass
172 class Egg:
173 def __getslice__(self, i, h): pass
174 def __setslice__(self, i, j, what): pass
175 def __delslice__(self, i, j): pass
176
177 expected = "in 3.x, __{0}slice__ has been removed; use __{0}item__"
178
179 for obj in (Spam(), Egg()):
Nick Coghland2e09382008-09-11 12:11:06 +0000180 with check_warnings() as w:
Benjamin Peterson712ee922008-08-24 18:10:20 +0000181 self.assertWarning(obj[1:2], w, expected.format('get'))
Nick Coghland2e09382008-09-11 12:11:06 +0000182 w.reset()
Benjamin Peterson712ee922008-08-24 18:10:20 +0000183 del obj[3:4]
184 self.assertWarning(None, w, expected.format('del'))
Nick Coghland2e09382008-09-11 12:11:06 +0000185 w.reset()
Benjamin Peterson712ee922008-08-24 18:10:20 +0000186 obj[4:5] = "eggs"
187 self.assertWarning(None, w, expected.format('set'))
188
Benjamin Petersonf4fcdb62008-06-08 23:00:00 +0000189 def test_tuple_parameter_unpacking(self):
190 expected = "tuple parameter unpacking has been removed in 3.x"
Nick Coghland2e09382008-09-11 12:11:06 +0000191 with check_warnings() as w:
Benjamin Petersonf4fcdb62008-06-08 23:00:00 +0000192 exec "def f((a, b)): pass"
193 self.assertWarning(None, w, expected)
194
Georg Brandl80055f62008-03-25 07:56:27 +0000195 def test_buffer(self):
Nick Coghlan48361f52008-08-11 15:45:58 +0000196 expected = 'buffer() not supported in 3.x'
Nick Coghland2e09382008-09-11 12:11:06 +0000197 with check_warnings() as w:
Georg Brandl80055f62008-03-25 07:56:27 +0000198 self.assertWarning(buffer('a'), w, expected)
199
Georg Brandla9916b52008-05-17 22:11:54 +0000200 def test_file_xreadlines(self):
201 expected = ("f.xreadlines() not supported in 3.x, "
202 "try 'for line in f' instead")
203 with file(__file__) as f:
Nick Coghland2e09382008-09-11 12:11:06 +0000204 with check_warnings() as w:
Georg Brandla9916b52008-05-17 22:11:54 +0000205 self.assertWarning(f.xreadlines(), w, expected)
206
Nick Coghlan48361f52008-08-11 15:45:58 +0000207 def test_hash_inheritance(self):
Nick Coghland2e09382008-09-11 12:11:06 +0000208 with check_warnings() as w:
Nick Coghlan48361f52008-08-11 15:45:58 +0000209 # With object as the base class
210 class WarnOnlyCmp(object):
211 def __cmp__(self, other): pass
Nick Coghland2e09382008-09-11 12:11:06 +0000212 self.assertEqual(len(w.warnings), 1)
Nick Coghlan48361f52008-08-11 15:45:58 +0000213 self.assertWarning(None, w,
214 "Overriding __cmp__ blocks inheritance of __hash__ in 3.x")
Nick Coghland2e09382008-09-11 12:11:06 +0000215 w.reset()
Nick Coghlan48361f52008-08-11 15:45:58 +0000216 class WarnOnlyEq(object):
217 def __eq__(self, other): pass
Nick Coghland2e09382008-09-11 12:11:06 +0000218 self.assertEqual(len(w.warnings), 1)
Nick Coghlan48361f52008-08-11 15:45:58 +0000219 self.assertWarning(None, w,
220 "Overriding __eq__ blocks inheritance of __hash__ in 3.x")
Nick Coghland2e09382008-09-11 12:11:06 +0000221 w.reset()
Nick Coghlan48361f52008-08-11 15:45:58 +0000222 class WarnCmpAndEq(object):
223 def __cmp__(self, other): pass
224 def __eq__(self, other): pass
Nick Coghland2e09382008-09-11 12:11:06 +0000225 self.assertEqual(len(w.warnings), 2)
226 self.assertWarning(None, w.warnings[0],
Nick Coghlan48361f52008-08-11 15:45:58 +0000227 "Overriding __cmp__ blocks inheritance of __hash__ in 3.x")
228 self.assertWarning(None, w,
229 "Overriding __eq__ blocks inheritance of __hash__ in 3.x")
Nick Coghland2e09382008-09-11 12:11:06 +0000230 w.reset()
Nick Coghlan48361f52008-08-11 15:45:58 +0000231 class NoWarningOnlyHash(object):
232 def __hash__(self): pass
Nick Coghland2e09382008-09-11 12:11:06 +0000233 self.assertEqual(len(w.warnings), 0)
Nick Coghlan48361f52008-08-11 15:45:58 +0000234 # With an intermediate class in the heirarchy
235 class DefinesAllThree(object):
236 def __cmp__(self, other): pass
237 def __eq__(self, other): pass
238 def __hash__(self): pass
239 class WarnOnlyCmp(DefinesAllThree):
240 def __cmp__(self, other): pass
Nick Coghland2e09382008-09-11 12:11:06 +0000241 self.assertEqual(len(w.warnings), 1)
Nick Coghlan48361f52008-08-11 15:45:58 +0000242 self.assertWarning(None, w,
243 "Overriding __cmp__ blocks inheritance of __hash__ in 3.x")
Nick Coghland2e09382008-09-11 12:11:06 +0000244 w.reset()
Nick Coghlan48361f52008-08-11 15:45:58 +0000245 class WarnOnlyEq(DefinesAllThree):
246 def __eq__(self, other): pass
Nick Coghland2e09382008-09-11 12:11:06 +0000247 self.assertEqual(len(w.warnings), 1)
Nick Coghlan48361f52008-08-11 15:45:58 +0000248 self.assertWarning(None, w,
249 "Overriding __eq__ blocks inheritance of __hash__ in 3.x")
Nick Coghland2e09382008-09-11 12:11:06 +0000250 w.reset()
Nick Coghlan48361f52008-08-11 15:45:58 +0000251 class WarnCmpAndEq(DefinesAllThree):
252 def __cmp__(self, other): pass
253 def __eq__(self, other): pass
Nick Coghland2e09382008-09-11 12:11:06 +0000254 self.assertEqual(len(w.warnings), 2)
255 self.assertWarning(None, w.warnings[0],
Nick Coghlan48361f52008-08-11 15:45:58 +0000256 "Overriding __cmp__ blocks inheritance of __hash__ in 3.x")
257 self.assertWarning(None, w,
258 "Overriding __eq__ blocks inheritance of __hash__ in 3.x")
Nick Coghland2e09382008-09-11 12:11:06 +0000259 w.reset()
Nick Coghlan48361f52008-08-11 15:45:58 +0000260 class NoWarningOnlyHash(DefinesAllThree):
261 def __hash__(self): pass
Nick Coghland2e09382008-09-11 12:11:06 +0000262 self.assertEqual(len(w.warnings), 0)
Nick Coghlan48361f52008-08-11 15:45:58 +0000263
Georg Brandl07e56812008-03-21 20:21:46 +0000264
Brett Cannone5d2cba2008-05-06 23:23:34 +0000265class TestStdlibRemovals(unittest.TestCase):
266
Brett Cannon3c759142008-05-09 05:25:37 +0000267 # test.testall not tested as it executes all unit tests as an
268 # import side-effect.
Brett Cannon4c1f8812008-05-10 02:27:04 +0000269 all_platforms = ('audiodev', 'imputil', 'mutex', 'user', 'new', 'rexec',
Brett Cannon1e8fba72008-07-18 19:30:22 +0000270 'Bastion', 'compiler', 'dircache', 'mimetools',
271 'fpformat', 'ihooks', 'mhlib', 'statvfs', 'htmllib',
272 'sgmllib', 'rfc822', 'sunaudio')
Brett Cannon54c77aa2008-05-14 21:08:41 +0000273 inclusive_platforms = {'irix' : ('pure', 'AL', 'al', 'CD', 'cd', 'cddb',
Brett Cannon044616a2008-05-15 02:33:55 +0000274 'cdplayer', 'CL', 'cl', 'DEVICE', 'GL',
Brett Cannon75ba4652008-05-15 03:23:17 +0000275 'gl', 'ERRNO', 'FILE', 'FL', 'flp', 'fl',
Brett Cannond8c41ec2008-05-15 03:41:55 +0000276 'fm', 'GET', 'GLWS', 'imgfile', 'IN',
Brett Cannoncd2de082008-05-15 03:51:21 +0000277 'IOCTL', 'jpeg', 'panel', 'panelparser',
Brett Cannon74a596c2008-05-15 04:17:35 +0000278 'readcd', 'SV', 'torgb', 'WAIT'),
Benjamin Peterson23681932008-05-12 21:42:13 +0000279 'darwin' : ('autoGIL', 'Carbon', 'OSATerminology',
Brett Cannonea785fb2008-05-14 01:09:40 +0000280 'icglue', 'Nav', 'MacOS', 'aepack',
281 'aetools', 'aetypes', 'applesingle',
282 'appletrawmain', 'appletrunner',
283 'argvemulator', 'bgenlocations',
Benjamin Peterson23681932008-05-12 21:42:13 +0000284 'EasyDialogs', 'macerrors', 'macostools',
285 'findertools', 'FrameWork', 'ic',
286 'gensuitemodule', 'icopen', 'macresource',
287 'MiniAEFrame', 'pimp', 'PixMapWrapper',
Brett Cannonea785fb2008-05-14 01:09:40 +0000288 'terminalcommand', 'videoreader',
289 '_builtinSuites', 'CodeWarrior',
290 'Explorer', 'Finder', 'Netscape',
291 'StdSuites', 'SystemEvents', 'Terminal',
292 'cfmfile', 'bundlebuilder', 'buildtools',
Benjamin Petersona6864e02008-07-14 17:42:17 +0000293 'ColorPicker', 'Audio_mac'),
Brett Cannon22248172008-05-16 00:10:24 +0000294 'sunos5' : ('sunaudiodev', 'SUNAUDIODEV'),
295 }
Brett Cannonac861b52008-05-12 03:45:59 +0000296 optional_modules = ('bsddb185', 'Canvas', 'dl', 'linuxaudiodev', 'imageop',
Brett Cannon32476fc2008-09-05 18:33:51 +0000297 'sv', 'cPickle', 'bsddb', 'dbhash')
Brett Cannone5d2cba2008-05-06 23:23:34 +0000298
Brett Cannon9ac39742008-05-09 22:51:58 +0000299 def check_removal(self, module_name, optional=False):
Brett Cannone5d2cba2008-05-06 23:23:34 +0000300 """Make sure the specified module, when imported, raises a
301 DeprecationWarning and specifies itself in the message."""
Brett Cannon672237d2008-09-09 00:49:16 +0000302 with nested(CleanImport(module_name), warnings.catch_warnings()):
Nick Coghland2e09382008-09-11 12:11:06 +0000303 # XXX: This is not quite enough for extension modules - those
304 # won't rerun their init code even with CleanImport.
305 # You can see this easily by running the whole test suite with -3
Benjamin Petersona6864e02008-07-14 17:42:17 +0000306 warnings.filterwarnings("error", ".+ removed",
307 DeprecationWarning, __name__)
308 try:
309 __import__(module_name, level=0)
310 except DeprecationWarning as exc:
311 self.assert_(module_name in exc.args[0],
312 "%s warning didn't contain module name"
313 % module_name)
314 except ImportError:
315 if not optional:
316 self.fail("Non-optional module {0} raised an "
317 "ImportError.".format(module_name))
318 else:
319 self.fail("DeprecationWarning not raised for {0}"
320 .format(module_name))
Brett Cannone5d2cba2008-05-06 23:23:34 +0000321
322 def test_platform_independent_removals(self):
323 # Make sure that the modules that are available on all platforms raise
324 # the proper DeprecationWarning.
325 for module_name in self.all_platforms:
326 self.check_removal(module_name)
327
Brett Cannon9ac39742008-05-09 22:51:58 +0000328 def test_platform_specific_removals(self):
329 # Test the removal of platform-specific modules.
330 for module_name in self.inclusive_platforms.get(sys.platform, []):
331 self.check_removal(module_name, optional=True)
332
Brett Cannon768d44f2008-05-10 02:47:54 +0000333 def test_optional_module_removals(self):
334 # Test the removal of modules that may or may not be built.
335 for module_name in self.optional_modules:
336 self.check_removal(module_name, optional=True)
337
Benjamin Peterson0893a0a2008-05-09 00:27:01 +0000338 def test_os_path_walk(self):
339 msg = "In 3.x, os.path.walk is removed in favor of os.walk."
340 def dumbo(where, names, args): pass
341 for path_mod in ("ntpath", "macpath", "os2emxpath", "posixpath"):
342 mod = __import__(path_mod)
Nick Coghland2e09382008-09-11 12:11:06 +0000343 reset_module_registry(mod)
344 with check_warnings() as w:
Benjamin Peterson1d310232008-05-27 01:42:29 +0000345 mod.walk("crashers", dumbo, None)
Nick Coghland2e09382008-09-11 12:11:06 +0000346 self.assertEquals(str(w.message), msg)
Benjamin Peterson0893a0a2008-05-09 00:27:01 +0000347
Benjamin Peterson3aa84a72008-05-26 19:41:53 +0000348 def test_commands_members(self):
349 import commands
Nick Coghland2e09382008-09-11 12:11:06 +0000350 # commands module tests may have already triggered this warning
351 reset_module_registry(commands)
Benjamin Peterson3aa84a72008-05-26 19:41:53 +0000352 members = {"mk2arg" : 2, "mkarg" : 1, "getstatus" : 1}
353 for name, arg_count in members.items():
Brett Cannon672237d2008-09-09 00:49:16 +0000354 with warnings.catch_warnings():
Benjamin Peterson3aa84a72008-05-26 19:41:53 +0000355 warnings.filterwarnings("error")
356 func = getattr(commands, name)
357 self.assertRaises(DeprecationWarning, func, *([None]*arg_count))
358
Benjamin Peterson541f7da2008-08-18 02:12:23 +0000359 def test_reduce_move(self):
360 from operator import add
Nick Coghland2e09382008-09-11 12:11:06 +0000361 # reduce tests may have already triggered this warning
362 reset_module_registry(unittest)
Brett Cannon672237d2008-09-09 00:49:16 +0000363 with warnings.catch_warnings():
Benjamin Peterson541f7da2008-08-18 02:12:23 +0000364 warnings.filterwarnings("error", "reduce")
365 self.assertRaises(DeprecationWarning, reduce, add, range(10))
366
Brett Cannonabb34fe2008-05-29 05:08:50 +0000367 def test_mutablestring_removal(self):
368 # UserString.MutableString has been removed in 3.0.
369 import UserString
Nick Coghland2e09382008-09-11 12:11:06 +0000370 # UserString tests may have already triggered this warning
371 reset_module_registry(UserString)
Brett Cannon672237d2008-09-09 00:49:16 +0000372 with warnings.catch_warnings():
Brett Cannonabb34fe2008-05-29 05:08:50 +0000373 warnings.filterwarnings("error", ".*MutableString",
374 DeprecationWarning)
375 self.assertRaises(DeprecationWarning, UserString.MutableString)
376
Brett Cannone5d2cba2008-05-06 23:23:34 +0000377
Steven Bethardae42f332008-03-18 17:26:10 +0000378def test_main():
Nick Coghland2e09382008-09-11 12:11:06 +0000379 with check_warnings():
Benjamin Peterson1d310232008-05-27 01:42:29 +0000380 warnings.simplefilter("always")
381 run_unittest(TestPy3KWarnings,
382 TestStdlibRemovals)
Steven Bethardae42f332008-03-18 17:26:10 +0000383
384if __name__ == '__main__':
385 test_main()