1edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepimport unittest
2edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepimport sys
3edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepfrom test.test_support import check_py3k_warnings, CleanImport, run_unittest
4edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepimport warnings
5edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
6edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepif not sys.py3kwarning:
7edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    raise unittest.SkipTest('%s must be run with the -3 flag' % __name__)
8edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
9edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoeptry:
10edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    from test.test_support import __warningregistry__ as _registry
11edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepexcept ImportError:
12edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def check_deprecated_module(module_name):
13edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return False
14edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepelse:
15edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    past_warnings = _registry.keys()
16edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    del _registry
17edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def check_deprecated_module(module_name):
18edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Lookup the past warnings for module already loaded using
19edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        test_support.import_module(..., deprecated=True)
20edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
21edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return any(module_name in msg and ' removed' in msg
22edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                   and issubclass(cls, DeprecationWarning)
23edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                   and (' module' in msg or ' package' in msg)
24edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                   for (msg, cls, line) in past_warnings)
25edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
26edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdef reset_module_registry(module):
27edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    try:
28edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        registry = module.__warningregistry__
29edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    except AttributeError:
30edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        pass
31edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    else:
32edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        registry.clear()
33edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
34edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass TestPy3KWarnings(unittest.TestCase):
35edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
36edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def assertWarning(self, _, warning, expected_message):
37edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(str(warning.message), expected_message)
38edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
39edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def assertNoWarning(self, _, recorder):
40edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(len(recorder.warnings), 0)
41edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
42edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_backquote(self):
43edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        expected = 'backquote not supported in 3.x; use repr()'
44edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        with check_py3k_warnings((expected, SyntaxWarning)):
45edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            exec "`2`" in {}
46edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
47edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_paren_arg_names(self):
48edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        expected = 'parenthesized argument names are invalid in 3.x'
49edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def check(s):
50edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            with check_py3k_warnings((expected, SyntaxWarning)):
51edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                exec s in {}
52edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        check("def f((x)): pass")
53edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        check("def f((((x))), (y)): pass")
54edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        check("def f((x), (((y))), m=32): pass")
55edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # Something like def f((a, (b))): pass will raise the tuple
56edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # unpacking warning.
57edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
58edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_forbidden_names(self):
59edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # So we don't screw up our globals
60edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def safe_exec(expr):
61edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def f(**kwargs): pass
62edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            exec expr in {'f' : f}
63edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
64edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        tests = [("True", "assignment to True or False is forbidden in 3.x"),
65edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                 ("False", "assignment to True or False is forbidden in 3.x"),
66edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                 ("nonlocal", "nonlocal is a keyword in 3.x")]
67edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        with check_py3k_warnings(('', SyntaxWarning)) as w:
68edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            for keyword, expected in tests:
69edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                safe_exec("{0} = False".format(keyword))
70edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                self.assertWarning(None, w, expected)
71edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                w.reset()
72edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                try:
73edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    safe_exec("obj.{0} = True".format(keyword))
74edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                except NameError:
75edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
76edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                self.assertWarning(None, w, expected)
77edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                w.reset()
78edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                safe_exec("def {0}(): pass".format(keyword))
79edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                self.assertWarning(None, w, expected)
80edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                w.reset()
81edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                safe_exec("class {0}: pass".format(keyword))
82edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                self.assertWarning(None, w, expected)
83edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                w.reset()
84edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                safe_exec("def f({0}=43): pass".format(keyword))
85edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                self.assertWarning(None, w, expected)
86edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                w.reset()
87edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
88edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
89edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_type_inequality_comparisons(self):
90edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        expected = 'type inequality comparisons not supported in 3.x'
91edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        with check_py3k_warnings() as w:
92edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertWarning(int < str, w, expected)
93edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            w.reset()
94edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertWarning(type < object, w, expected)
95edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
96edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_object_inequality_comparisons(self):
97edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        expected = 'comparing unequal types not supported in 3.x'
98edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        with check_py3k_warnings() as w:
99edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertWarning(str < [], w, expected)
100edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            w.reset()
101edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertWarning(object() < (1, 2), w, expected)
102edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
103edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_dict_inequality_comparisons(self):
104edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        expected = 'dict inequality comparisons not supported in 3.x'
105edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        with check_py3k_warnings() as w:
106edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertWarning({} < {2:3}, w, expected)
107edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            w.reset()
108edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertWarning({} <= {}, w, expected)
109edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            w.reset()
110edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertWarning({} > {2:3}, w, expected)
111edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            w.reset()
112edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertWarning({2:3} >= {}, w, expected)
113edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
114edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_cell_inequality_comparisons(self):
115edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        expected = 'cell comparisons not supported in 3.x'
116edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def f(x):
117edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def g():
118edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                return x
119edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return g
120edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        cell0, = f(0).func_closure
121edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        cell1, = f(1).func_closure
122edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        with check_py3k_warnings() as w:
123edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertWarning(cell0 == cell1, w, expected)
124edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            w.reset()
125edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertWarning(cell0 < cell1, w, expected)
126edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
127edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_code_inequality_comparisons(self):
128edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        expected = 'code inequality comparisons not supported in 3.x'
129edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def f(x):
130edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass
131edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def g(x):
132edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass
133edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        with check_py3k_warnings() as w:
134edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertWarning(f.func_code < g.func_code, w, expected)
135edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            w.reset()
136edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertWarning(f.func_code <= g.func_code, w, expected)
137edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            w.reset()
138edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertWarning(f.func_code >= g.func_code, w, expected)
139edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            w.reset()
140edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertWarning(f.func_code > g.func_code, w, expected)
141edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
142edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_builtin_function_or_method_comparisons(self):
143edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        expected = ('builtin_function_or_method '
144edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    'order comparisons not supported in 3.x')
145edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        func = eval
146edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        meth = {}.get
147edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        with check_py3k_warnings() as w:
148edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertWarning(func < meth, w, expected)
149edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            w.reset()
150edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertWarning(func > meth, w, expected)
151edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            w.reset()
152edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertWarning(meth <= func, w, expected)
153edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            w.reset()
154edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertWarning(meth >= func, w, expected)
155edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            w.reset()
156edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertNoWarning(meth == func, w)
157edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertNoWarning(meth != func, w)
158edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            lam = lambda x: x
159edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertNoWarning(lam == func, w)
160edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertNoWarning(lam != func, w)
161edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
162edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_frame_attributes(self):
163edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        template = "%s has been removed in 3.x"
164edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        f = sys._getframe(0)
165edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for attr in ("f_exc_traceback", "f_exc_value", "f_exc_type"):
166edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            expected = template % attr
167edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            with check_py3k_warnings() as w:
168edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                self.assertWarning(getattr(f, attr), w, expected)
169edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                w.reset()
170edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                self.assertWarning(setattr(f, attr, None), w, expected)
171edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
172edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_sort_cmp_arg(self):
173edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        expected = "the cmp argument is not supported in 3.x"
174edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        lst = range(5)
175edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        cmp = lambda x,y: -1
176edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
177edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        with check_py3k_warnings() as w:
178edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertWarning(lst.sort(cmp=cmp), w, expected)
179edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            w.reset()
180edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertWarning(sorted(lst, cmp=cmp), w, expected)
181edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            w.reset()
182edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertWarning(lst.sort(cmp), w, expected)
183edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            w.reset()
184edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertWarning(sorted(lst, cmp), w, expected)
185edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
186edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_sys_exc_clear(self):
187edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        expected = 'sys.exc_clear() not supported in 3.x; use except clauses'
188edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        with check_py3k_warnings() as w:
189edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertWarning(sys.exc_clear(), w, expected)
190edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
191edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_methods_members(self):
192edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        expected = '__members__ and __methods__ not supported in 3.x'
193edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class C:
194edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            __methods__ = ['a']
195edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            __members__ = ['b']
196edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        c = C()
197edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        with check_py3k_warnings() as w:
198edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertWarning(dir(c), w, expected)
199edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
200edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_softspace(self):
201edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        expected = 'file.softspace not supported in 3.x'
202edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        with file(__file__) as f:
203edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            with check_py3k_warnings() as w:
204edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                self.assertWarning(f.softspace, w, expected)
205edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def set():
206edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                f.softspace = 0
207edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            with check_py3k_warnings() as w:
208edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                self.assertWarning(set(), w, expected)
209edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
210edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_slice_methods(self):
211edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class Spam(object):
212edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def __getslice__(self, i, j): pass
213edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def __setslice__(self, i, j, what): pass
214edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def __delslice__(self, i, j): pass
215edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class Egg:
216edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def __getslice__(self, i, h): pass
217edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def __setslice__(self, i, j, what): pass
218edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def __delslice__(self, i, j): pass
219edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
220edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        expected = "in 3.x, __{0}slice__ has been removed; use __{0}item__"
221edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
222edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for obj in (Spam(), Egg()):
223edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            with check_py3k_warnings() as w:
224edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                self.assertWarning(obj[1:2], w, expected.format('get'))
225edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                w.reset()
226edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                del obj[3:4]
227edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                self.assertWarning(None, w, expected.format('del'))
228edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                w.reset()
229edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                obj[4:5] = "eggs"
230edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                self.assertWarning(None, w, expected.format('set'))
231edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
232edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_tuple_parameter_unpacking(self):
233edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        expected = "tuple parameter unpacking has been removed in 3.x"
234edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        with check_py3k_warnings((expected, SyntaxWarning)):
235edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            exec "def f((a, b)): pass"
236edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
237edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_buffer(self):
238edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        expected = 'buffer() not supported in 3.x'
239edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        with check_py3k_warnings() as w:
240edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertWarning(buffer('a'), w, expected)
241edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
242edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_file_xreadlines(self):
243edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        expected = ("f.xreadlines() not supported in 3.x, "
244edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    "try 'for line in f' instead")
245edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        with file(__file__) as f:
246edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            with check_py3k_warnings() as w:
247edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                self.assertWarning(f.xreadlines(), w, expected)
248edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
249edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_hash_inheritance(self):
250edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        with check_py3k_warnings() as w:
251edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # With object as the base class
252edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class WarnOnlyCmp(object):
253edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def __cmp__(self, other): pass
254edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertEqual(len(w.warnings), 0)
255edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            w.reset()
256edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class WarnOnlyEq(object):
257edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def __eq__(self, other): pass
258edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertEqual(len(w.warnings), 1)
259edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertWarning(None, w,
260edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                 "Overriding __eq__ blocks inheritance of __hash__ in 3.x")
261edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            w.reset()
262edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class WarnCmpAndEq(object):
263edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def __cmp__(self, other): pass
264edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def __eq__(self, other): pass
265edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertEqual(len(w.warnings), 1)
266edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertWarning(None, w,
267edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                 "Overriding __eq__ blocks inheritance of __hash__ in 3.x")
268edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            w.reset()
269edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class NoWarningOnlyHash(object):
270edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def __hash__(self): pass
271edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertEqual(len(w.warnings), 0)
272edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # With an intermediate class in the heirarchy
273edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class DefinesAllThree(object):
274edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def __cmp__(self, other): pass
275edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def __eq__(self, other): pass
276edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def __hash__(self): pass
277edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class WarnOnlyCmp(DefinesAllThree):
278edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def __cmp__(self, other): pass
279edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertEqual(len(w.warnings), 0)
280edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            w.reset()
281edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class WarnOnlyEq(DefinesAllThree):
282edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def __eq__(self, other): pass
283edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertEqual(len(w.warnings), 1)
284edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertWarning(None, w,
285edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                 "Overriding __eq__ blocks inheritance of __hash__ in 3.x")
286edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            w.reset()
287edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class WarnCmpAndEq(DefinesAllThree):
288edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def __cmp__(self, other): pass
289edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def __eq__(self, other): pass
290edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertEqual(len(w.warnings), 1)
291edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertWarning(None, w,
292edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                 "Overriding __eq__ blocks inheritance of __hash__ in 3.x")
293edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            w.reset()
294edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class NoWarningOnlyHash(DefinesAllThree):
295edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def __hash__(self): pass
296edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertEqual(len(w.warnings), 0)
297edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
298edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_operator(self):
299edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        from operator import isCallable, sequenceIncludes
300edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
301edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        callable_warn = ("operator.isCallable() is not supported in 3.x. "
302edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                         "Use hasattr(obj, '__call__').")
303edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        seq_warn = ("operator.sequenceIncludes() is not supported "
304edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    "in 3.x. Use operator.contains().")
305edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        with check_py3k_warnings() as w:
306edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertWarning(isCallable(self), w, callable_warn)
307edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            w.reset()
308edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertWarning(sequenceIncludes(range(3), 2), w, seq_warn)
309edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
310edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
311edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass TestStdlibRemovals(unittest.TestCase):
312edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
313edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # test.testall not tested as it executes all unit tests as an
314edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # import side-effect.
315edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    all_platforms = ('audiodev', 'imputil', 'mutex', 'user', 'new', 'rexec',
316edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                        'Bastion', 'compiler', 'dircache', 'mimetools',
317edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                        'fpformat', 'ihooks', 'mhlib', 'statvfs', 'htmllib',
318edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                        'sgmllib', 'rfc822', 'sunaudio')
319edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    inclusive_platforms = {'irix' : ('pure', 'AL', 'al', 'CD', 'cd', 'cddb',
320edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                     'cdplayer', 'CL', 'cl', 'DEVICE', 'GL',
321edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                     'gl', 'ERRNO', 'FILE', 'FL', 'flp', 'fl',
322edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                     'fm', 'GET', 'GLWS', 'imgfile', 'IN',
323edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                     'IOCTL', 'jpeg', 'panel', 'panelparser',
324edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                     'readcd', 'SV', 'torgb', 'WAIT'),
325edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                          'darwin' : ('autoGIL', 'Carbon', 'OSATerminology',
326edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                      'icglue', 'Nav',
327edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                      # MacOS should (and does) give a Py3kWarning, but one of the
328edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                      # earlier tests already imports the MacOS extension which causes
329edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                      # this test to fail. Disabling the test for 'MacOS' avoids this
330edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                      # spurious test failure.
331edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                      #'MacOS',
332edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                      'aepack',
333edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                      'aetools', 'aetypes', 'applesingle',
334edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                      'appletrawmain', 'appletrunner',
335edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                      'argvemulator', 'bgenlocations',
336edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                      'EasyDialogs', 'macerrors', 'macostools',
337edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                      'findertools', 'FrameWork', 'ic',
338edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                      'gensuitemodule', 'icopen', 'macresource',
339edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                      'MiniAEFrame', 'pimp', 'PixMapWrapper',
340edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                      'terminalcommand', 'videoreader',
341edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                      '_builtinSuites', 'CodeWarrior',
342edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                      'Explorer', 'Finder', 'Netscape',
343edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                      'StdSuites', 'SystemEvents', 'Terminal',
344edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                      'cfmfile', 'bundlebuilder', 'buildtools',
345edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                      'ColorPicker', 'Audio_mac'),
346edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                           'sunos5' : ('sunaudiodev', 'SUNAUDIODEV'),
347edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                          }
348edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    optional_modules = ('bsddb185', 'Canvas', 'dl', 'linuxaudiodev', 'imageop',
349edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                        'sv', 'bsddb', 'dbhash')
350edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
351edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def check_removal(self, module_name, optional=False):
352edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Make sure the specified module, when imported, raises a
353edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        DeprecationWarning and specifies itself in the message."""
354edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        with CleanImport(module_name), warnings.catch_warnings():
355edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            warnings.filterwarnings("error", ".+ (module|package) .+ removed",
356edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                    DeprecationWarning, __name__)
357edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            warnings.filterwarnings("error", ".+ removed .+ (module|package)",
358edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                    DeprecationWarning, __name__)
359edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
360edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                __import__(module_name, level=0)
361edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except DeprecationWarning as exc:
362edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                self.assertIn(module_name, exc.args[0],
363edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                              "%s warning didn't contain module name"
364edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                              % module_name)
365edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except ImportError:
366edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                if not optional:
367edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    self.fail("Non-optional module {0} raised an "
368edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                              "ImportError.".format(module_name))
369edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            else:
370edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                # For extension modules, check the __warningregistry__.
371edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                # They won't rerun their init code even with CleanImport.
372edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                if not check_deprecated_module(module_name):
373edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    self.fail("DeprecationWarning not raised for {0}"
374edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                              .format(module_name))
375edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
376edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_platform_independent_removals(self):
377edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # Make sure that the modules that are available on all platforms raise
378edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # the proper DeprecationWarning.
379edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for module_name in self.all_platforms:
380edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.check_removal(module_name)
381edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
382edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_platform_specific_removals(self):
383edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # Test the removal of platform-specific modules.
384edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for module_name in self.inclusive_platforms.get(sys.platform, []):
385edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.check_removal(module_name, optional=True)
386edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
387edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_optional_module_removals(self):
388edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # Test the removal of modules that may or may not be built.
389edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for module_name in self.optional_modules:
390edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.check_removal(module_name, optional=True)
391edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
392edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_os_path_walk(self):
393edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        msg = "In 3.x, os.path.walk is removed in favor of os.walk."
394edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def dumbo(where, names, args): pass
395edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for path_mod in ("ntpath", "macpath", "os2emxpath", "posixpath"):
396edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            mod = __import__(path_mod)
397edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            reset_module_registry(mod)
398edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            with check_py3k_warnings() as w:
399edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                mod.walk("crashers", dumbo, None)
400edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertEqual(str(w.message), msg)
401edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
402edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_reduce_move(self):
403edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        from operator import add
404edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # reduce tests may have already triggered this warning
405edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        reset_module_registry(unittest.case)
406edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        with warnings.catch_warnings():
407edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            warnings.filterwarnings("error", "reduce")
408edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertRaises(DeprecationWarning, reduce, add, range(10))
409edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
410edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_mutablestring_removal(self):
411edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # UserString.MutableString has been removed in 3.0.
412edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        import UserString
413edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # UserString tests may have already triggered this warning
414edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        reset_module_registry(UserString)
415edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        with warnings.catch_warnings():
416edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            warnings.filterwarnings("error", ".*MutableString",
417edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                    DeprecationWarning)
418edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertRaises(DeprecationWarning, UserString.MutableString)
419edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
420edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
421edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdef test_main():
422edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    run_unittest(TestPy3KWarnings,
423edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                 TestStdlibRemovals)
424edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
425edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepif __name__ == '__main__':
426edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    test_main()
427