annotate Lib/test/test_py3kwarn.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents b36cb4602e21
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
45860
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
1 import unittest
45926
3bf19c31c956 Use sys.py3kwarning instead of trying to trigger a Py3k-related warning.
Brett Cannon <bcannon@gmail.com>
parents: 45899
diff changeset
2 import sys
59669
7df3e13d3e50 Cleanup some test cases using check_warnings and check_py3k_warnings.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59489
diff changeset
3 from test.test_support import check_py3k_warnings, CleanImport, run_unittest
45860
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
4 import warnings
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
5
45926
3bf19c31c956 Use sys.py3kwarning instead of trying to trigger a Py3k-related warning.
Brett Cannon <bcannon@gmail.com>
parents: 45899
diff changeset
6 if not sys.py3kwarning:
52355
228cfb6e2900 fix incorrect auto-translation of TestSkipped -> unittest.SkipTest
Benjamin Peterson <benjamin@python.org>
parents: 52353
diff changeset
7 raise unittest.SkipTest('%s must be run with the -3 flag' % __name__)
45926
3bf19c31c956 Use sys.py3kwarning instead of trying to trigger a Py3k-related warning.
Brett Cannon <bcannon@gmail.com>
parents: 45899
diff changeset
8
63612
29d34e4d0a9a Merged revisions 78815 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62111
diff changeset
9 try:
29d34e4d0a9a Merged revisions 78815 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62111
diff changeset
10 from test.test_support import __warningregistry__ as _registry
29d34e4d0a9a Merged revisions 78815 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62111
diff changeset
11 except ImportError:
29d34e4d0a9a Merged revisions 78815 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62111
diff changeset
12 def check_deprecated_module(module_name):
29d34e4d0a9a Merged revisions 78815 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62111
diff changeset
13 return False
29d34e4d0a9a Merged revisions 78815 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62111
diff changeset
14 else:
29d34e4d0a9a Merged revisions 78815 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62111
diff changeset
15 past_warnings = _registry.keys()
29d34e4d0a9a Merged revisions 78815 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62111
diff changeset
16 del _registry
29d34e4d0a9a Merged revisions 78815 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62111
diff changeset
17 def check_deprecated_module(module_name):
29d34e4d0a9a Merged revisions 78815 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62111
diff changeset
18 """Lookup the past warnings for module already loaded using
29d34e4d0a9a Merged revisions 78815 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62111
diff changeset
19 test_support.import_module(..., deprecated=True)
29d34e4d0a9a Merged revisions 78815 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62111
diff changeset
20 """
29d34e4d0a9a Merged revisions 78815 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62111
diff changeset
21 return any(module_name in msg and ' removed' in msg
29d34e4d0a9a Merged revisions 78815 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62111
diff changeset
22 and issubclass(cls, DeprecationWarning)
29d34e4d0a9a Merged revisions 78815 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62111
diff changeset
23 and (' module' in msg or ' package' in msg)
29d34e4d0a9a Merged revisions 78815 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62111
diff changeset
24 for (msg, cls, line) in past_warnings)
29d34e4d0a9a Merged revisions 78815 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62111
diff changeset
25
49146
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
26 def reset_module_registry(module):
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
27 try:
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
28 registry = module.__warningregistry__
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
29 except AttributeError:
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
30 pass
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
31 else:
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
32 registry.clear()
45860
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
33
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
34 class TestPy3KWarnings(unittest.TestCase):
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
35
48213
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
36 def assertWarning(self, _, warning, expected_message):
49146
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
37 self.assertEqual(str(warning.message), expected_message)
48213
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
38
55052
7dc0d2c4b520 Merged revisions 73774 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
39 def assertNoWarning(self, _, recorder):
7dc0d2c4b520 Merged revisions 73774 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
40 self.assertEqual(len(recorder.warnings), 0)
7dc0d2c4b520 Merged revisions 73774 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
41
47516
f3df51b60dc2 change Py3k backquote warning to a SyntaxWarning and add a test
Benjamin Peterson <benjamin@python.org>
parents: 47433
diff changeset
42 def test_backquote(self):
f3df51b60dc2 change Py3k backquote warning to a SyntaxWarning and add a test
Benjamin Peterson <benjamin@python.org>
parents: 47433
diff changeset
43 expected = 'backquote not supported in 3.x; use repr()'
59669
7df3e13d3e50 Cleanup some test cases using check_warnings and check_py3k_warnings.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59489
diff changeset
44 with check_py3k_warnings((expected, SyntaxWarning)):
47516
f3df51b60dc2 change Py3k backquote warning to a SyntaxWarning and add a test
Benjamin Peterson <benjamin@python.org>
parents: 47433
diff changeset
45 exec "`2`" in {}
f3df51b60dc2 change Py3k backquote warning to a SyntaxWarning and add a test
Benjamin Peterson <benjamin@python.org>
parents: 47433
diff changeset
46
57370
f9f3950b5ec7 Merged revisions 76416-76417 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 55052
diff changeset
47 def test_paren_arg_names(self):
f9f3950b5ec7 Merged revisions 76416-76417 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 55052
diff changeset
48 expected = 'parenthesized argument names are invalid in 3.x'
f9f3950b5ec7 Merged revisions 76416-76417 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 55052
diff changeset
49 def check(s):
59669
7df3e13d3e50 Cleanup some test cases using check_warnings and check_py3k_warnings.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59489
diff changeset
50 with check_py3k_warnings((expected, SyntaxWarning)):
7df3e13d3e50 Cleanup some test cases using check_warnings and check_py3k_warnings.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59489
diff changeset
51 exec s in {}
7df3e13d3e50 Cleanup some test cases using check_warnings and check_py3k_warnings.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59489
diff changeset
52 check("def f((x)): pass")
7df3e13d3e50 Cleanup some test cases using check_warnings and check_py3k_warnings.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59489
diff changeset
53 check("def f((((x))), (y)): pass")
7df3e13d3e50 Cleanup some test cases using check_warnings and check_py3k_warnings.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59489
diff changeset
54 check("def f((x), (((y))), m=32): pass")
7df3e13d3e50 Cleanup some test cases using check_warnings and check_py3k_warnings.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59489
diff changeset
55 # Something like def f((a, (b))): pass will raise the tuple
7df3e13d3e50 Cleanup some test cases using check_warnings and check_py3k_warnings.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59489
diff changeset
56 # unpacking warning.
57370
f9f3950b5ec7 Merged revisions 76416-76417 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 55052
diff changeset
57
49584
6634530a04e0 give a py3k warning when 'nonlocal' is used as a variable name
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
58 def test_forbidden_names(self):
47523
d56450db60a2 Warn about assigning to Py3k keywords (True and False)
Benjamin Peterson <benjamin@python.org>
parents: 47516
diff changeset
59 # So we don't screw up our globals
d56450db60a2 Warn about assigning to Py3k keywords (True and False)
Benjamin Peterson <benjamin@python.org>
parents: 47516
diff changeset
60 def safe_exec(expr):
d56450db60a2 Warn about assigning to Py3k keywords (True and False)
Benjamin Peterson <benjamin@python.org>
parents: 47516
diff changeset
61 def f(**kwargs): pass
d56450db60a2 Warn about assigning to Py3k keywords (True and False)
Benjamin Peterson <benjamin@python.org>
parents: 47516
diff changeset
62 exec expr in {'f' : f}
d56450db60a2 Warn about assigning to Py3k keywords (True and False)
Benjamin Peterson <benjamin@python.org>
parents: 47516
diff changeset
63
49584
6634530a04e0 give a py3k warning when 'nonlocal' is used as a variable name
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
64 tests = [("True", "assignment to True or False is forbidden in 3.x"),
6634530a04e0 give a py3k warning when 'nonlocal' is used as a variable name
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
65 ("False", "assignment to True or False is forbidden in 3.x"),
6634530a04e0 give a py3k warning when 'nonlocal' is used as a variable name
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
66 ("nonlocal", "nonlocal is a keyword in 3.x")]
59669
7df3e13d3e50 Cleanup some test cases using check_warnings and check_py3k_warnings.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59489
diff changeset
67 with check_py3k_warnings(('', SyntaxWarning)) as w:
49584
6634530a04e0 give a py3k warning when 'nonlocal' is used as a variable name
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
68 for keyword, expected in tests:
6634530a04e0 give a py3k warning when 'nonlocal' is used as a variable name
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
69 safe_exec("{0} = False".format(keyword))
6634530a04e0 give a py3k warning when 'nonlocal' is used as a variable name
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
70 self.assertWarning(None, w, expected)
6634530a04e0 give a py3k warning when 'nonlocal' is used as a variable name
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
71 w.reset()
6634530a04e0 give a py3k warning when 'nonlocal' is used as a variable name
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
72 try:
6634530a04e0 give a py3k warning when 'nonlocal' is used as a variable name
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
73 safe_exec("obj.{0} = True".format(keyword))
6634530a04e0 give a py3k warning when 'nonlocal' is used as a variable name
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
74 except NameError:
6634530a04e0 give a py3k warning when 'nonlocal' is used as a variable name
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
75 pass
6634530a04e0 give a py3k warning when 'nonlocal' is used as a variable name
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
76 self.assertWarning(None, w, expected)
6634530a04e0 give a py3k warning when 'nonlocal' is used as a variable name
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
77 w.reset()
6634530a04e0 give a py3k warning when 'nonlocal' is used as a variable name
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
78 safe_exec("def {0}(): pass".format(keyword))
6634530a04e0 give a py3k warning when 'nonlocal' is used as a variable name
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
79 self.assertWarning(None, w, expected)
6634530a04e0 give a py3k warning when 'nonlocal' is used as a variable name
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
80 w.reset()
6634530a04e0 give a py3k warning when 'nonlocal' is used as a variable name
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
81 safe_exec("class {0}: pass".format(keyword))
6634530a04e0 give a py3k warning when 'nonlocal' is used as a variable name
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
82 self.assertWarning(None, w, expected)
6634530a04e0 give a py3k warning when 'nonlocal' is used as a variable name
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
83 w.reset()
6634530a04e0 give a py3k warning when 'nonlocal' is used as a variable name
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
84 safe_exec("def f({0}=43): pass".format(keyword))
6634530a04e0 give a py3k warning when 'nonlocal' is used as a variable name
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
85 self.assertWarning(None, w, expected)
6634530a04e0 give a py3k warning when 'nonlocal' is used as a variable name
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
86 w.reset()
47523
d56450db60a2 Warn about assigning to Py3k keywords (True and False)
Benjamin Peterson <benjamin@python.org>
parents: 47516
diff changeset
87
d56450db60a2 Warn about assigning to Py3k keywords (True and False)
Benjamin Peterson <benjamin@python.org>
parents: 47516
diff changeset
88
45860
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
89 def test_type_inequality_comparisons(self):
46075
84bb7701efba Make Py3k warnings consistent w.r.t. punctuation; also respect the
Georg Brandl <georg@python.org>
parents: 46074
diff changeset
90 expected = 'type inequality comparisons not supported in 3.x'
59669
7df3e13d3e50 Cleanup some test cases using check_warnings and check_py3k_warnings.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59489
diff changeset
91 with check_py3k_warnings() as w:
45860
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
92 self.assertWarning(int < str, w, expected)
49146
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
93 w.reset()
45860
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
94 self.assertWarning(type < object, w, expected)
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
95
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
96 def test_object_inequality_comparisons(self):
46075
84bb7701efba Make Py3k warnings consistent w.r.t. punctuation; also respect the
Georg Brandl <georg@python.org>
parents: 46074
diff changeset
97 expected = 'comparing unequal types not supported in 3.x'
59669
7df3e13d3e50 Cleanup some test cases using check_warnings and check_py3k_warnings.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59489
diff changeset
98 with check_py3k_warnings() as w:
45860
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
99 self.assertWarning(str < [], w, expected)
49146
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
100 w.reset()
45860
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
101 self.assertWarning(object() < (1, 2), w, expected)
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
102
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
103 def test_dict_inequality_comparisons(self):
46075
84bb7701efba Make Py3k warnings consistent w.r.t. punctuation; also respect the
Georg Brandl <georg@python.org>
parents: 46074
diff changeset
104 expected = 'dict inequality comparisons not supported in 3.x'
59669
7df3e13d3e50 Cleanup some test cases using check_warnings and check_py3k_warnings.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59489
diff changeset
105 with check_py3k_warnings() as w:
45860
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
106 self.assertWarning({} < {2:3}, w, expected)
49146
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
107 w.reset()
45860
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
108 self.assertWarning({} <= {}, w, expected)
49146
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
109 w.reset()
45860
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
110 self.assertWarning({} > {2:3}, w, expected)
49146
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
111 w.reset()
45860
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
112 self.assertWarning({2:3} >= {}, w, expected)
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
113
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
114 def test_cell_inequality_comparisons(self):
46075
84bb7701efba Make Py3k warnings consistent w.r.t. punctuation; also respect the
Georg Brandl <georg@python.org>
parents: 46074
diff changeset
115 expected = 'cell comparisons not supported in 3.x'
45860
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
116 def f(x):
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
117 def g():
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
118 return x
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
119 return g
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
120 cell0, = f(0).func_closure
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
121 cell1, = f(1).func_closure
59669
7df3e13d3e50 Cleanup some test cases using check_warnings and check_py3k_warnings.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59489
diff changeset
122 with check_py3k_warnings() as w:
45860
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
123 self.assertWarning(cell0 == cell1, w, expected)
49146
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
124 w.reset()
45860
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
125 self.assertWarning(cell0 < cell1, w, expected)
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
126
45885
860e23a61e55 Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents: 45860
diff changeset
127 def test_code_inequality_comparisons(self):
46075
84bb7701efba Make Py3k warnings consistent w.r.t. punctuation; also respect the
Georg Brandl <georg@python.org>
parents: 46074
diff changeset
128 expected = 'code inequality comparisons not supported in 3.x'
45885
860e23a61e55 Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents: 45860
diff changeset
129 def f(x):
860e23a61e55 Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents: 45860
diff changeset
130 pass
860e23a61e55 Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents: 45860
diff changeset
131 def g(x):
860e23a61e55 Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents: 45860
diff changeset
132 pass
59669
7df3e13d3e50 Cleanup some test cases using check_warnings and check_py3k_warnings.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59489
diff changeset
133 with check_py3k_warnings() as w:
45885
860e23a61e55 Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents: 45860
diff changeset
134 self.assertWarning(f.func_code < g.func_code, w, expected)
49146
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
135 w.reset()
45885
860e23a61e55 Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents: 45860
diff changeset
136 self.assertWarning(f.func_code <= g.func_code, w, expected)
49146
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
137 w.reset()
45885
860e23a61e55 Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents: 45860
diff changeset
138 self.assertWarning(f.func_code >= g.func_code, w, expected)
49146
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
139 w.reset()
45885
860e23a61e55 Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents: 45860
diff changeset
140 self.assertWarning(f.func_code > g.func_code, w, expected)
860e23a61e55 Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents: 45860
diff changeset
141
860e23a61e55 Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents: 45860
diff changeset
142 def test_builtin_function_or_method_comparisons(self):
860e23a61e55 Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents: 45860
diff changeset
143 expected = ('builtin_function_or_method '
55052
7dc0d2c4b520 Merged revisions 73774 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
144 'order comparisons not supported in 3.x')
45885
860e23a61e55 Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents: 45860
diff changeset
145 func = eval
860e23a61e55 Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents: 45860
diff changeset
146 meth = {}.get
59669
7df3e13d3e50 Cleanup some test cases using check_warnings and check_py3k_warnings.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59489
diff changeset
147 with check_py3k_warnings() as w:
45885
860e23a61e55 Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents: 45860
diff changeset
148 self.assertWarning(func < meth, w, expected)
49146
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
149 w.reset()
45885
860e23a61e55 Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents: 45860
diff changeset
150 self.assertWarning(func > meth, w, expected)
49146
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
151 w.reset()
45885
860e23a61e55 Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents: 45860
diff changeset
152 self.assertWarning(meth <= func, w, expected)
49146
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
153 w.reset()
45885
860e23a61e55 Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents: 45860
diff changeset
154 self.assertWarning(meth >= func, w, expected)
55052
7dc0d2c4b520 Merged revisions 73774 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
155 w.reset()
7dc0d2c4b520 Merged revisions 73774 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
156 self.assertNoWarning(meth == func, w)
7dc0d2c4b520 Merged revisions 73774 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
157 self.assertNoWarning(meth != func, w)
7dc0d2c4b520 Merged revisions 73774 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
158 lam = lambda x: x
7dc0d2c4b520 Merged revisions 73774 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
159 self.assertNoWarning(lam == func, w)
7dc0d2c4b520 Merged revisions 73774 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49146
diff changeset
160 self.assertNoWarning(lam != func, w)
45885
860e23a61e55 Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Steven Bethard <steven.bethard@gmail.com>
parents: 45860
diff changeset
161
50259
d79fdd8420f3 add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents: 49584
diff changeset
162 def test_frame_attributes(self):
d79fdd8420f3 add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents: 49584
diff changeset
163 template = "%s has been removed in 3.x"
d79fdd8420f3 add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents: 49584
diff changeset
164 f = sys._getframe(0)
d79fdd8420f3 add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents: 49584
diff changeset
165 for attr in ("f_exc_traceback", "f_exc_value", "f_exc_type"):
d79fdd8420f3 add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents: 49584
diff changeset
166 expected = template % attr
59669
7df3e13d3e50 Cleanup some test cases using check_warnings and check_py3k_warnings.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59489
diff changeset
167 with check_py3k_warnings() as w:
50259
d79fdd8420f3 add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents: 49584
diff changeset
168 self.assertWarning(getattr(f, attr), w, expected)
d79fdd8420f3 add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents: 49584
diff changeset
169 w.reset()
d79fdd8420f3 add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents: 49584
diff changeset
170 self.assertWarning(setattr(f, attr, None), w, expected)
d79fdd8420f3 add py3k warnings to frame.f_exc_*
Benjamin Peterson <benjamin@python.org>
parents: 49584
diff changeset
171
45927
dc5be0b3c3be Issue 2354: Fix-up compare warning. Patch contributed by Jeff Balogh.
Raymond Hettinger <python@rcn.com>
parents: 45926
diff changeset
172 def test_sort_cmp_arg(self):
46075
84bb7701efba Make Py3k warnings consistent w.r.t. punctuation; also respect the
Georg Brandl <georg@python.org>
parents: 46074
diff changeset
173 expected = "the cmp argument is not supported in 3.x"
45927
dc5be0b3c3be Issue 2354: Fix-up compare warning. Patch contributed by Jeff Balogh.
Raymond Hettinger <python@rcn.com>
parents: 45926
diff changeset
174 lst = range(5)
dc5be0b3c3be Issue 2354: Fix-up compare warning. Patch contributed by Jeff Balogh.
Raymond Hettinger <python@rcn.com>
parents: 45926
diff changeset
175 cmp = lambda x,y: -1
dc5be0b3c3be Issue 2354: Fix-up compare warning. Patch contributed by Jeff Balogh.
Raymond Hettinger <python@rcn.com>
parents: 45926
diff changeset
176
59669
7df3e13d3e50 Cleanup some test cases using check_warnings and check_py3k_warnings.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59489
diff changeset
177 with check_py3k_warnings() as w:
45927
dc5be0b3c3be Issue 2354: Fix-up compare warning. Patch contributed by Jeff Balogh.
Raymond Hettinger <python@rcn.com>
parents: 45926
diff changeset
178 self.assertWarning(lst.sort(cmp=cmp), w, expected)
49146
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
179 w.reset()
45927
dc5be0b3c3be Issue 2354: Fix-up compare warning. Patch contributed by Jeff Balogh.
Raymond Hettinger <python@rcn.com>
parents: 45926
diff changeset
180 self.assertWarning(sorted(lst, cmp=cmp), w, expected)
49146
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
181 w.reset()
45927
dc5be0b3c3be Issue 2354: Fix-up compare warning. Patch contributed by Jeff Balogh.
Raymond Hettinger <python@rcn.com>
parents: 45926
diff changeset
182 self.assertWarning(lst.sort(cmp), w, expected)
49146
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
183 w.reset()
45927
dc5be0b3c3be Issue 2354: Fix-up compare warning. Patch contributed by Jeff Balogh.
Raymond Hettinger <python@rcn.com>
parents: 45926
diff changeset
184 self.assertWarning(sorted(lst, cmp), w, expected)
dc5be0b3c3be Issue 2354: Fix-up compare warning. Patch contributed by Jeff Balogh.
Raymond Hettinger <python@rcn.com>
parents: 45926
diff changeset
185
45983
99355baa748d #2358: add py3k warning to sys.exc_clear().
Georg Brandl <georg@python.org>
parents: 45928
diff changeset
186 def test_sys_exc_clear(self):
46075
84bb7701efba Make Py3k warnings consistent w.r.t. punctuation; also respect the
Georg Brandl <georg@python.org>
parents: 46074
diff changeset
187 expected = 'sys.exc_clear() not supported in 3.x; use except clauses'
59669
7df3e13d3e50 Cleanup some test cases using check_warnings and check_py3k_warnings.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59489
diff changeset
188 with check_py3k_warnings() as w:
45983
99355baa748d #2358: add py3k warning to sys.exc_clear().
Georg Brandl <georg@python.org>
parents: 45928
diff changeset
189 self.assertWarning(sys.exc_clear(), w, expected)
99355baa748d #2358: add py3k warning to sys.exc_clear().
Georg Brandl <georg@python.org>
parents: 45928
diff changeset
190
45984
2275612c16a9 #2346/#2347: add py3k warning for __methods__ and __members__. Patch by Jack Diederich.
Georg Brandl <georg@python.org>
parents: 45983
diff changeset
191 def test_methods_members(self):
2275612c16a9 #2346/#2347: add py3k warning for __methods__ and __members__. Patch by Jack Diederich.
Georg Brandl <georg@python.org>
parents: 45983
diff changeset
192 expected = '__members__ and __methods__ not supported in 3.x'
2275612c16a9 #2346/#2347: add py3k warning for __methods__ and __members__. Patch by Jack Diederich.
Georg Brandl <georg@python.org>
parents: 45983
diff changeset
193 class C:
2275612c16a9 #2346/#2347: add py3k warning for __methods__ and __members__. Patch by Jack Diederich.
Georg Brandl <georg@python.org>
parents: 45983
diff changeset
194 __methods__ = ['a']
2275612c16a9 #2346/#2347: add py3k warning for __methods__ and __members__. Patch by Jack Diederich.
Georg Brandl <georg@python.org>
parents: 45983
diff changeset
195 __members__ = ['b']
2275612c16a9 #2346/#2347: add py3k warning for __methods__ and __members__. Patch by Jack Diederich.
Georg Brandl <georg@python.org>
parents: 45983
diff changeset
196 c = C()
59669
7df3e13d3e50 Cleanup some test cases using check_warnings and check_py3k_warnings.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59489
diff changeset
197 with check_py3k_warnings() as w:
45984
2275612c16a9 #2346/#2347: add py3k warning for __methods__ and __members__. Patch by Jack Diederich.
Georg Brandl <georg@python.org>
parents: 45983
diff changeset
198 self.assertWarning(dir(c), w, expected)
2275612c16a9 #2346/#2347: add py3k warning for __methods__ and __members__. Patch by Jack Diederich.
Georg Brandl <georg@python.org>
parents: 45983
diff changeset
199
45985
bf07bad1d72f #2348: add py3k warning for file.softspace.
Georg Brandl <georg@python.org>
parents: 45984
diff changeset
200 def test_softspace(self):
bf07bad1d72f #2348: add py3k warning for file.softspace.
Georg Brandl <georg@python.org>
parents: 45984
diff changeset
201 expected = 'file.softspace not supported in 3.x'
bf07bad1d72f #2348: add py3k warning for file.softspace.
Georg Brandl <georg@python.org>
parents: 45984
diff changeset
202 with file(__file__) as f:
59669
7df3e13d3e50 Cleanup some test cases using check_warnings and check_py3k_warnings.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59489
diff changeset
203 with check_py3k_warnings() as w:
45985
bf07bad1d72f #2348: add py3k warning for file.softspace.
Georg Brandl <georg@python.org>
parents: 45984
diff changeset
204 self.assertWarning(f.softspace, w, expected)
bf07bad1d72f #2348: add py3k warning for file.softspace.
Georg Brandl <georg@python.org>
parents: 45984
diff changeset
205 def set():
bf07bad1d72f #2348: add py3k warning for file.softspace.
Georg Brandl <georg@python.org>
parents: 45984
diff changeset
206 f.softspace = 0
59669
7df3e13d3e50 Cleanup some test cases using check_warnings and check_py3k_warnings.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59489
diff changeset
207 with check_py3k_warnings() as w:
45985
bf07bad1d72f #2348: add py3k warning for file.softspace.
Georg Brandl <georg@python.org>
parents: 45984
diff changeset
208 self.assertWarning(set(), w, expected)
bf07bad1d72f #2348: add py3k warning for file.softspace.
Georg Brandl <georg@python.org>
parents: 45984
diff changeset
209
48854
6ea1a720b057 generate py3k warnings on __getslice__, __delslice__, and __setslice__
Benjamin Peterson <benjamin@python.org>
parents: 48295
diff changeset
210 def test_slice_methods(self):
6ea1a720b057 generate py3k warnings on __getslice__, __delslice__, and __setslice__
Benjamin Peterson <benjamin@python.org>
parents: 48295
diff changeset
211 class Spam(object):
6ea1a720b057 generate py3k warnings on __getslice__, __delslice__, and __setslice__
Benjamin Peterson <benjamin@python.org>
parents: 48295
diff changeset
212 def __getslice__(self, i, j): pass
6ea1a720b057 generate py3k warnings on __getslice__, __delslice__, and __setslice__
Benjamin Peterson <benjamin@python.org>
parents: 48295
diff changeset
213 def __setslice__(self, i, j, what): pass
6ea1a720b057 generate py3k warnings on __getslice__, __delslice__, and __setslice__
Benjamin Peterson <benjamin@python.org>
parents: 48295
diff changeset
214 def __delslice__(self, i, j): pass
6ea1a720b057 generate py3k warnings on __getslice__, __delslice__, and __setslice__
Benjamin Peterson <benjamin@python.org>
parents: 48295
diff changeset
215 class Egg:
6ea1a720b057 generate py3k warnings on __getslice__, __delslice__, and __setslice__
Benjamin Peterson <benjamin@python.org>
parents: 48295
diff changeset
216 def __getslice__(self, i, h): pass
6ea1a720b057 generate py3k warnings on __getslice__, __delslice__, and __setslice__
Benjamin Peterson <benjamin@python.org>
parents: 48295
diff changeset
217 def __setslice__(self, i, j, what): pass
6ea1a720b057 generate py3k warnings on __getslice__, __delslice__, and __setslice__
Benjamin Peterson <benjamin@python.org>
parents: 48295
diff changeset
218 def __delslice__(self, i, j): pass
6ea1a720b057 generate py3k warnings on __getslice__, __delslice__, and __setslice__
Benjamin Peterson <benjamin@python.org>
parents: 48295
diff changeset
219
6ea1a720b057 generate py3k warnings on __getslice__, __delslice__, and __setslice__
Benjamin Peterson <benjamin@python.org>
parents: 48295
diff changeset
220 expected = "in 3.x, __{0}slice__ has been removed; use __{0}item__"
6ea1a720b057 generate py3k warnings on __getslice__, __delslice__, and __setslice__
Benjamin Peterson <benjamin@python.org>
parents: 48295
diff changeset
221
6ea1a720b057 generate py3k warnings on __getslice__, __delslice__, and __setslice__
Benjamin Peterson <benjamin@python.org>
parents: 48295
diff changeset
222 for obj in (Spam(), Egg()):
59669
7df3e13d3e50 Cleanup some test cases using check_warnings and check_py3k_warnings.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59489
diff changeset
223 with check_py3k_warnings() as w:
48854
6ea1a720b057 generate py3k warnings on __getslice__, __delslice__, and __setslice__
Benjamin Peterson <benjamin@python.org>
parents: 48295
diff changeset
224 self.assertWarning(obj[1:2], w, expected.format('get'))
49146
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
225 w.reset()
48854
6ea1a720b057 generate py3k warnings on __getslice__, __delslice__, and __setslice__
Benjamin Peterson <benjamin@python.org>
parents: 48295
diff changeset
226 del obj[3:4]
6ea1a720b057 generate py3k warnings on __getslice__, __delslice__, and __setslice__
Benjamin Peterson <benjamin@python.org>
parents: 48295
diff changeset
227 self.assertWarning(None, w, expected.format('del'))
49146
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
228 w.reset()
48854
6ea1a720b057 generate py3k warnings on __getslice__, __delslice__, and __setslice__
Benjamin Peterson <benjamin@python.org>
parents: 48295
diff changeset
229 obj[4:5] = "eggs"
6ea1a720b057 generate py3k warnings on __getslice__, __delslice__, and __setslice__
Benjamin Peterson <benjamin@python.org>
parents: 48295
diff changeset
230 self.assertWarning(None, w, expected.format('set'))
6ea1a720b057 generate py3k warnings on __getslice__, __delslice__, and __setslice__
Benjamin Peterson <benjamin@python.org>
parents: 48295
diff changeset
231
47524
53253f36014e warn about parameter tuple unpacking
Benjamin Peterson <benjamin@python.org>
parents: 47523
diff changeset
232 def test_tuple_parameter_unpacking(self):
53253f36014e warn about parameter tuple unpacking
Benjamin Peterson <benjamin@python.org>
parents: 47523
diff changeset
233 expected = "tuple parameter unpacking has been removed in 3.x"
59669
7df3e13d3e50 Cleanup some test cases using check_warnings and check_py3k_warnings.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59489
diff changeset
234 with check_py3k_warnings((expected, SyntaxWarning)):
47524
53253f36014e warn about parameter tuple unpacking
Benjamin Peterson <benjamin@python.org>
parents: 47523
diff changeset
235 exec "def f((a, b)): pass"
53253f36014e warn about parameter tuple unpacking
Benjamin Peterson <benjamin@python.org>
parents: 47523
diff changeset
236
46074
9b3f0fa5d8ca #2355: py3k warning for buffer().
Georg Brandl <georg@python.org>
parents: 45985
diff changeset
237 def test_buffer(self):
48213
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
238 expected = 'buffer() not supported in 3.x'
59669
7df3e13d3e50 Cleanup some test cases using check_warnings and check_py3k_warnings.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59489
diff changeset
239 with check_py3k_warnings() as w:
46074
9b3f0fa5d8ca #2355: py3k warning for buffer().
Georg Brandl <georg@python.org>
parents: 45985
diff changeset
240 self.assertWarning(buffer('a'), w, expected)
9b3f0fa5d8ca #2355: py3k warning for buffer().
Georg Brandl <georg@python.org>
parents: 45985
diff changeset
241
47148
3d5cddc6e5e7 #2353: raise Py3k warning in file.xreadlines().
Georg Brandl <georg@python.org>
parents: 47141
diff changeset
242 def test_file_xreadlines(self):
3d5cddc6e5e7 #2353: raise Py3k warning in file.xreadlines().
Georg Brandl <georg@python.org>
parents: 47141
diff changeset
243 expected = ("f.xreadlines() not supported in 3.x, "
3d5cddc6e5e7 #2353: raise Py3k warning in file.xreadlines().
Georg Brandl <georg@python.org>
parents: 47141
diff changeset
244 "try 'for line in f' instead")
3d5cddc6e5e7 #2353: raise Py3k warning in file.xreadlines().
Georg Brandl <georg@python.org>
parents: 47141
diff changeset
245 with file(__file__) as f:
59669
7df3e13d3e50 Cleanup some test cases using check_warnings and check_py3k_warnings.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59489
diff changeset
246 with check_py3k_warnings() as w:
47148
3d5cddc6e5e7 #2353: raise Py3k warning in file.xreadlines().
Georg Brandl <georg@python.org>
parents: 47141
diff changeset
247 self.assertWarning(f.xreadlines(), w, expected)
3d5cddc6e5e7 #2353: raise Py3k warning in file.xreadlines().
Georg Brandl <georg@python.org>
parents: 47141
diff changeset
248
48213
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
249 def test_hash_inheritance(self):
59669
7df3e13d3e50 Cleanup some test cases using check_warnings and check_py3k_warnings.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59489
diff changeset
250 with check_py3k_warnings() as w:
48213
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
251 # With object as the base class
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
252 class WarnOnlyCmp(object):
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
253 def __cmp__(self, other): pass
62111
af2bde72ce61 Merged revisions 81749 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 58201
diff changeset
254 self.assertEqual(len(w.warnings), 0)
49146
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
255 w.reset()
48213
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
256 class WarnOnlyEq(object):
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
257 def __eq__(self, other): pass
49146
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
258 self.assertEqual(len(w.warnings), 1)
48213
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
259 self.assertWarning(None, w,
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
260 "Overriding __eq__ blocks inheritance of __hash__ in 3.x")
49146
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
261 w.reset()
48213
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
262 class WarnCmpAndEq(object):
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
263 def __cmp__(self, other): pass
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
264 def __eq__(self, other): pass
62111
af2bde72ce61 Merged revisions 81749 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 58201
diff changeset
265 self.assertEqual(len(w.warnings), 1)
48213
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
266 self.assertWarning(None, w,
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
267 "Overriding __eq__ blocks inheritance of __hash__ in 3.x")
49146
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
268 w.reset()
48213
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
269 class NoWarningOnlyHash(object):
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
270 def __hash__(self): pass
49146
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
271 self.assertEqual(len(w.warnings), 0)
48213
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
272 # With an intermediate class in the heirarchy
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
273 class DefinesAllThree(object):
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
274 def __cmp__(self, other): pass
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
275 def __eq__(self, other): pass
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
276 def __hash__(self): pass
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
277 class WarnOnlyCmp(DefinesAllThree):
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
278 def __cmp__(self, other): pass
62111
af2bde72ce61 Merged revisions 81749 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 58201
diff changeset
279 self.assertEqual(len(w.warnings), 0)
49146
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
280 w.reset()
48213
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
281 class WarnOnlyEq(DefinesAllThree):
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
282 def __eq__(self, other): pass
49146
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
283 self.assertEqual(len(w.warnings), 1)
48213
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
284 self.assertWarning(None, w,
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
285 "Overriding __eq__ blocks inheritance of __hash__ in 3.x")
49146
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
286 w.reset()
48213
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
287 class WarnCmpAndEq(DefinesAllThree):
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
288 def __cmp__(self, other): pass
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
289 def __eq__(self, other): pass
62111
af2bde72ce61 Merged revisions 81749 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 58201
diff changeset
290 self.assertEqual(len(w.warnings), 1)
48213
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
291 self.assertWarning(None, w,
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
292 "Overriding __eq__ blocks inheritance of __hash__ in 3.x")
49146
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
293 w.reset()
48213
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
294 class NoWarningOnlyHash(DefinesAllThree):
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
295 def __hash__(self): pass
49146
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
296 self.assertEqual(len(w.warnings), 0)
48213
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 48020
diff changeset
297
55111
466ca96be182 Issue 2370: Add Python 3 warnings for the removal of operator.isCallable and
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 55051
diff changeset
298 def test_operator(self):
466ca96be182 Issue 2370: Add Python 3 warnings for the removal of operator.isCallable and
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 55051
diff changeset
299 from operator import isCallable, sequenceIncludes
466ca96be182 Issue 2370: Add Python 3 warnings for the removal of operator.isCallable and
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 55051
diff changeset
300
55112
77ebeacc107a Fix bad variable name in r73846.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 55111
diff changeset
301 callable_warn = ("operator.isCallable() is not supported in 3.x. "
77ebeacc107a Fix bad variable name in r73846.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 55111
diff changeset
302 "Use hasattr(obj, '__call__').")
55111
466ca96be182 Issue 2370: Add Python 3 warnings for the removal of operator.isCallable and
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 55051
diff changeset
303 seq_warn = ("operator.sequenceIncludes() is not supported "
466ca96be182 Issue 2370: Add Python 3 warnings for the removal of operator.isCallable and
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 55051
diff changeset
304 "in 3.x. Use operator.contains().")
59669
7df3e13d3e50 Cleanup some test cases using check_warnings and check_py3k_warnings.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59489
diff changeset
305 with check_py3k_warnings() as w:
55111
466ca96be182 Issue 2370: Add Python 3 warnings for the removal of operator.isCallable and
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 55051
diff changeset
306 self.assertWarning(isCallable(self), w, callable_warn)
466ca96be182 Issue 2370: Add Python 3 warnings for the removal of operator.isCallable and
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 55051
diff changeset
307 w.reset()
466ca96be182 Issue 2370: Add Python 3 warnings for the removal of operator.isCallable and
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 55051
diff changeset
308 self.assertWarning(sequenceIncludes(range(3), 2), w, seq_warn)
466ca96be182 Issue 2370: Add Python 3 warnings for the removal of operator.isCallable and
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 55051
diff changeset
309
45984
2275612c16a9 #2346/#2347: add py3k warning for __methods__ and __members__. Patch by Jack Diederich.
Georg Brandl <georg@python.org>
parents: 45983
diff changeset
310
46702
ffdb5f4139fe Deprecate the audiodev module for 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 46075
diff changeset
311 class TestStdlibRemovals(unittest.TestCase):
ffdb5f4139fe Deprecate the audiodev module for 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 46075
diff changeset
312
46777
946fbae4baab Deprecate test.testall for removal in 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 46775
diff changeset
313 # test.testall not tested as it executes all unit tests as an
946fbae4baab Deprecate test.testall for removal in 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 46775
diff changeset
314 # import side-effect.
46811
5679ce66e74b Deprecate Bastion and rexec for 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 46807
diff changeset
315 all_platforms = ('audiodev', 'imputil', 'mutex', 'user', 'new', 'rexec',
48020
f9040d107d66 Deprecate the sunaudio module for removal in Python 3.0. The sunau module can provide similar functionality.
Brett Cannon <bcannon@gmail.com>
parents: 47958
diff changeset
316 'Bastion', 'compiler', 'dircache', 'mimetools',
f9040d107d66 Deprecate the sunaudio module for removal in Python 3.0. The sunau module can provide similar functionality.
Brett Cannon <bcannon@gmail.com>
parents: 47958
diff changeset
317 'fpformat', 'ihooks', 'mhlib', 'statvfs', 'htmllib',
f9040d107d66 Deprecate the sunaudio module for removal in Python 3.0. The sunau module can provide similar functionality.
Brett Cannon <bcannon@gmail.com>
parents: 47958
diff changeset
318 'sgmllib', 'rfc822', 'sunaudio')
47000
f2c4ab74cc65 Deprecate the cdplayer module for IRIX for 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 46997
diff changeset
319 inclusive_platforms = {'irix' : ('pure', 'AL', 'al', 'CD', 'cd', 'cddb',
47017
f0a47091c8d8 Deprecate DEVICE, GL, gl, and the related modules cgen and cgensupport for removal in 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 47006
diff changeset
320 'cdplayer', 'CL', 'cl', 'DEVICE', 'GL',
47025
62d9ec9c9efd Deprecated 'fm' for removal in 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 47023
diff changeset
321 'gl', 'ERRNO', 'FILE', 'FL', 'flp', 'fl',
47034
bada0e871ac1 Deprecate IOCTL from IRIX for removal in 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 47032
diff changeset
322 'fm', 'GET', 'GLWS', 'imgfile', 'IN',
47042
80435bc7aac4 Deprecate readcd for removal in 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 47038
diff changeset
323 'IOCTL', 'jpeg', 'panel', 'panelparser',
47048
ed532ca7ae75 Deprecate WAIT for removal in 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 47046
diff changeset
324 'readcd', 'SV', 'torgb', 'WAIT'),
46967
6df0394abbf1 Add warnings to and deprecated all those Mac modules
Benjamin Peterson <benjamin@python.org>
parents: 46936
diff changeset
325 'darwin' : ('autoGIL', 'Carbon', 'OSATerminology',
62435
5a325e0f1fd0 Fix for issue8446:
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 62110
diff changeset
326 'icglue', 'Nav',
5a325e0f1fd0 Fix for issue8446:
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 62110
diff changeset
327 # MacOS should (and does) give a Py3kWarning, but one of the
5a325e0f1fd0 Fix for issue8446:
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 62110
diff changeset
328 # earlier tests already imports the MacOS extension which causes
5a325e0f1fd0 Fix for issue8446:
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 62110
diff changeset
329 # this test to fail. Disabling the test for 'MacOS' avoids this
5a325e0f1fd0 Fix for issue8446:
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 62110
diff changeset
330 # spurious test failure.
5a325e0f1fd0 Fix for issue8446:
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 62110
diff changeset
331 #'MacOS',
5a325e0f1fd0 Fix for issue8446:
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 62110
diff changeset
332 'aepack',
46988
49038ee0e5b5 Rewrap some lines in test_py3kwarn.
Brett Cannon <bcannon@gmail.com>
parents: 46987
diff changeset
333 'aetools', 'aetypes', 'applesingle',
49038ee0e5b5 Rewrap some lines in test_py3kwarn.
Brett Cannon <bcannon@gmail.com>
parents: 46987
diff changeset
334 'appletrawmain', 'appletrunner',
49038ee0e5b5 Rewrap some lines in test_py3kwarn.
Brett Cannon <bcannon@gmail.com>
parents: 46987
diff changeset
335 'argvemulator', 'bgenlocations',
46967
6df0394abbf1 Add warnings to and deprecated all those Mac modules
Benjamin Peterson <benjamin@python.org>
parents: 46936
diff changeset
336 'EasyDialogs', 'macerrors', 'macostools',
6df0394abbf1 Add warnings to and deprecated all those Mac modules
Benjamin Peterson <benjamin@python.org>
parents: 46936
diff changeset
337 'findertools', 'FrameWork', 'ic',
6df0394abbf1 Add warnings to and deprecated all those Mac modules
Benjamin Peterson <benjamin@python.org>
parents: 46936
diff changeset
338 'gensuitemodule', 'icopen', 'macresource',
6df0394abbf1 Add warnings to and deprecated all those Mac modules
Benjamin Peterson <benjamin@python.org>
parents: 46936
diff changeset
339 'MiniAEFrame', 'pimp', 'PixMapWrapper',
46988
49038ee0e5b5 Rewrap some lines in test_py3kwarn.
Brett Cannon <bcannon@gmail.com>
parents: 46987
diff changeset
340 'terminalcommand', 'videoreader',
49038ee0e5b5 Rewrap some lines in test_py3kwarn.
Brett Cannon <bcannon@gmail.com>
parents: 46987
diff changeset
341 '_builtinSuites', 'CodeWarrior',
49038ee0e5b5 Rewrap some lines in test_py3kwarn.
Brett Cannon <bcannon@gmail.com>
parents: 46987
diff changeset
342 'Explorer', 'Finder', 'Netscape',
49038ee0e5b5 Rewrap some lines in test_py3kwarn.
Brett Cannon <bcannon@gmail.com>
parents: 46987
diff changeset
343 'StdSuites', 'SystemEvents', 'Terminal',
49038ee0e5b5 Rewrap some lines in test_py3kwarn.
Brett Cannon <bcannon@gmail.com>
parents: 46987
diff changeset
344 'cfmfile', 'bundlebuilder', 'buildtools',
47958
e7a6a4515ab0 fix test_py3kwarns
Benjamin Peterson <benjamin@python.org>
parents: 47942
diff changeset
345 'ColorPicker', 'Audio_mac'),
47068
ae16e94bb03a Deprecate sunaudiodev/SUNAUDIODEV for removal in 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 47048
diff changeset
346 'sunos5' : ('sunaudiodev', 'SUNAUDIODEV'),
ae16e94bb03a Deprecate sunaudiodev/SUNAUDIODEV for removal in 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 47048
diff changeset
347 }
46936
799321e7e7bb Deprecate the sv module as per PEP 4.
Brett Cannon <bcannon@gmail.com>
parents: 46928
diff changeset
348 optional_modules = ('bsddb185', 'Canvas', 'dl', 'linuxaudiodev', 'imageop',
58201
0c7ead034a03 Merged revisions 77370 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57370
diff changeset
349 'sv', 'bsddb', 'dbhash')
46702
ffdb5f4139fe Deprecate the audiodev module for 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 46075
diff changeset
350
46807
c56e83d08d0b Deprecate the pure module for 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 46777
diff changeset
351 def check_removal(self, module_name, optional=False):
46702
ffdb5f4139fe Deprecate the audiodev module for 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 46075
diff changeset
352 """Make sure the specified module, when imported, raises a
ffdb5f4139fe Deprecate the audiodev module for 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 46075
diff changeset
353 DeprecationWarning and specifies itself in the message."""
59489
269a12a50123 #7772: Fix test_py3kwarn. Now the test suite could pass with "-3" flag.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58460
diff changeset
354 with CleanImport(module_name), warnings.catch_warnings():
63612
29d34e4d0a9a Merged revisions 78815 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62111
diff changeset
355 warnings.filterwarnings("error", ".+ (module|package) .+ removed",
29d34e4d0a9a Merged revisions 78815 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62111
diff changeset
356 DeprecationWarning, __name__)
29d34e4d0a9a Merged revisions 78815 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62111
diff changeset
357 warnings.filterwarnings("error", ".+ removed .+ (module|package)",
47958
e7a6a4515ab0 fix test_py3kwarns
Benjamin Peterson <benjamin@python.org>
parents: 47942
diff changeset
358 DeprecationWarning, __name__)
e7a6a4515ab0 fix test_py3kwarns
Benjamin Peterson <benjamin@python.org>
parents: 47942
diff changeset
359 try:
e7a6a4515ab0 fix test_py3kwarns
Benjamin Peterson <benjamin@python.org>
parents: 47942
diff changeset
360 __import__(module_name, level=0)
e7a6a4515ab0 fix test_py3kwarns
Benjamin Peterson <benjamin@python.org>
parents: 47942
diff changeset
361 except DeprecationWarning as exc:
58460
17891566a478 use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58199
diff changeset
362 self.assertIn(module_name, exc.args[0],
17891566a478 use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58199
diff changeset
363 "%s warning didn't contain module name"
17891566a478 use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58199
diff changeset
364 % module_name)
47958
e7a6a4515ab0 fix test_py3kwarns
Benjamin Peterson <benjamin@python.org>
parents: 47942
diff changeset
365 except ImportError:
e7a6a4515ab0 fix test_py3kwarns
Benjamin Peterson <benjamin@python.org>
parents: 47942
diff changeset
366 if not optional:
e7a6a4515ab0 fix test_py3kwarns
Benjamin Peterson <benjamin@python.org>
parents: 47942
diff changeset
367 self.fail("Non-optional module {0} raised an "
e7a6a4515ab0 fix test_py3kwarns
Benjamin Peterson <benjamin@python.org>
parents: 47942
diff changeset
368 "ImportError.".format(module_name))
e7a6a4515ab0 fix test_py3kwarns
Benjamin Peterson <benjamin@python.org>
parents: 47942
diff changeset
369 else:
63612
29d34e4d0a9a Merged revisions 78815 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62111
diff changeset
370 # For extension modules, check the __warningregistry__.
29d34e4d0a9a Merged revisions 78815 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62111
diff changeset
371 # They won't rerun their init code even with CleanImport.
29d34e4d0a9a Merged revisions 78815 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62111
diff changeset
372 if not check_deprecated_module(module_name):
29d34e4d0a9a Merged revisions 78815 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62111
diff changeset
373 self.fail("DeprecationWarning not raised for {0}"
59489
269a12a50123 #7772: Fix test_py3kwarn. Now the test suite could pass with "-3" flag.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58460
diff changeset
374 .format(module_name))
46702
ffdb5f4139fe Deprecate the audiodev module for 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 46075
diff changeset
375
ffdb5f4139fe Deprecate the audiodev module for 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 46075
diff changeset
376 def test_platform_independent_removals(self):
ffdb5f4139fe Deprecate the audiodev module for 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 46075
diff changeset
377 # Make sure that the modules that are available on all platforms raise
ffdb5f4139fe Deprecate the audiodev module for 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 46075
diff changeset
378 # the proper DeprecationWarning.
ffdb5f4139fe Deprecate the audiodev module for 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 46075
diff changeset
379 for module_name in self.all_platforms:
ffdb5f4139fe Deprecate the audiodev module for 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 46075
diff changeset
380 self.check_removal(module_name)
ffdb5f4139fe Deprecate the audiodev module for 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 46075
diff changeset
381
46807
c56e83d08d0b Deprecate the pure module for 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 46777
diff changeset
382 def test_platform_specific_removals(self):
c56e83d08d0b Deprecate the pure module for 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 46777
diff changeset
383 # Test the removal of platform-specific modules.
c56e83d08d0b Deprecate the pure module for 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 46777
diff changeset
384 for module_name in self.inclusive_platforms.get(sys.platform, []):
c56e83d08d0b Deprecate the pure module for 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 46777
diff changeset
385 self.check_removal(module_name, optional=True)
c56e83d08d0b Deprecate the pure module for 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 46777
diff changeset
386
46813
aa9250e6c409 Deprecate the bsddb185 module for removal in 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 46811
diff changeset
387 def test_optional_module_removals(self):
aa9250e6c409 Deprecate the bsddb185 module for removal in 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 46811
diff changeset
388 # Test the removal of modules that may or may not be built.
aa9250e6c409 Deprecate the bsddb185 module for removal in 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 46811
diff changeset
389 for module_name in self.optional_modules:
aa9250e6c409 Deprecate the bsddb185 module for removal in 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 46811
diff changeset
390 self.check_removal(module_name, optional=True)
aa9250e6c409 Deprecate the bsddb185 module for removal in 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 46811
diff changeset
391
46771
b93005712e39 Add Py3k warnings to os.path.walk
Benjamin Peterson <benjamin@python.org>
parents: 46764
diff changeset
392 def test_os_path_walk(self):
b93005712e39 Add Py3k warnings to os.path.walk
Benjamin Peterson <benjamin@python.org>
parents: 46764
diff changeset
393 msg = "In 3.x, os.path.walk is removed in favor of os.walk."
b93005712e39 Add Py3k warnings to os.path.walk
Benjamin Peterson <benjamin@python.org>
parents: 46764
diff changeset
394 def dumbo(where, names, args): pass
b93005712e39 Add Py3k warnings to os.path.walk
Benjamin Peterson <benjamin@python.org>
parents: 46764
diff changeset
395 for path_mod in ("ntpath", "macpath", "os2emxpath", "posixpath"):
b93005712e39 Add Py3k warnings to os.path.walk
Benjamin Peterson <benjamin@python.org>
parents: 46764
diff changeset
396 mod = __import__(path_mod)
49146
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
397 reset_module_registry(mod)
59669
7df3e13d3e50 Cleanup some test cases using check_warnings and check_py3k_warnings.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59489
diff changeset
398 with check_py3k_warnings() as w:
47349
e4104597c2a3 Improvements for test_py3kwarn
Benjamin Peterson <benjamin@python.org>
parents: 47336
diff changeset
399 mod.walk("crashers", dumbo, None)
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62435
diff changeset
400 self.assertEqual(str(w.message), msg)
47336
2f9319169fec warn about some members of the commands module
Benjamin Peterson <benjamin@python.org>
parents: 47252
diff changeset
401
48281
5a87b0d1ce91 add a test for reduce's move
Benjamin Peterson <benjamin@python.org>
parents: 48213
diff changeset
402 def test_reduce_move(self):
5a87b0d1ce91 add a test for reduce's move
Benjamin Peterson <benjamin@python.org>
parents: 48213
diff changeset
403 from operator import add
49146
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
404 # reduce tests may have already triggered this warning
59489
269a12a50123 #7772: Fix test_py3kwarn. Now the test suite could pass with "-3" flag.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58460
diff changeset
405 reset_module_registry(unittest.case)
49099
ff96a313cd1c warnings.catch_warnings() now returns a list or None instead of the custom
Brett Cannon <bcannon@gmail.com>
parents: 49028
diff changeset
406 with warnings.catch_warnings():
48281
5a87b0d1ce91 add a test for reduce's move
Benjamin Peterson <benjamin@python.org>
parents: 48213
diff changeset
407 warnings.filterwarnings("error", "reduce")
5a87b0d1ce91 add a test for reduce's move
Benjamin Peterson <benjamin@python.org>
parents: 48213
diff changeset
408 self.assertRaises(DeprecationWarning, reduce, add, range(10))
5a87b0d1ce91 add a test for reduce's move
Benjamin Peterson <benjamin@python.org>
parents: 48213
diff changeset
409
47362
156746a63a5c UserString.MutableString has been removed in Python 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 47349
diff changeset
410 def test_mutablestring_removal(self):
156746a63a5c UserString.MutableString has been removed in Python 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 47349
diff changeset
411 # UserString.MutableString has been removed in 3.0.
156746a63a5c UserString.MutableString has been removed in Python 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 47349
diff changeset
412 import UserString
49146
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
413 # UserString tests may have already triggered this warning
f28b999a69f8 Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
Nick Coghlan <ncoghlan@gmail.com>
parents: 49099
diff changeset
414 reset_module_registry(UserString)
49099
ff96a313cd1c warnings.catch_warnings() now returns a list or None instead of the custom
Brett Cannon <bcannon@gmail.com>
parents: 49028
diff changeset
415 with warnings.catch_warnings():
47362
156746a63a5c UserString.MutableString has been removed in Python 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 47349
diff changeset
416 warnings.filterwarnings("error", ".*MutableString",
156746a63a5c UserString.MutableString has been removed in Python 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 47349
diff changeset
417 DeprecationWarning)
156746a63a5c UserString.MutableString has been removed in Python 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 47349
diff changeset
418 self.assertRaises(DeprecationWarning, UserString.MutableString)
156746a63a5c UserString.MutableString has been removed in Python 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 47349
diff changeset
419
46702
ffdb5f4139fe Deprecate the audiodev module for 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 46075
diff changeset
420
45860
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
421 def test_main():
63612
29d34e4d0a9a Merged revisions 78815 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62111
diff changeset
422 run_unittest(TestPy3KWarnings,
29d34e4d0a9a Merged revisions 78815 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62111
diff changeset
423 TestStdlibRemovals)
45860
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
424
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
425 if __name__ == '__main__':
50771a3fad2c Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373.
Steven Bethard <steven.bethard@gmail.com>
parents:
diff changeset
426 test_main()