blob: aa1ecbb588bebd80b0fba62bbd626c113e59faed [file] [log] [blame]
Steven Bethardae42f332008-03-18 17:26:10 +00001import unittest
Brett Cannon977eb022008-03-19 17:37:43 +00002import sys
Brett Cannon672237d2008-09-09 00:49:16 +00003from test.test_support import CleanImport, TestSkipped, 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:
9 raise TestSkipped('%s must be run with the -3 flag' % __name__)
10
Steven Bethardae42f332008-03-18 17:26:10 +000011
12class TestPy3KWarnings(unittest.TestCase):
13
Nick Coghlan48361f52008-08-11 15:45:58 +000014 def assertWarning(self, _, warning, expected_message):
Brett Cannon672237d2008-09-09 00:49:16 +000015 self.assertEqual(str(warning[-1].message), expected_message)
Nick Coghlan48361f52008-08-11 15:45:58 +000016
Benjamin Peterson2fe3ef82008-06-08 02:05:33 +000017 def test_backquote(self):
18 expected = 'backquote not supported in 3.x; use repr()'
Brett Cannon672237d2008-09-09 00:49:16 +000019 with warnings.catch_warnings(record=True) as w:
Benjamin Peterson2fe3ef82008-06-08 02:05:33 +000020 exec "`2`" in {}
21 self.assertWarning(None, w, expected)
22
Benjamin Petersond5efd202008-06-08 22:52:37 +000023 def test_bool_assign(self):
24 # So we don't screw up our globals
25 def safe_exec(expr):
26 def f(**kwargs): pass
27 exec expr in {'f' : f}
28
29 expected = "assignment to True or False is forbidden in 3.x"
Brett Cannon672237d2008-09-09 00:49:16 +000030 with warnings.catch_warnings(record=True) as w:
Benjamin Petersond5efd202008-06-08 22:52:37 +000031 safe_exec("True = False")
32 self.assertWarning(None, w, expected)
Benjamin Petersond5efd202008-06-08 22:52:37 +000033 safe_exec("False = True")
34 self.assertWarning(None, w, expected)
Benjamin Petersond5efd202008-06-08 22:52:37 +000035 try:
36 safe_exec("obj.False = True")
37 except NameError: pass
38 self.assertWarning(None, w, expected)
Benjamin Petersond5efd202008-06-08 22:52:37 +000039 try:
40 safe_exec("obj.True = False")
41 except NameError: pass
42 self.assertWarning(None, w, expected)
Benjamin Petersond5efd202008-06-08 22:52:37 +000043 safe_exec("def False(): pass")
44 self.assertWarning(None, w, expected)
Benjamin Petersond5efd202008-06-08 22:52:37 +000045 safe_exec("def True(): pass")
46 self.assertWarning(None, w, expected)
Benjamin Petersond5efd202008-06-08 22:52:37 +000047 safe_exec("class False: pass")
48 self.assertWarning(None, w, expected)
Benjamin Petersond5efd202008-06-08 22:52:37 +000049 safe_exec("class True: pass")
50 self.assertWarning(None, w, expected)
Benjamin Petersond5efd202008-06-08 22:52:37 +000051 safe_exec("def f(True=43): pass")
52 self.assertWarning(None, w, expected)
Benjamin Petersond5efd202008-06-08 22:52:37 +000053 safe_exec("def f(False=None): pass")
54 self.assertWarning(None, w, expected)
Benjamin Petersond5efd202008-06-08 22:52:37 +000055 safe_exec("f(False=True)")
56 self.assertWarning(None, w, expected)
Benjamin Petersond5efd202008-06-08 22:52:37 +000057 safe_exec("f(True=1)")
58 self.assertWarning(None, w, expected)
59
60
Steven Bethardae42f332008-03-18 17:26:10 +000061 def test_type_inequality_comparisons(self):
Georg Brandld5b635f2008-03-25 08:29:14 +000062 expected = 'type inequality comparisons not supported in 3.x'
Brett Cannon672237d2008-09-09 00:49:16 +000063 with warnings.catch_warnings(record=True) as w:
Steven Bethardae42f332008-03-18 17:26:10 +000064 self.assertWarning(int < str, w, expected)
Steven Bethardae42f332008-03-18 17:26:10 +000065 self.assertWarning(type < object, w, expected)
66
67 def test_object_inequality_comparisons(self):
Georg Brandld5b635f2008-03-25 08:29:14 +000068 expected = 'comparing unequal types not supported in 3.x'
Brett Cannon672237d2008-09-09 00:49:16 +000069 with warnings.catch_warnings(record=True) as w:
Steven Bethardae42f332008-03-18 17:26:10 +000070 self.assertWarning(str < [], w, expected)
Steven Bethardae42f332008-03-18 17:26:10 +000071 self.assertWarning(object() < (1, 2), w, expected)
72
73 def test_dict_inequality_comparisons(self):
Georg Brandld5b635f2008-03-25 08:29:14 +000074 expected = 'dict inequality comparisons not supported in 3.x'
Brett Cannon672237d2008-09-09 00:49:16 +000075 with warnings.catch_warnings(record=True) as w:
Steven Bethardae42f332008-03-18 17:26:10 +000076 self.assertWarning({} < {2:3}, w, expected)
Steven Bethardae42f332008-03-18 17:26:10 +000077 self.assertWarning({} <= {}, w, expected)
Steven Bethardae42f332008-03-18 17:26:10 +000078 self.assertWarning({} > {2:3}, w, expected)
Steven Bethardae42f332008-03-18 17:26:10 +000079 self.assertWarning({2:3} >= {}, w, expected)
80
81 def test_cell_inequality_comparisons(self):
Georg Brandld5b635f2008-03-25 08:29:14 +000082 expected = 'cell comparisons not supported in 3.x'
Steven Bethardae42f332008-03-18 17:26:10 +000083 def f(x):
84 def g():
85 return x
86 return g
87 cell0, = f(0).func_closure
88 cell1, = f(1).func_closure
Brett Cannon672237d2008-09-09 00:49:16 +000089 with warnings.catch_warnings(record=True) as w:
Steven Bethardae42f332008-03-18 17:26:10 +000090 self.assertWarning(cell0 == cell1, w, expected)
Steven Bethardae42f332008-03-18 17:26:10 +000091 self.assertWarning(cell0 < cell1, w, expected)
92
Steven Bethard6a644f92008-03-18 22:08:20 +000093 def test_code_inequality_comparisons(self):
Georg Brandld5b635f2008-03-25 08:29:14 +000094 expected = 'code inequality comparisons not supported in 3.x'
Steven Bethard6a644f92008-03-18 22:08:20 +000095 def f(x):
96 pass
97 def g(x):
98 pass
Brett Cannon672237d2008-09-09 00:49:16 +000099 with warnings.catch_warnings(record=True) as w:
Steven Bethard6a644f92008-03-18 22:08:20 +0000100 self.assertWarning(f.func_code < g.func_code, w, expected)
Steven Bethard6a644f92008-03-18 22:08:20 +0000101 self.assertWarning(f.func_code <= g.func_code, w, expected)
Steven Bethard6a644f92008-03-18 22:08:20 +0000102 self.assertWarning(f.func_code >= g.func_code, w, expected)
Steven Bethard6a644f92008-03-18 22:08:20 +0000103 self.assertWarning(f.func_code > g.func_code, w, expected)
104
105 def test_builtin_function_or_method_comparisons(self):
106 expected = ('builtin_function_or_method '
Georg Brandld5b635f2008-03-25 08:29:14 +0000107 'inequality comparisons not supported in 3.x')
Steven Bethard6a644f92008-03-18 22:08:20 +0000108 func = eval
109 meth = {}.get
Brett Cannon672237d2008-09-09 00:49:16 +0000110 with warnings.catch_warnings(record=True) as w:
Steven Bethard6a644f92008-03-18 22:08:20 +0000111 self.assertWarning(func < meth, w, expected)
Steven Bethard6a644f92008-03-18 22:08:20 +0000112 self.assertWarning(func > meth, w, expected)
Steven Bethard6a644f92008-03-18 22:08:20 +0000113 self.assertWarning(meth <= func, w, expected)
Steven Bethard6a644f92008-03-18 22:08:20 +0000114 self.assertWarning(meth >= func, w, expected)
115
Raymond Hettinger05387862008-03-19 17:45:19 +0000116 def test_sort_cmp_arg(self):
Georg Brandld5b635f2008-03-25 08:29:14 +0000117 expected = "the cmp argument is not supported in 3.x"
Raymond Hettinger05387862008-03-19 17:45:19 +0000118 lst = range(5)
119 cmp = lambda x,y: -1
120
Brett Cannon672237d2008-09-09 00:49:16 +0000121 with warnings.catch_warnings(record=True) as w:
Raymond Hettinger05387862008-03-19 17:45:19 +0000122 self.assertWarning(lst.sort(cmp=cmp), w, expected)
Raymond Hettinger05387862008-03-19 17:45:19 +0000123 self.assertWarning(sorted(lst, cmp=cmp), w, expected)
Raymond Hettinger05387862008-03-19 17:45:19 +0000124 self.assertWarning(lst.sort(cmp), w, expected)
Raymond Hettinger05387862008-03-19 17:45:19 +0000125 self.assertWarning(sorted(lst, cmp), w, expected)
126
Georg Brandl5a444242008-03-21 20:11:46 +0000127 def test_sys_exc_clear(self):
Georg Brandld5b635f2008-03-25 08:29:14 +0000128 expected = 'sys.exc_clear() not supported in 3.x; use except clauses'
Brett Cannon672237d2008-09-09 00:49:16 +0000129 with warnings.catch_warnings(record=True) as w:
Georg Brandl5a444242008-03-21 20:11:46 +0000130 self.assertWarning(sys.exc_clear(), w, expected)
131
Georg Brandl07e56812008-03-21 20:21:46 +0000132 def test_methods_members(self):
133 expected = '__members__ and __methods__ not supported in 3.x'
134 class C:
135 __methods__ = ['a']
136 __members__ = ['b']
137 c = C()
Brett Cannon672237d2008-09-09 00:49:16 +0000138 with warnings.catch_warnings(record=True) as w:
Georg Brandl07e56812008-03-21 20:21:46 +0000139 self.assertWarning(dir(c), w, expected)
140
Georg Brandl65bb42d2008-03-21 20:38:24 +0000141 def test_softspace(self):
142 expected = 'file.softspace not supported in 3.x'
143 with file(__file__) as f:
Brett Cannon672237d2008-09-09 00:49:16 +0000144 with warnings.catch_warnings(record=True) as w:
Georg Brandl65bb42d2008-03-21 20:38:24 +0000145 self.assertWarning(f.softspace, w, expected)
146 def set():
147 f.softspace = 0
Brett Cannon672237d2008-09-09 00:49:16 +0000148 with warnings.catch_warnings(record=True) as w:
Georg Brandl65bb42d2008-03-21 20:38:24 +0000149 self.assertWarning(set(), w, expected)
150
Benjamin Peterson712ee922008-08-24 18:10:20 +0000151 def test_slice_methods(self):
152 class Spam(object):
153 def __getslice__(self, i, j): pass
154 def __setslice__(self, i, j, what): pass
155 def __delslice__(self, i, j): pass
156 class Egg:
157 def __getslice__(self, i, h): pass
158 def __setslice__(self, i, j, what): pass
159 def __delslice__(self, i, j): pass
160
161 expected = "in 3.x, __{0}slice__ has been removed; use __{0}item__"
162
163 for obj in (Spam(), Egg()):
Brett Cannon672237d2008-09-09 00:49:16 +0000164 with warnings.catch_warnings(record=True) as w:
Benjamin Peterson712ee922008-08-24 18:10:20 +0000165 self.assertWarning(obj[1:2], w, expected.format('get'))
Benjamin Peterson712ee922008-08-24 18:10:20 +0000166 del obj[3:4]
167 self.assertWarning(None, w, expected.format('del'))
Benjamin Peterson712ee922008-08-24 18:10:20 +0000168 obj[4:5] = "eggs"
169 self.assertWarning(None, w, expected.format('set'))
170
Benjamin Petersonf4fcdb62008-06-08 23:00:00 +0000171 def test_tuple_parameter_unpacking(self):
172 expected = "tuple parameter unpacking has been removed in 3.x"
Brett Cannon672237d2008-09-09 00:49:16 +0000173 with warnings.catch_warnings(record=True) as w:
Benjamin Petersonf4fcdb62008-06-08 23:00:00 +0000174 exec "def f((a, b)): pass"
175 self.assertWarning(None, w, expected)
176
Georg Brandl80055f62008-03-25 07:56:27 +0000177 def test_buffer(self):
Nick Coghlan48361f52008-08-11 15:45:58 +0000178 expected = 'buffer() not supported in 3.x'
Brett Cannon672237d2008-09-09 00:49:16 +0000179 with warnings.catch_warnings(record=True) as w:
Georg Brandl80055f62008-03-25 07:56:27 +0000180 self.assertWarning(buffer('a'), w, expected)
181
Georg Brandla9916b52008-05-17 22:11:54 +0000182 def test_file_xreadlines(self):
183 expected = ("f.xreadlines() not supported in 3.x, "
184 "try 'for line in f' instead")
185 with file(__file__) as f:
Brett Cannon672237d2008-09-09 00:49:16 +0000186 with warnings.catch_warnings(record=True) as w:
Georg Brandla9916b52008-05-17 22:11:54 +0000187 self.assertWarning(f.xreadlines(), w, expected)
188
Nick Coghlan48361f52008-08-11 15:45:58 +0000189 def test_hash_inheritance(self):
Brett Cannon672237d2008-09-09 00:49:16 +0000190 with warnings.catch_warnings(record=True) as w:
Nick Coghlan48361f52008-08-11 15:45:58 +0000191 # With object as the base class
192 class WarnOnlyCmp(object):
193 def __cmp__(self, other): pass
Brett Cannona0b74442008-09-03 22:45:11 +0000194 self.assertEqual(len(w), 1)
Nick Coghlan48361f52008-08-11 15:45:58 +0000195 self.assertWarning(None, w,
196 "Overriding __cmp__ blocks inheritance of __hash__ in 3.x")
Brett Cannon672237d2008-09-09 00:49:16 +0000197 del w[:]
Nick Coghlan48361f52008-08-11 15:45:58 +0000198 class WarnOnlyEq(object):
199 def __eq__(self, other): pass
Brett Cannona0b74442008-09-03 22:45:11 +0000200 self.assertEqual(len(w), 1)
Nick Coghlan48361f52008-08-11 15:45:58 +0000201 self.assertWarning(None, w,
202 "Overriding __eq__ blocks inheritance of __hash__ in 3.x")
Brett Cannon672237d2008-09-09 00:49:16 +0000203 del w[:]
Nick Coghlan48361f52008-08-11 15:45:58 +0000204 class WarnCmpAndEq(object):
205 def __cmp__(self, other): pass
206 def __eq__(self, other): pass
Brett Cannona0b74442008-09-03 22:45:11 +0000207 self.assertEqual(len(w), 2)
Brett Cannon672237d2008-09-09 00:49:16 +0000208 self.assertWarning(None, w[:1],
Nick Coghlan48361f52008-08-11 15:45:58 +0000209 "Overriding __cmp__ blocks inheritance of __hash__ in 3.x")
210 self.assertWarning(None, w,
211 "Overriding __eq__ blocks inheritance of __hash__ in 3.x")
Brett Cannon672237d2008-09-09 00:49:16 +0000212 del w[:]
Nick Coghlan48361f52008-08-11 15:45:58 +0000213 class NoWarningOnlyHash(object):
214 def __hash__(self): pass
Brett Cannona0b74442008-09-03 22:45:11 +0000215 self.assertEqual(len(w), 0)
Brett Cannon672237d2008-09-09 00:49:16 +0000216 del w[:]
Nick Coghlan48361f52008-08-11 15:45:58 +0000217 # With an intermediate class in the heirarchy
218 class DefinesAllThree(object):
219 def __cmp__(self, other): pass
220 def __eq__(self, other): pass
221 def __hash__(self): pass
222 class WarnOnlyCmp(DefinesAllThree):
223 def __cmp__(self, other): pass
Brett Cannona0b74442008-09-03 22:45:11 +0000224 self.assertEqual(len(w), 1)
Nick Coghlan48361f52008-08-11 15:45:58 +0000225 self.assertWarning(None, w,
226 "Overriding __cmp__ blocks inheritance of __hash__ in 3.x")
Brett Cannon672237d2008-09-09 00:49:16 +0000227 del w[:]
Nick Coghlan48361f52008-08-11 15:45:58 +0000228 class WarnOnlyEq(DefinesAllThree):
229 def __eq__(self, other): pass
Brett Cannona0b74442008-09-03 22:45:11 +0000230 self.assertEqual(len(w), 1)
Nick Coghlan48361f52008-08-11 15:45:58 +0000231 self.assertWarning(None, w,
232 "Overriding __eq__ blocks inheritance of __hash__ in 3.x")
Brett Cannon672237d2008-09-09 00:49:16 +0000233 del w[:]
Nick Coghlan48361f52008-08-11 15:45:58 +0000234 class WarnCmpAndEq(DefinesAllThree):
235 def __cmp__(self, other): pass
236 def __eq__(self, other): pass
Brett Cannona0b74442008-09-03 22:45:11 +0000237 self.assertEqual(len(w), 2)
Brett Cannon672237d2008-09-09 00:49:16 +0000238 self.assertWarning(None, w[:1],
Nick Coghlan48361f52008-08-11 15:45:58 +0000239 "Overriding __cmp__ blocks inheritance of __hash__ in 3.x")
240 self.assertWarning(None, w,
241 "Overriding __eq__ blocks inheritance of __hash__ in 3.x")
Brett Cannon672237d2008-09-09 00:49:16 +0000242 del w[:]
Nick Coghlan48361f52008-08-11 15:45:58 +0000243 class NoWarningOnlyHash(DefinesAllThree):
244 def __hash__(self): pass
Brett Cannona0b74442008-09-03 22:45:11 +0000245 self.assertEqual(len(w), 0)
Nick Coghlan48361f52008-08-11 15:45:58 +0000246
Georg Brandl07e56812008-03-21 20:21:46 +0000247
Brett Cannone5d2cba2008-05-06 23:23:34 +0000248class TestStdlibRemovals(unittest.TestCase):
249
Brett Cannon3c759142008-05-09 05:25:37 +0000250 # test.testall not tested as it executes all unit tests as an
251 # import side-effect.
Brett Cannon4c1f8812008-05-10 02:27:04 +0000252 all_platforms = ('audiodev', 'imputil', 'mutex', 'user', 'new', 'rexec',
Brett Cannon1e8fba72008-07-18 19:30:22 +0000253 'Bastion', 'compiler', 'dircache', 'mimetools',
254 'fpformat', 'ihooks', 'mhlib', 'statvfs', 'htmllib',
255 'sgmllib', 'rfc822', 'sunaudio')
Brett Cannon54c77aa2008-05-14 21:08:41 +0000256 inclusive_platforms = {'irix' : ('pure', 'AL', 'al', 'CD', 'cd', 'cddb',
Brett Cannon044616a2008-05-15 02:33:55 +0000257 'cdplayer', 'CL', 'cl', 'DEVICE', 'GL',
Brett Cannon75ba4652008-05-15 03:23:17 +0000258 'gl', 'ERRNO', 'FILE', 'FL', 'flp', 'fl',
Brett Cannond8c41ec2008-05-15 03:41:55 +0000259 'fm', 'GET', 'GLWS', 'imgfile', 'IN',
Brett Cannoncd2de082008-05-15 03:51:21 +0000260 'IOCTL', 'jpeg', 'panel', 'panelparser',
Brett Cannon74a596c2008-05-15 04:17:35 +0000261 'readcd', 'SV', 'torgb', 'WAIT'),
Benjamin Peterson23681932008-05-12 21:42:13 +0000262 'darwin' : ('autoGIL', 'Carbon', 'OSATerminology',
Brett Cannonea785fb2008-05-14 01:09:40 +0000263 'icglue', 'Nav', 'MacOS', 'aepack',
264 'aetools', 'aetypes', 'applesingle',
265 'appletrawmain', 'appletrunner',
266 'argvemulator', 'bgenlocations',
Benjamin Peterson23681932008-05-12 21:42:13 +0000267 'EasyDialogs', 'macerrors', 'macostools',
268 'findertools', 'FrameWork', 'ic',
269 'gensuitemodule', 'icopen', 'macresource',
270 'MiniAEFrame', 'pimp', 'PixMapWrapper',
Brett Cannonea785fb2008-05-14 01:09:40 +0000271 'terminalcommand', 'videoreader',
272 '_builtinSuites', 'CodeWarrior',
273 'Explorer', 'Finder', 'Netscape',
274 'StdSuites', 'SystemEvents', 'Terminal',
275 'cfmfile', 'bundlebuilder', 'buildtools',
Benjamin Petersona6864e02008-07-14 17:42:17 +0000276 'ColorPicker', 'Audio_mac'),
Brett Cannon22248172008-05-16 00:10:24 +0000277 'sunos5' : ('sunaudiodev', 'SUNAUDIODEV'),
278 }
Brett Cannonac861b52008-05-12 03:45:59 +0000279 optional_modules = ('bsddb185', 'Canvas', 'dl', 'linuxaudiodev', 'imageop',
Brett Cannon32476fc2008-09-05 18:33:51 +0000280 'sv', 'cPickle', 'bsddb', 'dbhash')
Brett Cannone5d2cba2008-05-06 23:23:34 +0000281
Brett Cannon9ac39742008-05-09 22:51:58 +0000282 def check_removal(self, module_name, optional=False):
Brett Cannone5d2cba2008-05-06 23:23:34 +0000283 """Make sure the specified module, when imported, raises a
284 DeprecationWarning and specifies itself in the message."""
Brett Cannon672237d2008-09-09 00:49:16 +0000285 with nested(CleanImport(module_name), warnings.catch_warnings()):
Benjamin Petersona6864e02008-07-14 17:42:17 +0000286 warnings.filterwarnings("error", ".+ removed",
287 DeprecationWarning, __name__)
288 try:
289 __import__(module_name, level=0)
290 except DeprecationWarning as exc:
291 self.assert_(module_name in exc.args[0],
292 "%s warning didn't contain module name"
293 % module_name)
294 except ImportError:
295 if not optional:
296 self.fail("Non-optional module {0} raised an "
297 "ImportError.".format(module_name))
298 else:
299 self.fail("DeprecationWarning not raised for {0}"
300 .format(module_name))
Brett Cannone5d2cba2008-05-06 23:23:34 +0000301
302 def test_platform_independent_removals(self):
303 # Make sure that the modules that are available on all platforms raise
304 # the proper DeprecationWarning.
305 for module_name in self.all_platforms:
306 self.check_removal(module_name)
307
Brett Cannon9ac39742008-05-09 22:51:58 +0000308 def test_platform_specific_removals(self):
309 # Test the removal of platform-specific modules.
310 for module_name in self.inclusive_platforms.get(sys.platform, []):
311 self.check_removal(module_name, optional=True)
312
Brett Cannon768d44f2008-05-10 02:47:54 +0000313 def test_optional_module_removals(self):
314 # Test the removal of modules that may or may not be built.
315 for module_name in self.optional_modules:
316 self.check_removal(module_name, optional=True)
317
Benjamin Peterson0893a0a2008-05-09 00:27:01 +0000318 def test_os_path_walk(self):
319 msg = "In 3.x, os.path.walk is removed in favor of os.walk."
320 def dumbo(where, names, args): pass
321 for path_mod in ("ntpath", "macpath", "os2emxpath", "posixpath"):
322 mod = __import__(path_mod)
Brett Cannon672237d2008-09-09 00:49:16 +0000323 with warnings.catch_warnings(record=True) as w:
Benjamin Peterson1d310232008-05-27 01:42:29 +0000324 mod.walk("crashers", dumbo, None)
Brett Cannon672237d2008-09-09 00:49:16 +0000325 self.assertEquals(str(w[-1].message), msg)
Benjamin Peterson0893a0a2008-05-09 00:27:01 +0000326
Benjamin Peterson3aa84a72008-05-26 19:41:53 +0000327 def test_commands_members(self):
328 import commands
329 members = {"mk2arg" : 2, "mkarg" : 1, "getstatus" : 1}
330 for name, arg_count in members.items():
Brett Cannon672237d2008-09-09 00:49:16 +0000331 with warnings.catch_warnings():
Benjamin Peterson3aa84a72008-05-26 19:41:53 +0000332 warnings.filterwarnings("error")
333 func = getattr(commands, name)
334 self.assertRaises(DeprecationWarning, func, *([None]*arg_count))
335
Benjamin Peterson541f7da2008-08-18 02:12:23 +0000336 def test_reduce_move(self):
337 from operator import add
Brett Cannon672237d2008-09-09 00:49:16 +0000338 with warnings.catch_warnings():
Benjamin Peterson541f7da2008-08-18 02:12:23 +0000339 warnings.filterwarnings("error", "reduce")
340 self.assertRaises(DeprecationWarning, reduce, add, range(10))
341
Brett Cannonabb34fe2008-05-29 05:08:50 +0000342 def test_mutablestring_removal(self):
343 # UserString.MutableString has been removed in 3.0.
344 import UserString
Brett Cannon672237d2008-09-09 00:49:16 +0000345 with warnings.catch_warnings():
Brett Cannonabb34fe2008-05-29 05:08:50 +0000346 warnings.filterwarnings("error", ".*MutableString",
347 DeprecationWarning)
348 self.assertRaises(DeprecationWarning, UserString.MutableString)
349
Brett Cannone5d2cba2008-05-06 23:23:34 +0000350
Steven Bethardae42f332008-03-18 17:26:10 +0000351def test_main():
Brett Cannon672237d2008-09-09 00:49:16 +0000352 with warnings.catch_warnings():
Benjamin Peterson1d310232008-05-27 01:42:29 +0000353 warnings.simplefilter("always")
354 run_unittest(TestPy3KWarnings,
355 TestStdlibRemovals)
Steven Bethardae42f332008-03-18 17:26:10 +0000356
357if __name__ == '__main__':
358 test_main()