1edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep""" Test suite for the fixer modules """
2edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep# Python imports
4edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepimport os
5edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepimport unittest
6edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepfrom itertools import chain
7edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepfrom operator import itemgetter
8edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
9edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep# Local imports
10edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepfrom lib2to3 import pygram, pytree, refactor, fixer_util
11edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepfrom lib2to3.tests import support
12edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
13edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
14edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass FixerTestCase(support.TestCase):
15edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
16edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # Other test cases can subclass this class and replace "fixer_pkg" with
17edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # their own.
18edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def setUp(self, fix_list=None, fixer_pkg="lib2to3", options=None):
19edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if fix_list is None:
20edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            fix_list = [self.fixer]
21edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.refactor = support.get_refactorer(fixer_pkg, fix_list, options)
22edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.fixer_log = []
23edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.filename = u"<string>"
24edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
25edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for fixer in chain(self.refactor.pre_order,
26edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                           self.refactor.post_order):
27edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            fixer.log = self.fixer_log
28edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
29edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def _check(self, before, after):
30edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        before = support.reformat(before)
31edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        after = support.reformat(after)
32edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        tree = self.refactor.refactor_string(before, self.filename)
33edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(after, unicode(tree))
34edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return tree
35edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
36edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def check(self, before, after, ignore_warnings=False):
37edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        tree = self._check(before, after)
38edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertTrue(tree.was_changed)
39edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if not ignore_warnings:
40edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertEqual(self.fixer_log, [])
41edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
42edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def warns(self, before, after, message, unchanged=False):
43edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        tree = self._check(before, after)
44edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertTrue(message in "".join(self.fixer_log))
45edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if not unchanged:
46edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertTrue(tree.was_changed)
47edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
48edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def warns_unchanged(self, before, message):
49edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns(before, before, message, unchanged=True)
50edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
51edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def unchanged(self, before, ignore_warnings=False):
52edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self._check(before, before)
53edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if not ignore_warnings:
54edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertEqual(self.fixer_log, [])
55edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
56edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def assert_runs_after(self, *names):
57edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        fixes = [self.fixer]
58edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        fixes.extend(names)
59edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        r = support.get_refactorer("lib2to3", fixes)
60edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        (pre, post) = r.get_fixers()
61edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        n = "fix_" + self.fixer
62edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if post and post[-1].__class__.__module__.endswith(n):
63edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # We're the last fixer to run
64edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return
65edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if pre and pre[-1].__class__.__module__.endswith(n) and not post:
66edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # We're the last in pre and post is empty
67edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return
68edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.fail("Fixer run order (%s) is incorrect; %s should be last."\
69edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep               %(", ".join([x.__class__.__module__ for x in (pre+post)]), n))
70edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
71edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_ne(FixerTestCase):
72edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "ne"
73edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
74edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_basic(self):
75edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """if x <> y:
76edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass"""
77edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
78edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """if x != y:
79edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass"""
80edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
81edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
82edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_no_spaces(self):
83edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """if x<>y:
84edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass"""
85edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
86edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """if x!=y:
87edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass"""
88edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
89edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
90edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_chained(self):
91edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """if x<>y<>z:
92edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass"""
93edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
94edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """if x!=y!=z:
95edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass"""
96edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
97edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
98edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_has_key(FixerTestCase):
99edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "has_key"
100edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
101edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_1(self):
102edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = d.has_key("x") or d.has_key("y")"""
103edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = "x" in d or "y" in d"""
104edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
105edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
106edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_2(self):
107edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = a.b.c.d.has_key("x") ** 3"""
108edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = ("x" in a.b.c.d) ** 3"""
109edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
110edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
111edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_3(self):
112edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = a.b.has_key(1 + 2).__repr__()"""
113edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = (1 + 2 in a.b).__repr__()"""
114edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
115edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
116edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_4(self):
117edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = a.b.has_key(1 + 2).__repr__() ** -3 ** 4"""
118edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = (1 + 2 in a.b).__repr__() ** -3 ** 4"""
119edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
120edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
121edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_5(self):
122edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = a.has_key(f or g)"""
123edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = (f or g) in a"""
124edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
125edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
126edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_6(self):
127edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = a + b.has_key(c)"""
128edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = a + (c in b)"""
129edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
130edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
131edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_7(self):
132edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = a.has_key(lambda: 12)"""
133edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = (lambda: 12) in a"""
134edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
135edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
136edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_8(self):
137edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = a.has_key(a for a in b)"""
138edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = (a for a in b) in a"""
139edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
140edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
141edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_9(self):
142edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """if not a.has_key(b): pass"""
143edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """if b not in a: pass"""
144edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
145edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
146edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_10(self):
147edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """if not a.has_key(b).__repr__(): pass"""
148edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """if not (b in a).__repr__(): pass"""
149edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
150edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
151edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_11(self):
152edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """if not a.has_key(b) ** 2: pass"""
153edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """if not (b in a) ** 2: pass"""
154edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
155edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
156edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_apply(FixerTestCase):
157edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "apply"
158edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
159edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_1(self):
160edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = apply(f, g + h)"""
161edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = f(*g + h)"""
162edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
163edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
164edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_2(self):
165edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """y = apply(f, g, h)"""
166edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """y = f(*g, **h)"""
167edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
168edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
169edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_3(self):
170edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """z = apply(fs[0], g or h, h or g)"""
171edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """z = fs[0](*g or h, **h or g)"""
172edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
173edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
174edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_4(self):
175edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """apply(f, (x, y) + t)"""
176edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """f(*(x, y) + t)"""
177edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
178edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
179edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_5(self):
180edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """apply(f, args,)"""
181edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """f(*args)"""
182edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
183edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
184edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_6(self):
185edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """apply(f, args, kwds,)"""
186edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """f(*args, **kwds)"""
187edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
188edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
189edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # Test that complex functions are parenthesized
190edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
191edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_complex_1(self):
192edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = apply(f+g, args)"""
193edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = (f+g)(*args)"""
194edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
195edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
196edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_complex_2(self):
197edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = apply(f*g, args)"""
198edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = (f*g)(*args)"""
199edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
200edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
201edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_complex_3(self):
202edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = apply(f**g, args)"""
203edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = (f**g)(*args)"""
204edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
205edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
206edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # But dotted names etc. not
207edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
208edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_dotted_name(self):
209edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = apply(f.g, args)"""
210edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = f.g(*args)"""
211edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
212edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
213edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_subscript(self):
214edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = apply(f[x], args)"""
215edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = f[x](*args)"""
216edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
217edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
218edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_call(self):
219edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = apply(f(), args)"""
220edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = f()(*args)"""
221edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
222edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
223edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # Extreme case
224edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_extreme(self):
225edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = apply(a.b.c.d.e.f, args, kwds)"""
226edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = a.b.c.d.e.f(*args, **kwds)"""
227edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
228edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
229edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # XXX Comments in weird places still get lost
230edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_weird_comments(self):
231edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """apply(   # foo
232edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep          f, # bar
233edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep          args)"""
234edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """f(*args)"""
235edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
236edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
237edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # These should *not* be touched
238edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
239edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_1(self):
240edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """apply()"""
241edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
242edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
243edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_2(self):
244edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """apply(f)"""
245edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
246edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
247edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_3(self):
248edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """apply(f,)"""
249edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
250edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
251edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_4(self):
252edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """apply(f, args, kwds, extras)"""
253edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
254edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
255edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_5(self):
256edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """apply(f, *args, **kwds)"""
257edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
258edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
259edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_6(self):
260edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """apply(f, *args)"""
261edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
262edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
263edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_7(self):
264edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """apply(func=f, args=args, kwds=kwds)"""
265edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
266edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
267edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_8(self):
268edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """apply(f, args=args, kwds=kwds)"""
269edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
270edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
271edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_9(self):
272edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """apply(f, args, kwds=kwds)"""
273edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
274edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
275edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_space_1(self):
276edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """apply(  f,  args,   kwds)"""
277edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """f(*args, **kwds)"""
278edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(a, b)
279edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
280edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_space_2(self):
281edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """apply(  f  ,args,kwds   )"""
282edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """f(*args, **kwds)"""
283edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(a, b)
284edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
285edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_intern(FixerTestCase):
286edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "intern"
287edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
288edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_prefix_preservation(self):
289edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x =   intern(  a  )"""
290edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """import sys\nx =   sys.intern(  a  )"""
291edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
292edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
293edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """y = intern("b" # test
294edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep              )"""
295edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """import sys\ny = sys.intern("b" # test
296edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep              )"""
297edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
298edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
299edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """z = intern(a+b+c.d,   )"""
300edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """import sys\nz = sys.intern(a+b+c.d,   )"""
301edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
302edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
303edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test(self):
304edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = intern(a)"""
305edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """import sys\nx = sys.intern(a)"""
306edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
307edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
308edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """z = intern(a+b+c.d,)"""
309edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """import sys\nz = sys.intern(a+b+c.d,)"""
310edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
311edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
312edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """intern("y%s" % 5).replace("y", "")"""
313edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """import sys\nsys.intern("y%s" % 5).replace("y", "")"""
314edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
315edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
316edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # These should not be refactored
317edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
318edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged(self):
319edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """intern(a=1)"""
320edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
321edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
322edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """intern(f, g)"""
323edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
324edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
325edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """intern(*h)"""
326edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
327edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
328edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """intern(**i)"""
329edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
330edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
331edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """intern()"""
332edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
333edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
334edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_reduce(FixerTestCase):
335edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "reduce"
336edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
337edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_simple_call(self):
338edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "reduce(a, b, c)"
339edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "from functools import reduce\nreduce(a, b, c)"
340edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
341edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
342edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_bug_7253(self):
343edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # fix_tuple_params was being bad and orphaning nodes in the tree.
344edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "def x(arg): reduce(sum, [])"
345edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "from functools import reduce\ndef x(arg): reduce(sum, [])"
346edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
347edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
348edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_call_with_lambda(self):
349edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "reduce(lambda x, y: x + y, seq)"
350edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "from functools import reduce\nreduce(lambda x, y: x + y, seq)"
351edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
352edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
353edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged(self):
354edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = "reduce(a)"
355edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
356edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
357edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = "reduce(a, b=42)"
358edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
359edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
360edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = "reduce(a, b, c, d)"
361edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
362edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
363edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = "reduce(**c)"
364edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
365edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
366edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = "reduce()"
367edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
368edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
369edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_print(FixerTestCase):
370edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "print"
371edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
372edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_prefix_preservation(self):
373edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """print 1,   1+1,   1+1+1"""
374edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """print(1,   1+1,   1+1+1)"""
375edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
376edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
377edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_idempotency(self):
378edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """print()"""
379edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
380edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
381edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """print('')"""
382edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
383edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
384edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_idempotency_print_as_function(self):
385edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.refactor.driver.grammar = pygram.python_grammar_no_print_statement
386edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """print(1, 1+1, 1+1+1)"""
387edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
388edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
389edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """print()"""
390edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
391edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
392edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """print('')"""
393edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
394edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
395edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_1(self):
396edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """print 1, 1+1, 1+1+1"""
397edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """print(1, 1+1, 1+1+1)"""
398edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
399edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
400edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_2(self):
401edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """print 1, 2"""
402edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """print(1, 2)"""
403edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
404edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
405edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_3(self):
406edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """print"""
407edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """print()"""
408edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
409edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
410edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_4(self):
411edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # from bug 3000
412edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """print whatever; print"""
413edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """print(whatever); print()"""
414edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
415edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
416edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_5(self):
417edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """print; print whatever;"""
418edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """print(); print(whatever);"""
419edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
420edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
421edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_tuple(self):
422edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """print (a, b, c)"""
423edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """print((a, b, c))"""
424edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
425edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
426edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # trailing commas
427edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
428edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_trailing_comma_1(self):
429edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """print 1, 2, 3,"""
430edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """print(1, 2, 3, end=' ')"""
431edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
432edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
433edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_trailing_comma_2(self):
434edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """print 1, 2,"""
435edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """print(1, 2, end=' ')"""
436edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
437edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
438edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_trailing_comma_3(self):
439edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """print 1,"""
440edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """print(1, end=' ')"""
441edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
442edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
443edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # >> stuff
444edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
445edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_vargs_without_trailing_comma(self):
446edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """print >>sys.stderr, 1, 2, 3"""
447edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """print(1, 2, 3, file=sys.stderr)"""
448edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
449edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
450edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_with_trailing_comma(self):
451edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """print >>sys.stderr, 1, 2,"""
452edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """print(1, 2, end=' ', file=sys.stderr)"""
453edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
454edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
455edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_no_trailing_comma(self):
456edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """print >>sys.stderr, 1+1"""
457edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """print(1+1, file=sys.stderr)"""
458edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
459edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
460edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_spaces_before_file(self):
461edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """print >>  sys.stderr"""
462edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """print(file=sys.stderr)"""
463edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
464edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
465edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_with_future_print_function(self):
466edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = "from __future__ import print_function\n" \
467edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            "print('Hai!', end=' ')"
468edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
469edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
470edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "print 'Hello, world!'"
471edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "print('Hello, world!')"
472edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
473edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
474edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
475edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_exec(FixerTestCase):
476edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "exec"
477edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
478edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_prefix_preservation(self):
479edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """  exec code in ns1,   ns2"""
480edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """  exec(code, ns1,   ns2)"""
481edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
482edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
483edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_basic(self):
484edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """exec code"""
485edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """exec(code)"""
486edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
487edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
488edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_with_globals(self):
489edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """exec code in ns"""
490edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """exec(code, ns)"""
491edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
492edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
493edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_with_globals_locals(self):
494edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """exec code in ns1, ns2"""
495edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """exec(code, ns1, ns2)"""
496edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
497edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
498edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_complex_1(self):
499edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """exec (a.b()) in ns"""
500edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """exec((a.b()), ns)"""
501edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
502edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
503edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_complex_2(self):
504edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """exec a.b() + c in ns"""
505edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """exec(a.b() + c, ns)"""
506edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
507edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
508edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # These should not be touched
509edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
510edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_1(self):
511edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """exec(code)"""
512edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
513edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
514edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_2(self):
515edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """exec (code)"""
516edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
517edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
518edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_3(self):
519edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """exec(code, ns)"""
520edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
521edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
522edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_4(self):
523edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """exec(code, ns1, ns2)"""
524edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
525edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
526edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_repr(FixerTestCase):
527edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "repr"
528edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
529edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_prefix_preservation(self):
530edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x =   `1 + 2`"""
531edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x =   repr(1 + 2)"""
532edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
533edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
534edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_simple_1(self):
535edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = `1 + 2`"""
536edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = repr(1 + 2)"""
537edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
538edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
539edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_simple_2(self):
540edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """y = `x`"""
541edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """y = repr(x)"""
542edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
543edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
544edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_complex(self):
545edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """z = `y`.__repr__()"""
546edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """z = repr(y).__repr__()"""
547edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
548edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
549edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_tuple(self):
550edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = `1, 2, 3`"""
551edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = repr((1, 2, 3))"""
552edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
553edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
554edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_nested(self):
555edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = `1 + `2``"""
556edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = repr(1 + repr(2))"""
557edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
558edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
559edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_nested_tuples(self):
560edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = `1, 2 + `3, 4``"""
561edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = repr((1, 2 + repr((3, 4))))"""
562edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
563edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
564edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_except(FixerTestCase):
565edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "except"
566edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
567edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_prefix_preservation(self):
568edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
569edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
570edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
571edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except (RuntimeError, ImportError),    e:
572edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass"""
573edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
574edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
575edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
576edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except (RuntimeError, ImportError) as    e:
577edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass"""
578edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
579edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
580edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_simple(self):
581edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
582edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
583edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
584edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except Foo, e:
585edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass"""
586edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
587edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
588edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
589edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except Foo as e:
590edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass"""
591edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
592edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
593edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_simple_no_space_before_target(self):
594edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
595edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
596edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
597edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except Foo,e:
598edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass"""
599edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
600edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
601edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
602edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except Foo as e:
603edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass"""
604edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
605edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
606edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_tuple_unpack(self):
607edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
608edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def foo():
609edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                try:
610edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
611edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                except Exception, (f, e):
612edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
613edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                except ImportError, e:
614edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass"""
615edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
616edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
617edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def foo():
618edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                try:
619edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
620edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                except Exception as xxx_todo_changeme:
621edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    (f, e) = xxx_todo_changeme.args
622edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
623edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                except ImportError as e:
624edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass"""
625edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
626edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
627edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_multi_class(self):
628edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
629edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
630edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
631edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except (RuntimeError, ImportError), e:
632edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass"""
633edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
634edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
635edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
636edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
637edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except (RuntimeError, ImportError) as e:
638edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass"""
639edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
640edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
641edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_list_unpack(self):
642edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
643edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
644edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
645edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except Exception, [a, b]:
646edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass"""
647edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
648edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
649edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
650edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
651edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except Exception as xxx_todo_changeme:
652edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                [a, b] = xxx_todo_changeme.args
653edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass"""
654edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
655edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
656edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_weird_target_1(self):
657edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
658edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
659edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
660edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except Exception, d[5]:
661edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass"""
662edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
663edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
664edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
665edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
666edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except Exception as xxx_todo_changeme:
667edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                d[5] = xxx_todo_changeme
668edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass"""
669edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
670edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
671edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_weird_target_2(self):
672edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
673edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
674edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
675edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except Exception, a.foo:
676edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass"""
677edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
678edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
679edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
680edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
681edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except Exception as xxx_todo_changeme:
682edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                a.foo = xxx_todo_changeme
683edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass"""
684edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
685edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
686edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_weird_target_3(self):
687edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
688edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
689edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
690edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except Exception, a().foo:
691edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass"""
692edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
693edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
694edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
695edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
696edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except Exception as xxx_todo_changeme:
697edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                a().foo = xxx_todo_changeme
698edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass"""
699edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
700edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
701edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_bare_except(self):
702edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
703edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
704edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
705edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except Exception, a:
706edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
707edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except:
708edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass"""
709edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
710edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
711edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
712edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
713edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except Exception as a:
714edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
715edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except:
716edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass"""
717edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
718edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
719edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_bare_except_and_else_finally(self):
720edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
721edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
722edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
723edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except Exception, a:
724edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
725edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except:
726edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
727edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            else:
728edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
729edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            finally:
730edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass"""
731edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
732edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
733edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
734edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
735edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except Exception as a:
736edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
737edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except:
738edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
739edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            else:
740edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
741edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            finally:
742edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass"""
743edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
744edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
745edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_multi_fixed_excepts_before_bare_except(self):
746edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
747edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
748edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
749edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except TypeError, b:
750edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
751edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except Exception, a:
752edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
753edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except:
754edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass"""
755edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
756edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
757edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
758edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
759edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except TypeError as b:
760edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
761edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except Exception as a:
762edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
763edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except:
764edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass"""
765edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
766edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
767edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_one_line_suites(self):
768edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
769edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try: raise TypeError
770edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except TypeError, e:
771edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
772edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
773edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
774edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try: raise TypeError
775edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except TypeError as e:
776edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
777edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
778edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
779edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
780edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
781edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                raise TypeError
782edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except TypeError, e: pass
783edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
784edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
785edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
786edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                raise TypeError
787edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except TypeError as e: pass
788edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
789edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
790edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
791edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try: raise TypeError
792edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except TypeError, e: pass
793edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
794edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
795edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try: raise TypeError
796edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except TypeError as e: pass
797edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
798edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
799edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
800edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try: raise TypeError
801edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except TypeError, e: pass
802edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            else: function()
803edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            finally: done()
804edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
805edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
806edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try: raise TypeError
807edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except TypeError as e: pass
808edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            else: function()
809edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            finally: done()
810edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
811edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
812edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
813edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # These should not be touched:
814edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
815edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_1(self):
816edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
817edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
818edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
819edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except:
820edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass"""
821edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
822edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
823edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_2(self):
824edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
825edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
826edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
827edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except Exception:
828edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass"""
829edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
830edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
831edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_3(self):
832edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
833edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
834edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
835edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except (Exception, SystemExit):
836edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass"""
837edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
838edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
839edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_raise(FixerTestCase):
840edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "raise"
841edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
842edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_basic(self):
843edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """raise Exception, 5"""
844edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """raise Exception(5)"""
845edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
846edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
847edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_prefix_preservation(self):
848edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """raise Exception,5"""
849edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """raise Exception(5)"""
850edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
851edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
852edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """raise   Exception,    5"""
853edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """raise   Exception(5)"""
854edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
855edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
856edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_with_comments(self):
857edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """raise Exception, 5 # foo"""
858edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """raise Exception(5) # foo"""
859edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
860edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
861edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """raise E, (5, 6) % (a, b) # foo"""
862edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """raise E((5, 6) % (a, b)) # foo"""
863edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
864edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
865edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """def foo():
866edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    raise Exception, 5, 6 # foo"""
867edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """def foo():
868edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    raise Exception(5).with_traceback(6) # foo"""
869edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
870edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
871edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_None_value(self):
872edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """raise Exception(5), None, tb"""
873edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """raise Exception(5).with_traceback(tb)"""
874edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
875edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
876edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_tuple_value(self):
877edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """raise Exception, (5, 6, 7)"""
878edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """raise Exception(5, 6, 7)"""
879edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
880edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
881edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_tuple_detection(self):
882edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """raise E, (5, 6) % (a, b)"""
883edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """raise E((5, 6) % (a, b))"""
884edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
885edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
886edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_tuple_exc_1(self):
887edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """raise (((E1, E2), E3), E4), V"""
888edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """raise E1(V)"""
889edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
890edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
891edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_tuple_exc_2(self):
892edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """raise (E1, (E2, E3), E4), V"""
893edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """raise E1(V)"""
894edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
895edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
896edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # These should produce a warning
897edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
898edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_string_exc(self):
899edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """raise 'foo'"""
900edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, "Python 3 does not support string exceptions")
901edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
902edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_string_exc_val(self):
903edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """raise "foo", 5"""
904edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, "Python 3 does not support string exceptions")
905edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
906edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_string_exc_val_tb(self):
907edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """raise "foo", 5, 6"""
908edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, "Python 3 does not support string exceptions")
909edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
910edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # These should result in traceback-assignment
911edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
912edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_tb_1(self):
913edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """def foo():
914edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    raise Exception, 5, 6"""
915edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """def foo():
916edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    raise Exception(5).with_traceback(6)"""
917edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
918edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
919edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_tb_2(self):
920edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """def foo():
921edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    a = 5
922edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    raise Exception, 5, 6
923edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    b = 6"""
924edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """def foo():
925edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    a = 5
926edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    raise Exception(5).with_traceback(6)
927edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    b = 6"""
928edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
929edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
930edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_tb_3(self):
931edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """def foo():
932edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    raise Exception,5,6"""
933edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """def foo():
934edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    raise Exception(5).with_traceback(6)"""
935edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
936edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
937edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_tb_4(self):
938edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """def foo():
939edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    a = 5
940edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    raise Exception,5,6
941edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    b = 6"""
942edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """def foo():
943edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    a = 5
944edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    raise Exception(5).with_traceback(6)
945edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    b = 6"""
946edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
947edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
948edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_tb_5(self):
949edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """def foo():
950edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    raise Exception, (5, 6, 7), 6"""
951edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """def foo():
952edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    raise Exception(5, 6, 7).with_traceback(6)"""
953edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
954edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
955edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_tb_6(self):
956edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """def foo():
957edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    a = 5
958edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    raise Exception, (5, 6, 7), 6
959edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    b = 6"""
960edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """def foo():
961edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    a = 5
962edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    raise Exception(5, 6, 7).with_traceback(6)
963edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    b = 6"""
964edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
965edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
966edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_throw(FixerTestCase):
967edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "throw"
968edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
969edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_1(self):
970edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """g.throw(Exception, 5)"""
971edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """g.throw(Exception(5))"""
972edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
973edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
974edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_2(self):
975edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """g.throw(Exception,5)"""
976edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """g.throw(Exception(5))"""
977edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
978edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
979edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_3(self):
980edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """g.throw(Exception, (5, 6, 7))"""
981edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """g.throw(Exception(5, 6, 7))"""
982edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
983edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
984edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_4(self):
985edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """5 + g.throw(Exception, 5)"""
986edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """5 + g.throw(Exception(5))"""
987edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
988edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
989edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # These should produce warnings
990edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
991edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_warn_1(self):
992edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """g.throw("foo")"""
993edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, "Python 3 does not support string exceptions")
994edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
995edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_warn_2(self):
996edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """g.throw("foo", 5)"""
997edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, "Python 3 does not support string exceptions")
998edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
999edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_warn_3(self):
1000edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """g.throw("foo", 5, 6)"""
1001edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, "Python 3 does not support string exceptions")
1002edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1003edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # These should not be touched
1004edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1005edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_untouched_1(self):
1006edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """g.throw(Exception)"""
1007edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
1008edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1009edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_untouched_2(self):
1010edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """g.throw(Exception(5, 6))"""
1011edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
1012edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1013edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_untouched_3(self):
1014edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """5 + g.throw(Exception(5, 6))"""
1015edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
1016edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1017edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # These should result in traceback-assignment
1018edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1019edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_tb_1(self):
1020edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """def foo():
1021edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    g.throw(Exception, 5, 6)"""
1022edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """def foo():
1023edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    g.throw(Exception(5).with_traceback(6))"""
1024edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1025edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1026edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_tb_2(self):
1027edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """def foo():
1028edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    a = 5
1029edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    g.throw(Exception, 5, 6)
1030edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    b = 6"""
1031edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """def foo():
1032edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    a = 5
1033edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    g.throw(Exception(5).with_traceback(6))
1034edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    b = 6"""
1035edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1036edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1037edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_tb_3(self):
1038edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """def foo():
1039edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    g.throw(Exception,5,6)"""
1040edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """def foo():
1041edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    g.throw(Exception(5).with_traceback(6))"""
1042edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1043edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1044edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_tb_4(self):
1045edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """def foo():
1046edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    a = 5
1047edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    g.throw(Exception,5,6)
1048edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    b = 6"""
1049edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """def foo():
1050edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    a = 5
1051edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    g.throw(Exception(5).with_traceback(6))
1052edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    b = 6"""
1053edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1054edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1055edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_tb_5(self):
1056edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """def foo():
1057edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    g.throw(Exception, (5, 6, 7), 6)"""
1058edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """def foo():
1059edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    g.throw(Exception(5, 6, 7).with_traceback(6))"""
1060edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1061edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1062edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_tb_6(self):
1063edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """def foo():
1064edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    a = 5
1065edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    g.throw(Exception, (5, 6, 7), 6)
1066edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    b = 6"""
1067edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """def foo():
1068edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    a = 5
1069edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    g.throw(Exception(5, 6, 7).with_traceback(6))
1070edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    b = 6"""
1071edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1072edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1073edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_tb_7(self):
1074edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """def foo():
1075edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    a + g.throw(Exception, 5, 6)"""
1076edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """def foo():
1077edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    a + g.throw(Exception(5).with_traceback(6))"""
1078edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1079edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1080edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_tb_8(self):
1081edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """def foo():
1082edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    a = 5
1083edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    a + g.throw(Exception, 5, 6)
1084edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    b = 6"""
1085edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """def foo():
1086edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    a = 5
1087edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    a + g.throw(Exception(5).with_traceback(6))
1088edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    b = 6"""
1089edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1090edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1091edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_long(FixerTestCase):
1092edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "long"
1093edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1094edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_1(self):
1095edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = long(x)"""
1096edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = int(x)"""
1097edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1098edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1099edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_2(self):
1100edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """y = isinstance(x, long)"""
1101edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """y = isinstance(x, int)"""
1102edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1103edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1104edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_3(self):
1105edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """z = type(x) in (int, long)"""
1106edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """z = type(x) in (int, int)"""
1107edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1108edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1109edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged(self):
1110edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """long = True"""
1111edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
1112edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1113edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """s.long = True"""
1114edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
1115edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1116edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """def long(): pass"""
1117edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
1118edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1119edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """class long(): pass"""
1120edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
1121edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1122edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """def f(long): pass"""
1123edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
1124edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1125edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """def f(g, long): pass"""
1126edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
1127edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1128edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """def f(x, long=True): pass"""
1129edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
1130edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1131edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_prefix_preservation(self):
1132edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x =   long(  x  )"""
1133edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x =   int(  x  )"""
1134edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1135edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1136edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1137edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_execfile(FixerTestCase):
1138edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "execfile"
1139edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1140edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_conversion(self):
1141edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """execfile("fn")"""
1142edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """exec(compile(open("fn").read(), "fn", 'exec'))"""
1143edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1144edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1145edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """execfile("fn", glob)"""
1146edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """exec(compile(open("fn").read(), "fn", 'exec'), glob)"""
1147edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1148edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1149edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """execfile("fn", glob, loc)"""
1150edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """exec(compile(open("fn").read(), "fn", 'exec'), glob, loc)"""
1151edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1152edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1153edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """execfile("fn", globals=glob)"""
1154edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """exec(compile(open("fn").read(), "fn", 'exec'), globals=glob)"""
1155edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1156edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1157edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """execfile("fn", locals=loc)"""
1158edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """exec(compile(open("fn").read(), "fn", 'exec'), locals=loc)"""
1159edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1160edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1161edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """execfile("fn", globals=glob, locals=loc)"""
1162edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """exec(compile(open("fn").read(), "fn", 'exec'), globals=glob, locals=loc)"""
1163edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1164edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1165edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_spacing(self):
1166edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """execfile( "fn" )"""
1167edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """exec(compile(open( "fn" ).read(), "fn", 'exec'))"""
1168edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1169edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1170edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """execfile("fn",  globals = glob)"""
1171edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """exec(compile(open("fn").read(), "fn", 'exec'),  globals = glob)"""
1172edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1173edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1174edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1175edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_isinstance(FixerTestCase):
1176edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "isinstance"
1177edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1178edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_remove_multiple_items(self):
1179edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """isinstance(x, (int, int, int))"""
1180edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """isinstance(x, int)"""
1181edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1182edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1183edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """isinstance(x, (int, float, int, int, float))"""
1184edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """isinstance(x, (int, float))"""
1185edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1186edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1187edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """isinstance(x, (int, float, int, int, float, str))"""
1188edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """isinstance(x, (int, float, str))"""
1189edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1190edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1191edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """isinstance(foo() + bar(), (x(), y(), x(), int, int))"""
1192edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """isinstance(foo() + bar(), (x(), y(), x(), int))"""
1193edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1194edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1195edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_prefix_preservation(self):
1196edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """if    isinstance(  foo(), (  bar, bar, baz )) : pass"""
1197edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """if    isinstance(  foo(), (  bar, baz )) : pass"""
1198edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1199edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1200edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged(self):
1201edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged("isinstance(x, (str, int))")
1202edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1203edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_dict(FixerTestCase):
1204edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "dict"
1205edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1206edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_prefix_preservation(self):
1207edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "if   d. keys  (  )  : pass"
1208edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "if   list(d. keys  (  ))  : pass"
1209edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1210edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1211edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "if   d. items  (  )  : pass"
1212edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "if   list(d. items  (  ))  : pass"
1213edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1214edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1215edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "if   d. iterkeys  ( )  : pass"
1216edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "if   iter(d. keys  ( ))  : pass"
1217edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1218edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1219edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "[i for i in    d.  iterkeys(  )  ]"
1220edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "[i for i in    d.  keys(  )  ]"
1221edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1222edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1223edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "if   d. viewkeys  ( )  : pass"
1224edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "if   d. keys  ( )  : pass"
1225edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1226edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1227edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "[i for i in    d.  viewkeys(  )  ]"
1228edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "[i for i in    d.  keys(  )  ]"
1229edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1230edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1231edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_trailing_comment(self):
1232edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "d.keys() # foo"
1233edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "list(d.keys()) # foo"
1234edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1235edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1236edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "d.items()  # foo"
1237edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "list(d.items())  # foo"
1238edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1239edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1240edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "d.iterkeys()  # foo"
1241edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "iter(d.keys())  # foo"
1242edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1243edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1244edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """[i for i in d.iterkeys() # foo
1245edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep               ]"""
1246edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """[i for i in d.keys() # foo
1247edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep               ]"""
1248edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1249edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1250edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """[i for i in d.iterkeys() # foo
1251edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep               ]"""
1252edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """[i for i in d.keys() # foo
1253edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep               ]"""
1254edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1255edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1256edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "d.viewitems()  # foo"
1257edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "d.items()  # foo"
1258edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1259edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1260edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged(self):
1261edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for wrapper in fixer_util.consuming_calls:
1262edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            s = "s = %s(d.keys())" % wrapper
1263edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.unchanged(s)
1264edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1265edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            s = "s = %s(d.values())" % wrapper
1266edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.unchanged(s)
1267edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1268edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            s = "s = %s(d.items())" % wrapper
1269edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.unchanged(s)
1270edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1271edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_01(self):
1272edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "d.keys()"
1273edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "list(d.keys())"
1274edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1275edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1276edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "a[0].foo().keys()"
1277edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "list(a[0].foo().keys())"
1278edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1279edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1280edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_02(self):
1281edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "d.items()"
1282edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "list(d.items())"
1283edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1284edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1285edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_03(self):
1286edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "d.values()"
1287edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "list(d.values())"
1288edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1289edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1290edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_04(self):
1291edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "d.iterkeys()"
1292edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "iter(d.keys())"
1293edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1294edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1295edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_05(self):
1296edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "d.iteritems()"
1297edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "iter(d.items())"
1298edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1299edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1300edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_06(self):
1301edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "d.itervalues()"
1302edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "iter(d.values())"
1303edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1304edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1305edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_07(self):
1306edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = "list(d.keys())"
1307edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
1308edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1309edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_08(self):
1310edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = "sorted(d.keys())"
1311edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
1312edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1313edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_09(self):
1314edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "iter(d.keys())"
1315edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "iter(list(d.keys()))"
1316edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1317edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1318edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_10(self):
1319edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "foo(d.keys())"
1320edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "foo(list(d.keys()))"
1321edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1322edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1323edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_11(self):
1324edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "for i in d.keys(): print i"
1325edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "for i in list(d.keys()): print i"
1326edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1327edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1328edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_12(self):
1329edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "for i in d.iterkeys(): print i"
1330edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "for i in d.keys(): print i"
1331edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1332edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1333edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_13(self):
1334edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "[i for i in d.keys()]"
1335edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "[i for i in list(d.keys())]"
1336edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1337edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1338edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_14(self):
1339edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "[i for i in d.iterkeys()]"
1340edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "[i for i in d.keys()]"
1341edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1342edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1343edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_15(self):
1344edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "(i for i in d.keys())"
1345edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "(i for i in list(d.keys()))"
1346edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1347edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1348edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_16(self):
1349edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "(i for i in d.iterkeys())"
1350edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "(i for i in d.keys())"
1351edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1352edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1353edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_17(self):
1354edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "iter(d.iterkeys())"
1355edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "iter(d.keys())"
1356edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1357edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1358edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_18(self):
1359edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "list(d.iterkeys())"
1360edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "list(d.keys())"
1361edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1362edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1363edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_19(self):
1364edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "sorted(d.iterkeys())"
1365edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "sorted(d.keys())"
1366edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1367edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1368edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_20(self):
1369edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "foo(d.iterkeys())"
1370edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "foo(iter(d.keys()))"
1371edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1372edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1373edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_21(self):
1374edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "print h.iterkeys().next()"
1375edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "print iter(h.keys()).next()"
1376edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1377edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1378edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_22(self):
1379edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "print h.keys()[0]"
1380edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "print list(h.keys())[0]"
1381edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1382edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1383edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_23(self):
1384edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "print list(h.iterkeys().next())"
1385edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "print list(iter(h.keys()).next())"
1386edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1387edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1388edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_24(self):
1389edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "for x in h.keys()[0]: print x"
1390edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "for x in list(h.keys())[0]: print x"
1391edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1392edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1393edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_25(self):
1394edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "d.viewkeys()"
1395edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "d.keys()"
1396edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1397edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1398edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_26(self):
1399edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "d.viewitems()"
1400edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "d.items()"
1401edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1402edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1403edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_27(self):
1404edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "d.viewvalues()"
1405edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "d.values()"
1406edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1407edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1408edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_14(self):
1409edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "[i for i in d.viewkeys()]"
1410edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "[i for i in d.keys()]"
1411edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1412edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1413edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_15(self):
1414edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "(i for i in d.viewkeys())"
1415edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "(i for i in d.keys())"
1416edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1417edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1418edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_17(self):
1419edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "iter(d.viewkeys())"
1420edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "iter(d.keys())"
1421edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1422edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1423edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_18(self):
1424edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "list(d.viewkeys())"
1425edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "list(d.keys())"
1426edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1427edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1428edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_19(self):
1429edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "sorted(d.viewkeys())"
1430edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "sorted(d.keys())"
1431edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1432edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1433edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_xrange(FixerTestCase):
1434edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "xrange"
1435edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1436edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_prefix_preservation(self):
1437edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x =    xrange(  10  )"""
1438edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x =    range(  10  )"""
1439edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1440edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1441edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = xrange(  1  ,  10   )"""
1442edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = range(  1  ,  10   )"""
1443edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1444edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1445edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = xrange(  0  ,  10 ,  2 )"""
1446edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = range(  0  ,  10 ,  2 )"""
1447edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1448edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1449edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_single_arg(self):
1450edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = xrange(10)"""
1451edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = range(10)"""
1452edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1453edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1454edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_two_args(self):
1455edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = xrange(1, 10)"""
1456edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = range(1, 10)"""
1457edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1458edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1459edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_three_args(self):
1460edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = xrange(0, 10, 2)"""
1461edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = range(0, 10, 2)"""
1462edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1463edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1464edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_wrap_in_list(self):
1465edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = range(10, 3, 9)"""
1466edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = list(range(10, 3, 9))"""
1467edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1468edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1469edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = foo(range(10, 3, 9))"""
1470edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = foo(list(range(10, 3, 9)))"""
1471edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1472edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1473edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = range(10, 3, 9) + [4]"""
1474edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = list(range(10, 3, 9)) + [4]"""
1475edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1476edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1477edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = range(10)[::-1]"""
1478edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = list(range(10))[::-1]"""
1479edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1480edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1481edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = range(10)  [3]"""
1482edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = list(range(10))  [3]"""
1483edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1484edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1485edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_xrange_in_for(self):
1486edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """for i in xrange(10):\n    j=i"""
1487edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """for i in range(10):\n    j=i"""
1488edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1489edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1490edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """[i for i in xrange(10)]"""
1491edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """[i for i in range(10)]"""
1492edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1493edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1494edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_range_in_for(self):
1495edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged("for i in range(10): pass")
1496edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged("[i for i in range(10)]")
1497edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1498edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_in_contains_test(self):
1499edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged("x in range(10, 3, 9)")
1500edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1501edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_in_consuming_context(self):
1502edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for call in fixer_util.consuming_calls:
1503edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.unchanged("a = %s(range(10))" % call)
1504edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1505edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_xrange_with_reduce(FixerTestCase):
1506edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1507edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def setUp(self):
1508edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        super(Test_xrange_with_reduce, self).setUp(["xrange", "reduce"])
1509edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1510edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_double_transform(self):
1511edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """reduce(x, xrange(5))"""
1512edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """from functools import reduce
1513edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepreduce(x, range(5))"""
1514edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1515edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1516edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_raw_input(FixerTestCase):
1517edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "raw_input"
1518edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1519edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_prefix_preservation(self):
1520edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x =    raw_input(   )"""
1521edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x =    input(   )"""
1522edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1523edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1524edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = raw_input(   ''   )"""
1525edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = input(   ''   )"""
1526edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1527edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1528edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_1(self):
1529edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = raw_input()"""
1530edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = input()"""
1531edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1532edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1533edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_2(self):
1534edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = raw_input('')"""
1535edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = input('')"""
1536edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1537edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1538edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_3(self):
1539edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = raw_input('prompt')"""
1540edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = input('prompt')"""
1541edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1542edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1543edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_4(self):
1544edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = raw_input(foo(a) + 6)"""
1545edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = input(foo(a) + 6)"""
1546edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1547edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1548edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_5(self):
1549edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = raw_input(invite).split()"""
1550edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = input(invite).split()"""
1551edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1552edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1553edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_6(self):
1554edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = raw_input(invite) . split ()"""
1555edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = input(invite) . split ()"""
1556edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1557edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1558edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_8(self):
1559edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "x = int(raw_input())"
1560edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "x = int(input())"
1561edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1562edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1563edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_funcattrs(FixerTestCase):
1564edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "funcattrs"
1565edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1566edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    attrs = ["closure", "doc", "name", "defaults", "code", "globals", "dict"]
1567edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1568edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test(self):
1569edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for attr in self.attrs:
1570edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            b = "a.func_%s" % attr
1571edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            a = "a.__%s__" % attr
1572edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.check(b, a)
1573edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1574edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            b = "self.foo.func_%s.foo_bar" % attr
1575edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            a = "self.foo.__%s__.foo_bar" % attr
1576edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.check(b, a)
1577edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1578edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged(self):
1579edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for attr in self.attrs:
1580edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            s = "foo(func_%s + 5)" % attr
1581edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.unchanged(s)
1582edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1583edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            s = "f(foo.__%s__)" % attr
1584edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.unchanged(s)
1585edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1586edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            s = "f(foo.__%s__.foo)" % attr
1587edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.unchanged(s)
1588edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1589edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_xreadlines(FixerTestCase):
1590edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "xreadlines"
1591edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1592edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_call(self):
1593edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "for x in f.xreadlines(): pass"
1594edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "for x in f: pass"
1595edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1596edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1597edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "for x in foo().xreadlines(): pass"
1598edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "for x in foo(): pass"
1599edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1600edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1601edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "for x in (5 + foo()).xreadlines(): pass"
1602edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "for x in (5 + foo()): pass"
1603edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1604edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1605edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_attr_ref(self):
1606edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "foo(f.xreadlines + 5)"
1607edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "foo(f.__iter__ + 5)"
1608edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1609edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1610edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "foo(f().xreadlines + 5)"
1611edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "foo(f().__iter__ + 5)"
1612edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1613edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1614edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "foo((5 + f()).xreadlines + 5)"
1615edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "foo((5 + f()).__iter__ + 5)"
1616edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1617edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1618edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged(self):
1619edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = "for x in f.xreadlines(5): pass"
1620edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
1621edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1622edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = "for x in f.xreadlines(k=5): pass"
1623edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
1624edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1625edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = "for x in f.xreadlines(*k, **v): pass"
1626edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
1627edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1628edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = "foo(xreadlines)"
1629edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
1630edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1631edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1632edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass ImportsFixerTests:
1633edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1634edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_import_module(self):
1635edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for old, new in self.modules.items():
1636edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            b = "import %s" % old
1637edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            a = "import %s" % new
1638edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.check(b, a)
1639edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1640edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            b = "import foo, %s, bar" % old
1641edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            a = "import foo, %s, bar" % new
1642edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.check(b, a)
1643edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1644edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_import_from(self):
1645edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for old, new in self.modules.items():
1646edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            b = "from %s import foo" % old
1647edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            a = "from %s import foo" % new
1648edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.check(b, a)
1649edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1650edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            b = "from %s import foo, bar" % old
1651edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            a = "from %s import foo, bar" % new
1652edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.check(b, a)
1653edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1654edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            b = "from %s import (yes, no)" % old
1655edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            a = "from %s import (yes, no)" % new
1656edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.check(b, a)
1657edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1658edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_import_module_as(self):
1659edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for old, new in self.modules.items():
1660edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            b = "import %s as foo_bar" % old
1661edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            a = "import %s as foo_bar" % new
1662edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.check(b, a)
1663edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1664edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            b = "import %s as foo_bar" % old
1665edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            a = "import %s as foo_bar" % new
1666edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.check(b, a)
1667edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1668edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_import_from_as(self):
1669edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for old, new in self.modules.items():
1670edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            b = "from %s import foo as bar" % old
1671edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            a = "from %s import foo as bar" % new
1672edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.check(b, a)
1673edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1674edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_star(self):
1675edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for old, new in self.modules.items():
1676edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            b = "from %s import *" % old
1677edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            a = "from %s import *" % new
1678edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.check(b, a)
1679edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1680edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_import_module_usage(self):
1681edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for old, new in self.modules.items():
1682edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            b = """
1683edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                import %s
1684edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                foo(%s.bar)
1685edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                """ % (old, old)
1686edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            a = """
1687edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                import %s
1688edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                foo(%s.bar)
1689edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                """ % (new, new)
1690edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.check(b, a)
1691edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1692edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            b = """
1693edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                from %s import x
1694edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                %s = 23
1695edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                """ % (old, old)
1696edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            a = """
1697edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                from %s import x
1698edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                %s = 23
1699edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                """ % (new, old)
1700edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.check(b, a)
1701edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1702edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            s = """
1703edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def f():
1704edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    %s.method()
1705edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                """ % (old,)
1706edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.unchanged(s)
1707edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1708edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # test nested usage
1709edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            b = """
1710edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                import %s
1711edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                %s.bar(%s.foo)
1712edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                """ % (old, old, old)
1713edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            a = """
1714edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                import %s
1715edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                %s.bar(%s.foo)
1716edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                """ % (new, new, new)
1717edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.check(b, a)
1718edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1719edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            b = """
1720edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                import %s
1721edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                x.%s
1722edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                """ % (old, old)
1723edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            a = """
1724edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                import %s
1725edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                x.%s
1726edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                """ % (new, old)
1727edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.check(b, a)
1728edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1729edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1730edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_imports(FixerTestCase, ImportsFixerTests):
1731edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "imports"
1732edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    from ..fixes.fix_imports import MAPPING as modules
1733edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1734edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_multiple_imports(self):
1735edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """import urlparse, cStringIO"""
1736edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """import urllib.parse, io"""
1737edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1738edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1739edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_multiple_imports_as(self):
1740edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
1741edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            import copy_reg as bar, HTMLParser as foo, urlparse
1742edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            s = urlparse.spam(bar.foo())
1743edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
1744edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
1745edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            import copyreg as bar, html.parser as foo, urllib.parse
1746edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            s = urllib.parse.spam(bar.foo())
1747edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
1748edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1749edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1750edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1751edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_imports2(FixerTestCase, ImportsFixerTests):
1752edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "imports2"
1753edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    from ..fixes.fix_imports2 import MAPPING as modules
1754edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1755edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1756edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_imports_fixer_order(FixerTestCase, ImportsFixerTests):
1757edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1758edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def setUp(self):
1759edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        super(Test_imports_fixer_order, self).setUp(['imports', 'imports2'])
1760edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        from ..fixes.fix_imports2 import MAPPING as mapping2
1761edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.modules = mapping2.copy()
1762edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        from ..fixes.fix_imports import MAPPING as mapping1
1763edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for key in ('dbhash', 'dumbdbm', 'dbm', 'gdbm'):
1764edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.modules[key] = mapping1[key]
1765edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1766edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_after_local_imports_refactoring(self):
1767edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for fix in ("imports", "imports2"):
1768edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.fixer = fix
1769edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assert_runs_after("import")
1770edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1771edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1772edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_urllib(FixerTestCase):
1773edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "urllib"
1774edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    from ..fixes.fix_urllib import MAPPING as modules
1775edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1776edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_import_module(self):
1777edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for old, changes in self.modules.items():
1778edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            b = "import %s" % old
1779edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            a = "import %s" % ", ".join(map(itemgetter(0), changes))
1780edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.check(b, a)
1781edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1782edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_import_from(self):
1783edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for old, changes in self.modules.items():
1784edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            all_members = []
1785edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            for new, members in changes:
1786edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                for member in members:
1787edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    all_members.append(member)
1788edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    b = "from %s import %s" % (old, member)
1789edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    a = "from %s import %s" % (new, member)
1790edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    self.check(b, a)
1791edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1792edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    s = "from foo import %s" % member
1793edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    self.unchanged(s)
1794edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1795edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                b = "from %s import %s" % (old, ", ".join(members))
1796edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                a = "from %s import %s" % (new, ", ".join(members))
1797edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                self.check(b, a)
1798edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1799edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                s = "from foo import %s" % ", ".join(members)
1800edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                self.unchanged(s)
1801edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1802edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # test the breaking of a module into multiple replacements
1803edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            b = "from %s import %s" % (old, ", ".join(all_members))
1804edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            a = "\n".join(["from %s import %s" % (new, ", ".join(members))
1805edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                            for (new, members) in changes])
1806edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.check(b, a)
1807edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1808edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_import_module_as(self):
1809edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for old in self.modules:
1810edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            s = "import %s as foo" % old
1811edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.warns_unchanged(s, "This module is now multiple modules")
1812edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1813edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_import_from_as(self):
1814edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for old, changes in self.modules.items():
1815edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            for new, members in changes:
1816edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                for member in members:
1817edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    b = "from %s import %s as foo_bar" % (old, member)
1818edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    a = "from %s import %s as foo_bar" % (new, member)
1819edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    self.check(b, a)
1820edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    b = "from %s import %s as blah, %s" % (old, member, member)
1821edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    a = "from %s import %s as blah, %s" % (new, member, member)
1822edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    self.check(b, a)
1823edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1824edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_star(self):
1825edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for old in self.modules:
1826edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            s = "from %s import *" % old
1827edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.warns_unchanged(s, "Cannot handle star imports")
1828edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1829edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_indented(self):
1830edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
1831edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdef foo():
1832edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    from urllib import urlencode, urlopen
1833edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep"""
1834edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
1835edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdef foo():
1836edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    from urllib.parse import urlencode
1837edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    from urllib.request import urlopen
1838edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep"""
1839edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1840edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1841edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
1842edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdef foo():
1843edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    other()
1844edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    from urllib import urlencode, urlopen
1845edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep"""
1846edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
1847edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdef foo():
1848edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    other()
1849edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    from urllib.parse import urlencode
1850edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    from urllib.request import urlopen
1851edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep"""
1852edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1853edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1854edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1855edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1856edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_import_module_usage(self):
1857edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for old, changes in self.modules.items():
1858edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            for new, members in changes:
1859edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                for member in members:
1860edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    new_import = ", ".join([n for (n, mems)
1861edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                            in self.modules[old]])
1862edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    b = """
1863edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                        import %s
1864edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                        foo(%s.%s)
1865edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                        """ % (old, old, member)
1866edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    a = """
1867edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                        import %s
1868edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                        foo(%s.%s)
1869edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                        """ % (new_import, new, member)
1870edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    self.check(b, a)
1871edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    b = """
1872edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                        import %s
1873edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                        %s.%s(%s.%s)
1874edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                        """ % (old, old, member, old, member)
1875edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    a = """
1876edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                        import %s
1877edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                        %s.%s(%s.%s)
1878edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                        """ % (new_import, new, member, new, member)
1879edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    self.check(b, a)
1880edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1881edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1882edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_input(FixerTestCase):
1883edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "input"
1884edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1885edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_prefix_preservation(self):
1886edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x =   input(   )"""
1887edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x =   eval(input(   ))"""
1888edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1889edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1890edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = input(   ''   )"""
1891edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = eval(input(   ''   ))"""
1892edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1893edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1894edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_trailing_comment(self):
1895edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = input()  #  foo"""
1896edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = eval(input())  #  foo"""
1897edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1898edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1899edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_idempotency(self):
1900edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """x = eval(input())"""
1901edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
1902edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1903edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """x = eval(input(''))"""
1904edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
1905edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1906edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """x = eval(input(foo(5) + 9))"""
1907edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
1908edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1909edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_1(self):
1910edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = input()"""
1911edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = eval(input())"""
1912edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1913edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1914edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_2(self):
1915edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = input('')"""
1916edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = eval(input(''))"""
1917edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1918edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1919edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_3(self):
1920edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = input('prompt')"""
1921edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = eval(input('prompt'))"""
1922edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1923edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1924edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_4(self):
1925edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = input(foo(5) + 9)"""
1926edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = eval(input(foo(5) + 9))"""
1927edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1928edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1929edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_tuple_params(FixerTestCase):
1930edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "tuple_params"
1931edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1932edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_1(self):
1933edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """def foo(): pass"""
1934edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
1935edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1936edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_2(self):
1937edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """def foo(a, b, c): pass"""
1938edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
1939edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1940edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_3(self):
1941edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """def foo(a=3, b=4, c=5): pass"""
1942edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
1943edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1944edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_1(self):
1945edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
1946edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def foo(((a, b), c)):
1947edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                x = 5"""
1948edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1949edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
1950edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def foo(xxx_todo_changeme):
1951edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                ((a, b), c) = xxx_todo_changeme
1952edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                x = 5"""
1953edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1954edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1955edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_2(self):
1956edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
1957edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def foo(((a, b), c), d):
1958edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                x = 5"""
1959edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1960edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
1961edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def foo(xxx_todo_changeme, d):
1962edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                ((a, b), c) = xxx_todo_changeme
1963edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                x = 5"""
1964edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1965edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1966edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_3(self):
1967edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
1968edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def foo(((a, b), c), d) -> e:
1969edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                x = 5"""
1970edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1971edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
1972edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def foo(xxx_todo_changeme, d) -> e:
1973edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                ((a, b), c) = xxx_todo_changeme
1974edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                x = 5"""
1975edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1976edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1977edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_semicolon(self):
1978edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
1979edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def foo(((a, b), c)): x = 5; y = 7"""
1980edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1981edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
1982edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def foo(xxx_todo_changeme): ((a, b), c) = xxx_todo_changeme; x = 5; y = 7"""
1983edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1984edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1985edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_keywords(self):
1986edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
1987edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def foo(((a, b), c), d, e=5) -> z:
1988edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                x = 5"""
1989edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1990edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
1991edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def foo(xxx_todo_changeme, d, e=5) -> z:
1992edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                ((a, b), c) = xxx_todo_changeme
1993edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                x = 5"""
1994edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
1995edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1996edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_varargs(self):
1997edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
1998edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def foo(((a, b), c), d, *vargs, **kwargs) -> z:
1999edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                x = 5"""
2000edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2001edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
2002edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def foo(xxx_todo_changeme, d, *vargs, **kwargs) -> z:
2003edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                ((a, b), c) = xxx_todo_changeme
2004edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                x = 5"""
2005edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2006edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2007edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_multi_1(self):
2008edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
2009edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def foo(((a, b), c), (d, e, f)) -> z:
2010edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                x = 5"""
2011edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2012edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
2013edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def foo(xxx_todo_changeme, xxx_todo_changeme1) -> z:
2014edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                ((a, b), c) = xxx_todo_changeme
2015edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                (d, e, f) = xxx_todo_changeme1
2016edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                x = 5"""
2017edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2018edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2019edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_multi_2(self):
2020edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
2021edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def foo(x, ((a, b), c), d, (e, f, g), y) -> z:
2022edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                x = 5"""
2023edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2024edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
2025edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def foo(x, xxx_todo_changeme, d, xxx_todo_changeme1, y) -> z:
2026edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                ((a, b), c) = xxx_todo_changeme
2027edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                (e, f, g) = xxx_todo_changeme1
2028edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                x = 5"""
2029edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2030edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2031edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_docstring(self):
2032edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
2033edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def foo(((a, b), c), (d, e, f)) -> z:
2034edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                "foo foo foo foo"
2035edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                x = 5"""
2036edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2037edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
2038edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def foo(xxx_todo_changeme, xxx_todo_changeme1) -> z:
2039edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                "foo foo foo foo"
2040edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                ((a, b), c) = xxx_todo_changeme
2041edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                (d, e, f) = xxx_todo_changeme1
2042edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                x = 5"""
2043edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2044edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2045edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_lambda_no_change(self):
2046edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """lambda x: x + 5"""
2047edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
2048edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2049edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_lambda_parens_single_arg(self):
2050edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """lambda (x): x + 5"""
2051edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """lambda x: x + 5"""
2052edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2053edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2054edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """lambda(x): x + 5"""
2055edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """lambda x: x + 5"""
2056edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2057edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2058edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """lambda ((((x)))): x + 5"""
2059edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """lambda x: x + 5"""
2060edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2061edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2062edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """lambda((((x)))): x + 5"""
2063edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """lambda x: x + 5"""
2064edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2065edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2066edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_lambda_simple(self):
2067edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """lambda (x, y): x + f(y)"""
2068edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """lambda x_y: x_y[0] + f(x_y[1])"""
2069edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2070edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2071edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """lambda(x, y): x + f(y)"""
2072edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """lambda x_y: x_y[0] + f(x_y[1])"""
2073edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2074edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2075edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """lambda (((x, y))): x + f(y)"""
2076edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """lambda x_y: x_y[0] + f(x_y[1])"""
2077edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2078edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2079edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """lambda(((x, y))): x + f(y)"""
2080edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """lambda x_y: x_y[0] + f(x_y[1])"""
2081edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2082edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2083edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_lambda_one_tuple(self):
2084edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """lambda (x,): x + f(x)"""
2085edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """lambda x1: x1[0] + f(x1[0])"""
2086edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2087edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2088edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """lambda (((x,))): x + f(x)"""
2089edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """lambda x1: x1[0] + f(x1[0])"""
2090edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2091edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2092edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_lambda_simple_multi_use(self):
2093edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """lambda (x, y): x + x + f(x) + x"""
2094edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """lambda x_y: x_y[0] + x_y[0] + f(x_y[0]) + x_y[0]"""
2095edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2096edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2097edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_lambda_simple_reverse(self):
2098edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """lambda (x, y): y + x"""
2099edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """lambda x_y: x_y[1] + x_y[0]"""
2100edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2101edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2102edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_lambda_nested(self):
2103edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """lambda (x, (y, z)): x + y + z"""
2104edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """lambda x_y_z: x_y_z[0] + x_y_z[1][0] + x_y_z[1][1]"""
2105edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2106edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2107edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """lambda (((x, (y, z)))): x + y + z"""
2108edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """lambda x_y_z: x_y_z[0] + x_y_z[1][0] + x_y_z[1][1]"""
2109edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2110edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2111edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_lambda_nested_multi_use(self):
2112edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """lambda (x, (y, z)): x + y + f(y)"""
2113edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """lambda x_y_z: x_y_z[0] + x_y_z[1][0] + f(x_y_z[1][0])"""
2114edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2115edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2116edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_methodattrs(FixerTestCase):
2117edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "methodattrs"
2118edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2119edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    attrs = ["func", "self", "class"]
2120edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2121edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test(self):
2122edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for attr in self.attrs:
2123edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            b = "a.im_%s" % attr
2124edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if attr == "class":
2125edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                a = "a.__self__.__class__"
2126edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            else:
2127edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                a = "a.__%s__" % attr
2128edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.check(b, a)
2129edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2130edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            b = "self.foo.im_%s.foo_bar" % attr
2131edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if attr == "class":
2132edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                a = "self.foo.__self__.__class__.foo_bar"
2133edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            else:
2134edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                a = "self.foo.__%s__.foo_bar" % attr
2135edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.check(b, a)
2136edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2137edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged(self):
2138edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for attr in self.attrs:
2139edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            s = "foo(im_%s + 5)" % attr
2140edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.unchanged(s)
2141edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2142edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            s = "f(foo.__%s__)" % attr
2143edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.unchanged(s)
2144edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2145edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            s = "f(foo.__%s__.foo)" % attr
2146edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.unchanged(s)
2147edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2148edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_next(FixerTestCase):
2149edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "next"
2150edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2151edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_1(self):
2152edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """it.next()"""
2153edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """next(it)"""
2154edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2155edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2156edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_2(self):
2157edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """a.b.c.d.next()"""
2158edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """next(a.b.c.d)"""
2159edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2160edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2161edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_3(self):
2162edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """(a + b).next()"""
2163edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """next((a + b))"""
2164edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2165edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2166edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_4(self):
2167edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """a().next()"""
2168edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """next(a())"""
2169edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2170edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2171edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_5(self):
2172edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """a().next() + b"""
2173edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """next(a()) + b"""
2174edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2175edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2176edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_6(self):
2177edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """c(      a().next() + b)"""
2178edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """c(      next(a()) + b)"""
2179edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2180edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2181edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_prefix_preservation_1(self):
2182edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
2183edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            for a in b:
2184edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                foo(a)
2185edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                a.next()
2186edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2187edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
2188edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            for a in b:
2189edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                foo(a)
2190edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                next(a)
2191edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2192edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2193edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2194edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_prefix_preservation_2(self):
2195edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
2196edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            for a in b:
2197edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                foo(a) # abc
2198edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                # def
2199edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                a.next()
2200edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2201edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
2202edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            for a in b:
2203edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                foo(a) # abc
2204edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                # def
2205edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                next(a)
2206edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2207edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2208edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2209edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_prefix_preservation_3(self):
2210edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
2211edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            next = 5
2212edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            for a in b:
2213edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                foo(a)
2214edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                a.next()
2215edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2216edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
2217edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            next = 5
2218edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            for a in b:
2219edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                foo(a)
2220edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                a.__next__()
2221edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2222edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a, ignore_warnings=True)
2223edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2224edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_prefix_preservation_4(self):
2225edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
2226edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            next = 5
2227edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            for a in b:
2228edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                foo(a) # abc
2229edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                # def
2230edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                a.next()
2231edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2232edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
2233edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            next = 5
2234edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            for a in b:
2235edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                foo(a) # abc
2236edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                # def
2237edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                a.__next__()
2238edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2239edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a, ignore_warnings=True)
2240edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2241edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_prefix_preservation_5(self):
2242edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
2243edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            next = 5
2244edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            for a in b:
2245edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                foo(foo(a), # abc
2246edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    a.next())
2247edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2248edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
2249edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            next = 5
2250edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            for a in b:
2251edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                foo(foo(a), # abc
2252edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    a.__next__())
2253edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2254edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a, ignore_warnings=True)
2255edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2256edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_prefix_preservation_6(self):
2257edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
2258edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            for a in b:
2259edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                foo(foo(a), # abc
2260edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    a.next())
2261edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2262edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
2263edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            for a in b:
2264edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                foo(foo(a), # abc
2265edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    next(a))
2266edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2267edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2268edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2269edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_method_1(self):
2270edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
2271edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A:
2272edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def next(self):
2273edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2274edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2275edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
2276edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A:
2277edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def __next__(self):
2278edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2279edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2280edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2281edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2282edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_method_2(self):
2283edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
2284edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A(object):
2285edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def next(self):
2286edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2287edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2288edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
2289edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A(object):
2290edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def __next__(self):
2291edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2292edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2293edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2294edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2295edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_method_3(self):
2296edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
2297edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A:
2298edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def next(x):
2299edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2300edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2301edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
2302edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A:
2303edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def __next__(x):
2304edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2305edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2306edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2307edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2308edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_method_4(self):
2309edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
2310edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A:
2311edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def __init__(self, foo):
2312edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    self.foo = foo
2313edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2314edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def next(self):
2315edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2316edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2317edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def __iter__(self):
2318edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    return self
2319edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2320edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
2321edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A:
2322edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def __init__(self, foo):
2323edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    self.foo = foo
2324edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2325edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def __next__(self):
2326edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2327edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2328edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def __iter__(self):
2329edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    return self
2330edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2331edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2332edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2333edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_method_unchanged(self):
2334edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
2335edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A:
2336edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def next(self, a, b):
2337edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2338edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2339edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
2340edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2341edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_shadowing_assign_simple(self):
2342edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
2343edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            next = foo
2344edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2345edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A:
2346edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def next(self, a, b):
2347edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2348edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2349edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
2350edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2351edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_shadowing_assign_tuple_1(self):
2352edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
2353edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            (next, a) = foo
2354edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2355edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A:
2356edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def next(self, a, b):
2357edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2358edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2359edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
2360edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2361edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_shadowing_assign_tuple_2(self):
2362edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
2363edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            (a, (b, (next, c)), a) = foo
2364edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2365edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A:
2366edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def next(self, a, b):
2367edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2368edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2369edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
2370edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2371edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_shadowing_assign_list_1(self):
2372edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
2373edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            [next, a] = foo
2374edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2375edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A:
2376edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def next(self, a, b):
2377edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2378edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2379edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
2380edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2381edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_shadowing_assign_list_2(self):
2382edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
2383edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            [a, [b, [next, c]], a] = foo
2384edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2385edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A:
2386edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def next(self, a, b):
2387edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2388edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2389edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
2390edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2391edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_builtin_assign(self):
2392edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
2393edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def foo():
2394edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                __builtin__.next = foo
2395edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2396edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A:
2397edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def next(self, a, b):
2398edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2399edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2400edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
2401edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2402edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_builtin_assign_in_tuple(self):
2403edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
2404edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def foo():
2405edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                (a, __builtin__.next) = foo
2406edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2407edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A:
2408edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def next(self, a, b):
2409edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2410edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2411edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
2412edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2413edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_builtin_assign_in_list(self):
2414edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
2415edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def foo():
2416edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                [a, __builtin__.next] = foo
2417edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2418edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A:
2419edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def next(self, a, b):
2420edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2421edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2422edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
2423edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2424edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_assign_to_next(self):
2425edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
2426edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def foo():
2427edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                A.next = foo
2428edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2429edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A:
2430edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def next(self, a, b):
2431edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2432edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2433edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
2434edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2435edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_assign_to_next_in_tuple(self):
2436edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
2437edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def foo():
2438edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                (a, A.next) = foo
2439edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2440edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A:
2441edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def next(self, a, b):
2442edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2443edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2444edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
2445edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2446edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_assign_to_next_in_list(self):
2447edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
2448edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def foo():
2449edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                [a, A.next] = foo
2450edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2451edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A:
2452edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def next(self, a, b):
2453edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2454edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2455edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
2456edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2457edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_shadowing_import_1(self):
2458edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
2459edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            import foo.bar as next
2460edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2461edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A:
2462edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def next(self, a, b):
2463edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2464edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2465edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
2466edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2467edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_shadowing_import_2(self):
2468edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
2469edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            import bar, bar.foo as next
2470edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2471edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A:
2472edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def next(self, a, b):
2473edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2474edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2475edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
2476edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2477edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_shadowing_import_3(self):
2478edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
2479edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            import bar, bar.foo as next, baz
2480edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2481edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A:
2482edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def next(self, a, b):
2483edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2484edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2485edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
2486edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2487edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_shadowing_import_from_1(self):
2488edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
2489edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            from x import next
2490edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2491edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A:
2492edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def next(self, a, b):
2493edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2494edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2495edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
2496edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2497edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_shadowing_import_from_2(self):
2498edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
2499edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            from x.a import next
2500edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2501edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A:
2502edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def next(self, a, b):
2503edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2504edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2505edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
2506edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2507edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_shadowing_import_from_3(self):
2508edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
2509edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            from x import a, next, b
2510edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2511edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A:
2512edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def next(self, a, b):
2513edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2514edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2515edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
2516edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2517edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_shadowing_import_from_4(self):
2518edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
2519edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            from x.a import a, next, b
2520edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2521edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A:
2522edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def next(self, a, b):
2523edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2524edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2525edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
2526edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2527edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_shadowing_funcdef_1(self):
2528edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
2529edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def next(a):
2530edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
2531edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2532edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A:
2533edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def next(self, a, b):
2534edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2535edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2536edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
2537edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2538edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_shadowing_funcdef_2(self):
2539edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
2540edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def next(a):
2541edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
2542edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2543edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A:
2544edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def next(self):
2545edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2546edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2547edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            it.next()
2548edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2549edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
2550edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def next(a):
2551edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
2552edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2553edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A:
2554edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def __next__(self):
2555edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2556edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2557edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            it.__next__()
2558edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2559edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns(b, a, "Calls to builtin next() possibly shadowed")
2560edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2561edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_shadowing_global_1(self):
2562edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
2563edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def f():
2564edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                global next
2565edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                next = 5
2566edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2567edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
2568edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2569edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_shadowing_global_2(self):
2570edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
2571edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def f():
2572edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                global a, next, b
2573edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                next = 5
2574edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2575edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
2576edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2577edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_shadowing_for_simple(self):
2578edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
2579edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            for next in it():
2580edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
2581edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2582edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            b = 5
2583edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            c = 6
2584edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2585edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
2586edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2587edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_shadowing_for_tuple_1(self):
2588edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
2589edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            for next, b in it():
2590edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
2591edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2592edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            b = 5
2593edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            c = 6
2594edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2595edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
2596edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2597edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_shadowing_for_tuple_2(self):
2598edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
2599edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            for a, (next, c), b in it():
2600edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
2601edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2602edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            b = 5
2603edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            c = 6
2604edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2605edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
2606edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2607edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_noncall_access_1(self):
2608edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """gnext = g.next"""
2609edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """gnext = g.__next__"""
2610edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2611edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2612edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_noncall_access_2(self):
2613edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """f(g.next + 5)"""
2614edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """f(g.__next__ + 5)"""
2615edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2616edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2617edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_noncall_access_3(self):
2618edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """f(g().next + 5)"""
2619edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """f(g().__next__ + 5)"""
2620edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2621edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2622edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_nonzero(FixerTestCase):
2623edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "nonzero"
2624edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2625edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_1(self):
2626edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
2627edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A:
2628edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def __nonzero__(self):
2629edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2630edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2631edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
2632edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A:
2633edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def __bool__(self):
2634edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2635edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2636edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2637edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2638edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_2(self):
2639edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
2640edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A(object):
2641edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def __nonzero__(self):
2642edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2643edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2644edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
2645edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A(object):
2646edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def __bool__(self):
2647edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2648edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2649edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2650edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2651edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_1(self):
2652edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
2653edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A(object):
2654edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def __bool__(self):
2655edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2656edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2657edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
2658edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2659edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_2(self):
2660edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
2661edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            class A(object):
2662edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                def __nonzero__(self, a):
2663edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    pass
2664edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2665edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
2666edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2667edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_func(self):
2668edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
2669edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def __nonzero__(self):
2670edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
2671edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
2672edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
2673edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2674edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_numliterals(FixerTestCase):
2675edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "numliterals"
2676edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2677edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_octal_1(self):
2678edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """0755"""
2679edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """0o755"""
2680edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2681edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2682edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_long_int_1(self):
2683edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """a = 12L"""
2684edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """a = 12"""
2685edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2686edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2687edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_long_int_2(self):
2688edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """a = 12l"""
2689edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """a = 12"""
2690edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2691edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2692edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_long_hex(self):
2693edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """b = 0x12l"""
2694edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """b = 0x12"""
2695edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2696edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2697edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_comments_and_spacing(self):
2698edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """b =   0x12L"""
2699edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """b =   0x12"""
2700edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2701edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2702edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """b = 0755 # spam"""
2703edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """b = 0o755 # spam"""
2704edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2705edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2706edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_int(self):
2707edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """5"""
2708edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
2709edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2710edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_float(self):
2711edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """5.0"""
2712edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
2713edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2714edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_octal(self):
2715edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """0o755"""
2716edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
2717edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2718edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_hex(self):
2719edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """0xABC"""
2720edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
2721edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2722edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_exp(self):
2723edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """5.0e10"""
2724edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
2725edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2726edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_complex_int(self):
2727edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """5 + 4j"""
2728edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
2729edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2730edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_complex_float(self):
2731edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """5.4 + 4.9j"""
2732edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
2733edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2734edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_complex_bare(self):
2735edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """4j"""
2736edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
2737edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """4.4j"""
2738edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
2739edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2740edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_renames(FixerTestCase):
2741edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "renames"
2742edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2743edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    modules = {"sys":  ("maxint", "maxsize"),
2744edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep              }
2745edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2746edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_import_from(self):
2747edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for mod, (old, new) in self.modules.items():
2748edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            b = "from %s import %s" % (mod, old)
2749edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            a = "from %s import %s" % (mod, new)
2750edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.check(b, a)
2751edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2752edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            s = "from foo import %s" % old
2753edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.unchanged(s)
2754edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2755edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_import_from_as(self):
2756edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for mod, (old, new) in self.modules.items():
2757edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            b = "from %s import %s as foo_bar" % (mod, old)
2758edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            a = "from %s import %s as foo_bar" % (mod, new)
2759edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.check(b, a)
2760edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2761edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_import_module_usage(self):
2762edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for mod, (old, new) in self.modules.items():
2763edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            b = """
2764edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                import %s
2765edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                foo(%s, %s.%s)
2766edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                """ % (mod, mod, mod, old)
2767edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            a = """
2768edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                import %s
2769edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                foo(%s, %s.%s)
2770edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                """ % (mod, mod, mod, new)
2771edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.check(b, a)
2772edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2773edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def XXX_test_from_import_usage(self):
2774edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # not implemented yet
2775edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for mod, (old, new) in self.modules.items():
2776edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            b = """
2777edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                from %s import %s
2778edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                foo(%s, %s)
2779edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                """ % (mod, old, mod, old)
2780edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            a = """
2781edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                from %s import %s
2782edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                foo(%s, %s)
2783edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                """ % (mod, new, mod, new)
2784edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.check(b, a)
2785edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2786edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_unicode(FixerTestCase):
2787edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "unicode"
2788edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2789edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_whitespace(self):
2790edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """unicode( x)"""
2791edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """str( x)"""
2792edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2793edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2794edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """ unicode(x )"""
2795edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """ str(x )"""
2796edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2797edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2798edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """ u'h'"""
2799edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """ 'h'"""
2800edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2801edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2802edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unicode_call(self):
2803edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """unicode(x, y, z)"""
2804edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """str(x, y, z)"""
2805edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2806edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2807edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unichr(self):
2808edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """unichr(u'h')"""
2809edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """chr('h')"""
2810edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2811edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2812edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unicode_literal_1(self):
2813edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = '''u"x"'''
2814edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = '''"x"'''
2815edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2816edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2817edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unicode_literal_2(self):
2818edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """ur'x'"""
2819edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """r'x'"""
2820edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2821edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2822edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unicode_literal_3(self):
2823edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """UR'''x''' """
2824edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """R'''x''' """
2825edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2826edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2827edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_callable(FixerTestCase):
2828edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "callable"
2829edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2830edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_prefix_preservation(self):
2831edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """callable(    x)"""
2832edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """import collections\nisinstance(    x, collections.Callable)"""
2833edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2834edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2835edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """if     callable(x): pass"""
2836edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """import collections
2837edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepif     isinstance(x, collections.Callable): pass"""
2838edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2839edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2840edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_callable_call(self):
2841edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """callable(x)"""
2842edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """import collections\nisinstance(x, collections.Callable)"""
2843edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2844edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2845edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_global_import(self):
2846edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
2847edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdef spam(foo):
2848edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    callable(foo)"""[1:]
2849edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
2850edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepimport collections
2851edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdef spam(foo):
2852edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    isinstance(foo, collections.Callable)"""[1:]
2853edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2854edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2855edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
2856edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepimport collections
2857edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdef spam(foo):
2858edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    callable(foo)"""[1:]
2859edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # same output if it was already imported
2860edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2861edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2862edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
2863edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepfrom collections import *
2864edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdef spam(foo):
2865edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    callable(foo)"""[1:]
2866edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
2867edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepfrom collections import *
2868edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepimport collections
2869edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdef spam(foo):
2870edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    isinstance(foo, collections.Callable)"""[1:]
2871edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2872edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2873edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
2874edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdo_stuff()
2875edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdo_some_other_stuff()
2876edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepassert callable(do_stuff)"""[1:]
2877edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
2878edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepimport collections
2879edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdo_stuff()
2880edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdo_some_other_stuff()
2881edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepassert isinstance(do_stuff, collections.Callable)"""[1:]
2882edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2883edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2884edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
2885edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepif isinstance(do_stuff, Callable):
2886edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    assert callable(do_stuff)
2887edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    do_stuff(do_stuff)
2888edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    if not callable(do_stuff):
2889edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        exit(1)
2890edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    else:
2891edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        assert callable(do_stuff)
2892edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepelse:
2893edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    assert not callable(do_stuff)"""[1:]
2894edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
2895edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepimport collections
2896edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepif isinstance(do_stuff, Callable):
2897edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    assert isinstance(do_stuff, collections.Callable)
2898edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    do_stuff(do_stuff)
2899edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    if not isinstance(do_stuff, collections.Callable):
2900edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        exit(1)
2901edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    else:
2902edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        assert isinstance(do_stuff, collections.Callable)
2903edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepelse:
2904edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    assert not isinstance(do_stuff, collections.Callable)"""[1:]
2905edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2906edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2907edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_callable_should_not_change(self):
2908edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """callable(*x)"""
2909edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
2910edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2911edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """callable(x, y)"""
2912edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
2913edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2914edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """callable(x, kw=y)"""
2915edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
2916edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2917edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """callable()"""
2918edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
2919edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2920edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_filter(FixerTestCase):
2921edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "filter"
2922edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2923edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_prefix_preservation(self):
2924edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x =   filter(    foo,     'abc'   )"""
2925edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x =   list(filter(    foo,     'abc'   ))"""
2926edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2927edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2928edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x =   filter(  None , 'abc'  )"""
2929edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x =   [_f for _f in 'abc' if _f]"""
2930edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2931edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2932edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_filter_basic(self):
2933edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = filter(None, 'abc')"""
2934edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = [_f for _f in 'abc' if _f]"""
2935edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2936edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2937edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = len(filter(f, 'abc'))"""
2938edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = len(list(filter(f, 'abc')))"""
2939edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2940edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2941edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = filter(lambda x: x%2 == 0, range(10))"""
2942edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = [x for x in range(10) if x%2 == 0]"""
2943edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2944edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2945edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # Note the parens around x
2946edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = filter(lambda (x): x%2 == 0, range(10))"""
2947edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = [x for x in range(10) if x%2 == 0]"""
2948edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
2949edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2950edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # XXX This (rare) case is not supported
2951edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep##         b = """x = filter(f, 'abc')[0]"""
2952edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep##         a = """x = list(filter(f, 'abc'))[0]"""
2953edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep##         self.check(b, a)
2954edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2955edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_filter_nochange(self):
2956edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """b.join(filter(f, 'abc'))"""
2957edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
2958edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """(a + foo(5)).join(filter(f, 'abc'))"""
2959edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
2960edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """iter(filter(f, 'abc'))"""
2961edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
2962edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """list(filter(f, 'abc'))"""
2963edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
2964edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """list(filter(f, 'abc'))[0]"""
2965edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
2966edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """set(filter(f, 'abc'))"""
2967edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
2968edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """set(filter(f, 'abc')).pop()"""
2969edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
2970edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """tuple(filter(f, 'abc'))"""
2971edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
2972edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """any(filter(f, 'abc'))"""
2973edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
2974edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """all(filter(f, 'abc'))"""
2975edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
2976edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """sum(filter(f, 'abc'))"""
2977edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
2978edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """sorted(filter(f, 'abc'))"""
2979edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
2980edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """sorted(filter(f, 'abc'), key=blah)"""
2981edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
2982edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """sorted(filter(f, 'abc'), key=blah)[0]"""
2983edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
2984edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """enumerate(filter(f, 'abc'))"""
2985edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
2986edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """enumerate(filter(f, 'abc'), start=1)"""
2987edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
2988edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """for i in filter(f, 'abc'): pass"""
2989edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
2990edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """[x for x in filter(f, 'abc')]"""
2991edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
2992edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """(x for x in filter(f, 'abc'))"""
2993edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
2994edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2995edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_future_builtins(self):
2996edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "from future_builtins import spam, filter; filter(f, 'ham')"
2997edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
2998edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2999edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """from future_builtins import spam; x = filter(f, 'abc')"""
3000edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """from future_builtins import spam; x = list(filter(f, 'abc'))"""
3001edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3002edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3003edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "from future_builtins import *; filter(f, 'ham')"
3004edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3005edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3006edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_map(FixerTestCase):
3007edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "map"
3008edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3009edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def check(self, b, a):
3010edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged("from future_builtins import map; " + b, a)
3011edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        super(Test_map, self).check(b, a)
3012edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3013edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_prefix_preservation(self):
3014edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x =    map(   f,    'abc'   )"""
3015edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x =    list(map(   f,    'abc'   ))"""
3016edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3017edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3018edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_trailing_comment(self):
3019edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = map(f, 'abc')   #   foo"""
3020edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = list(map(f, 'abc'))   #   foo"""
3021edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3022edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3023edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_None_with_multiple_arguments(self):
3024edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """x = map(None, a, b, c)"""
3025edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, "cannot convert map(None, ...) with "
3026edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                             "multiple arguments")
3027edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3028edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_map_basic(self):
3029edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = map(f, 'abc')"""
3030edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = list(map(f, 'abc'))"""
3031edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3032edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3033edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = len(map(f, 'abc', 'def'))"""
3034edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = len(list(map(f, 'abc', 'def')))"""
3035edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3036edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3037edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = map(None, 'abc')"""
3038edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = list('abc')"""
3039edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3040edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3041edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = map(lambda x: x+1, range(4))"""
3042edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = [x+1 for x in range(4)]"""
3043edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3044edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3045edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # Note the parens around x
3046edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = map(lambda (x): x+1, range(4))"""
3047edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = [x+1 for x in range(4)]"""
3048edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3049edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3050edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
3051edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            foo()
3052edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # foo
3053edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            map(f, x)
3054edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3055edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
3056edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            foo()
3057edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # foo
3058edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            list(map(f, x))
3059edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3060edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns(b, a, "You should use a for loop here")
3061edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3062edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # XXX This (rare) case is not supported
3063edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep##         b = """x = map(f, 'abc')[0]"""
3064edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep##         a = """x = list(map(f, 'abc'))[0]"""
3065edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep##         self.check(b, a)
3066edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3067edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_map_nochange(self):
3068edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """b.join(map(f, 'abc'))"""
3069edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3070edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """(a + foo(5)).join(map(f, 'abc'))"""
3071edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3072edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """iter(map(f, 'abc'))"""
3073edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3074edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """list(map(f, 'abc'))"""
3075edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3076edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """list(map(f, 'abc'))[0]"""
3077edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3078edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """set(map(f, 'abc'))"""
3079edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3080edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """set(map(f, 'abc')).pop()"""
3081edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3082edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """tuple(map(f, 'abc'))"""
3083edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3084edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """any(map(f, 'abc'))"""
3085edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3086edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """all(map(f, 'abc'))"""
3087edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3088edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """sum(map(f, 'abc'))"""
3089edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3090edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """sorted(map(f, 'abc'))"""
3091edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3092edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """sorted(map(f, 'abc'), key=blah)"""
3093edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3094edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """sorted(map(f, 'abc'), key=blah)[0]"""
3095edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3096edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """enumerate(map(f, 'abc'))"""
3097edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3098edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """enumerate(map(f, 'abc'), start=1)"""
3099edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3100edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """for i in map(f, 'abc'): pass"""
3101edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3102edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """[x for x in map(f, 'abc')]"""
3103edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3104edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """(x for x in map(f, 'abc'))"""
3105edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3106edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3107edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_future_builtins(self):
3108edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "from future_builtins import spam, map, eggs; map(f, 'ham')"
3109edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3110edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3111edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """from future_builtins import spam, eggs; x = map(f, 'abc')"""
3112edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """from future_builtins import spam, eggs; x = list(map(f, 'abc'))"""
3113edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3114edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3115edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "from future_builtins import *; map(f, 'ham')"
3116edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3117edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3118edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_zip(FixerTestCase):
3119edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "zip"
3120edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3121edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def check(self, b, a):
3122edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged("from future_builtins import zip; " + b, a)
3123edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        super(Test_zip, self).check(b, a)
3124edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3125edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_zip_basic(self):
3126edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = zip(a, b, c)"""
3127edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = list(zip(a, b, c))"""
3128edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3129edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3130edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = len(zip(a, b))"""
3131edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = len(list(zip(a, b)))"""
3132edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3133edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3134edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_zip_nochange(self):
3135edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """b.join(zip(a, b))"""
3136edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3137edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """(a + foo(5)).join(zip(a, b))"""
3138edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3139edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """iter(zip(a, b))"""
3140edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3141edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """list(zip(a, b))"""
3142edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3143edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """list(zip(a, b))[0]"""
3144edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3145edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """set(zip(a, b))"""
3146edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3147edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """set(zip(a, b)).pop()"""
3148edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3149edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """tuple(zip(a, b))"""
3150edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3151edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """any(zip(a, b))"""
3152edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3153edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """all(zip(a, b))"""
3154edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3155edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """sum(zip(a, b))"""
3156edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3157edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """sorted(zip(a, b))"""
3158edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3159edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """sorted(zip(a, b), key=blah)"""
3160edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3161edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """sorted(zip(a, b), key=blah)[0]"""
3162edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3163edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """enumerate(zip(a, b))"""
3164edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3165edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """enumerate(zip(a, b), start=1)"""
3166edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3167edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """for i in zip(a, b): pass"""
3168edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3169edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """[x for x in zip(a, b)]"""
3170edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3171edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """(x for x in zip(a, b))"""
3172edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3173edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3174edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_future_builtins(self):
3175edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "from future_builtins import spam, zip, eggs; zip(a, b)"
3176edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3177edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3178edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """from future_builtins import spam, eggs; x = zip(a, b)"""
3179edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """from future_builtins import spam, eggs; x = list(zip(a, b))"""
3180edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3181edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3182edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "from future_builtins import *; zip(a, b)"
3183edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3184edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3185edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_standarderror(FixerTestCase):
3186edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "standarderror"
3187edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3188edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test(self):
3189edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x =    StandardError()"""
3190edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x =    Exception()"""
3191edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3192edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3193edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = StandardError(a, b, c)"""
3194edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = Exception(a, b, c)"""
3195edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3196edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3197edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """f(2 + StandardError(a, b, c))"""
3198edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """f(2 + Exception(a, b, c))"""
3199edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3200edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3201edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_types(FixerTestCase):
3202edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "types"
3203edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3204edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_basic_types_convert(self):
3205edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """types.StringType"""
3206edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """bytes"""
3207edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3208edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3209edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """types.DictType"""
3210edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """dict"""
3211edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3212edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3213edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """types . IntType"""
3214edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """int"""
3215edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3216edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3217edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """types.ListType"""
3218edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """list"""
3219edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3220edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3221edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """types.LongType"""
3222edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """int"""
3223edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3224edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3225edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """types.NoneType"""
3226edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """type(None)"""
3227edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3228edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3229edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_idioms(FixerTestCase):
3230edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "idioms"
3231edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3232edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_while(self):
3233edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """while 1: foo()"""
3234edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """while True: foo()"""
3235edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3236edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3237edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """while   1: foo()"""
3238edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """while   True: foo()"""
3239edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3240edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3241edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
3242edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            while 1:
3243edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                foo()
3244edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3245edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
3246edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            while True:
3247edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                foo()
3248edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3249edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3250edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3251edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_while_unchanged(self):
3252edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """while 11: foo()"""
3253edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
3254edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3255edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """while 0: foo()"""
3256edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
3257edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3258edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """while foo(): foo()"""
3259edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
3260edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3261edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """while []: foo()"""
3262edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
3263edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3264edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_eq_simple(self):
3265edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """type(x) == T"""
3266edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """isinstance(x, T)"""
3267edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3268edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3269edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """if   type(x) == T: pass"""
3270edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """if   isinstance(x, T): pass"""
3271edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3272edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3273edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_eq_reverse(self):
3274edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """T == type(x)"""
3275edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """isinstance(x, T)"""
3276edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3277edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3278edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """if   T == type(x): pass"""
3279edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """if   isinstance(x, T): pass"""
3280edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3281edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3282edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_eq_expression(self):
3283edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """type(x+y) == d.get('T')"""
3284edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """isinstance(x+y, d.get('T'))"""
3285edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3286edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3287edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """type(   x  +  y) == d.get('T')"""
3288edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """isinstance(x  +  y, d.get('T'))"""
3289edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3290edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3291edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_is_simple(self):
3292edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """type(x) is T"""
3293edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """isinstance(x, T)"""
3294edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3295edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3296edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """if   type(x) is T: pass"""
3297edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """if   isinstance(x, T): pass"""
3298edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3299edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3300edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_is_reverse(self):
3301edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """T is type(x)"""
3302edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """isinstance(x, T)"""
3303edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3304edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3305edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """if   T is type(x): pass"""
3306edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """if   isinstance(x, T): pass"""
3307edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3308edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3309edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_is_expression(self):
3310edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """type(x+y) is d.get('T')"""
3311edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """isinstance(x+y, d.get('T'))"""
3312edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3313edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3314edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """type(   x  +  y) is d.get('T')"""
3315edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """isinstance(x  +  y, d.get('T'))"""
3316edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3317edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3318edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_is_not_simple(self):
3319edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """type(x) is not T"""
3320edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """not isinstance(x, T)"""
3321edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3322edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3323edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """if   type(x) is not T: pass"""
3324edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """if   not isinstance(x, T): pass"""
3325edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3326edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3327edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_is_not_reverse(self):
3328edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """T is not type(x)"""
3329edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """not isinstance(x, T)"""
3330edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3331edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3332edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """if   T is not type(x): pass"""
3333edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """if   not isinstance(x, T): pass"""
3334edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3335edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3336edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_is_not_expression(self):
3337edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """type(x+y) is not d.get('T')"""
3338edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """not isinstance(x+y, d.get('T'))"""
3339edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3340edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3341edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """type(   x  +  y) is not d.get('T')"""
3342edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """not isinstance(x  +  y, d.get('T'))"""
3343edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3344edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3345edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_ne_simple(self):
3346edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """type(x) != T"""
3347edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """not isinstance(x, T)"""
3348edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3349edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3350edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """if   type(x) != T: pass"""
3351edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """if   not isinstance(x, T): pass"""
3352edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3353edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3354edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_ne_reverse(self):
3355edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """T != type(x)"""
3356edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """not isinstance(x, T)"""
3357edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3358edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3359edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """if   T != type(x): pass"""
3360edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """if   not isinstance(x, T): pass"""
3361edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3362edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3363edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_ne_expression(self):
3364edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """type(x+y) != d.get('T')"""
3365edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """not isinstance(x+y, d.get('T'))"""
3366edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3367edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3368edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """type(   x  +  y) != d.get('T')"""
3369edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """not isinstance(x  +  y, d.get('T'))"""
3370edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3371edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3372edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_type_unchanged(self):
3373edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """type(x).__name__"""
3374edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(a)
3375edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3376edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_sort_list_call(self):
3377edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
3378edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v = list(t)
3379edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v.sort()
3380edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            foo(v)
3381edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3382edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
3383edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v = sorted(t)
3384edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            foo(v)
3385edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3386edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3387edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3388edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
3389edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v = list(foo(b) + d)
3390edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v.sort()
3391edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            foo(v)
3392edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3393edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
3394edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v = sorted(foo(b) + d)
3395edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            foo(v)
3396edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3397edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3398edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3399edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
3400edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            while x:
3401edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                v = list(t)
3402edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                v.sort()
3403edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                foo(v)
3404edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3405edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
3406edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            while x:
3407edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                v = sorted(t)
3408edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                foo(v)
3409edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3410edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3411edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3412edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
3413edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v = list(t)
3414edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # foo
3415edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v.sort()
3416edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            foo(v)
3417edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3418edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
3419edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v = sorted(t)
3420edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # foo
3421edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            foo(v)
3422edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3423edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3424edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3425edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = r"""
3426edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v = list(   t)
3427edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v.sort()
3428edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            foo(v)
3429edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3430edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = r"""
3431edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v = sorted(   t)
3432edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            foo(v)
3433edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3434edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3435edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3436edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = r"""
3437edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
3438edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                m = list(s)
3439edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                m.sort()
3440edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except: pass
3441edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3442edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3443edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = r"""
3444edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
3445edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                m = sorted(s)
3446edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except: pass
3447edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3448edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3449edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3450edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = r"""
3451edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
3452edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                m = list(s)
3453edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                # foo
3454edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                m.sort()
3455edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except: pass
3456edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3457edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3458edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = r"""
3459edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
3460edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                m = sorted(s)
3461edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                # foo
3462edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except: pass
3463edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3464edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3465edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3466edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = r"""
3467edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            m = list(s)
3468edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # more comments
3469edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            m.sort()"""
3470edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3471edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = r"""
3472edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            m = sorted(s)
3473edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # more comments"""
3474edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3475edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3476edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_sort_simple_expr(self):
3477edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
3478edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v = t
3479edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v.sort()
3480edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            foo(v)
3481edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3482edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
3483edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v = sorted(t)
3484edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            foo(v)
3485edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3486edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3487edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3488edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
3489edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v = foo(b)
3490edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v.sort()
3491edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            foo(v)
3492edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3493edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
3494edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v = sorted(foo(b))
3495edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            foo(v)
3496edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3497edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3498edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3499edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
3500edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v = b.keys()
3501edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v.sort()
3502edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            foo(v)
3503edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3504edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
3505edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v = sorted(b.keys())
3506edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            foo(v)
3507edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3508edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3509edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3510edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
3511edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v = foo(b) + d
3512edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v.sort()
3513edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            foo(v)
3514edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3515edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
3516edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v = sorted(foo(b) + d)
3517edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            foo(v)
3518edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3519edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3520edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3521edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
3522edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            while x:
3523edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                v = t
3524edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                v.sort()
3525edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                foo(v)
3526edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3527edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
3528edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            while x:
3529edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                v = sorted(t)
3530edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                foo(v)
3531edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3532edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3533edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3534edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
3535edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v = t
3536edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # foo
3537edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v.sort()
3538edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            foo(v)
3539edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3540edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
3541edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v = sorted(t)
3542edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # foo
3543edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            foo(v)
3544edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3545edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3546edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3547edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = r"""
3548edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v =   t
3549edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v.sort()
3550edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            foo(v)
3551edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3552edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = r"""
3553edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v =   sorted(t)
3554edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            foo(v)
3555edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3556edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3557edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3558edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_sort_unchanged(self):
3559edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
3560edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v = list(t)
3561edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            w.sort()
3562edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            foo(w)
3563edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3564edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
3565edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3566edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
3567edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v = list(t)
3568edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            v.sort(u)
3569edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            foo(v)
3570edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3571edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
3572edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3573edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_basestring(FixerTestCase):
3574edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "basestring"
3575edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3576edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_basestring(self):
3577edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """isinstance(x, basestring)"""
3578edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """isinstance(x, str)"""
3579edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3580edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3581edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_buffer(FixerTestCase):
3582edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "buffer"
3583edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3584edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_buffer(self):
3585edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """x = buffer(y)"""
3586edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """x = memoryview(y)"""
3587edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3588edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3589edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_slicing(self):
3590edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """buffer(y)[4:5]"""
3591edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """memoryview(y)[4:5]"""
3592edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3593edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3594edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_future(FixerTestCase):
3595edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "future"
3596edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3597edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_future(self):
3598edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """from __future__ import braces"""
3599edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """"""
3600edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3601edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3602edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """# comment\nfrom __future__ import braces"""
3603edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """# comment\n"""
3604edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3605edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3606edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """from __future__ import braces\n# comment"""
3607edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """\n# comment"""
3608edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3609edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3610edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_run_order(self):
3611edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assert_runs_after('print')
3612edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3613edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_itertools(FixerTestCase):
3614edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "itertools"
3615edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3616edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def checkall(self, before, after):
3617edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # Because we need to check with and without the itertools prefix
3618edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # and on each of the three functions, these loops make it all
3619edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # much easier
3620edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for i in ('itertools.', ''):
3621edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            for f in ('map', 'filter', 'zip'):
3622edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                b = before %(i+'i'+f)
3623edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                a = after %(f)
3624edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                self.check(b, a)
3625edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3626edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_0(self):
3627edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # A simple example -- test_1 covers exactly the same thing,
3628edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # but it's not quite as clear.
3629edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "itertools.izip(a, b)"
3630edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "zip(a, b)"
3631edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3632edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3633edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_1(self):
3634edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """%s(f, a)"""
3635edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """%s(f, a)"""
3636edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.checkall(b, a)
3637edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3638edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_qualified(self):
3639edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """itertools.ifilterfalse(a, b)"""
3640edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """itertools.filterfalse(a, b)"""
3641edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3642edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3643edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """itertools.izip_longest(a, b)"""
3644edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """itertools.zip_longest(a, b)"""
3645edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3646edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3647edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_2(self):
3648edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """ifilterfalse(a, b)"""
3649edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """filterfalse(a, b)"""
3650edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3651edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3652edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """izip_longest(a, b)"""
3653edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """zip_longest(a, b)"""
3654edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3655edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3656edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_space_1(self):
3657edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """    %s(f, a)"""
3658edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """    %s(f, a)"""
3659edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.checkall(b, a)
3660edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3661edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_space_2(self):
3662edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """    itertools.ifilterfalse(a, b)"""
3663edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """    itertools.filterfalse(a, b)"""
3664edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3665edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3666edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """    itertools.izip_longest(a, b)"""
3667edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """    itertools.zip_longest(a, b)"""
3668edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3669edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3670edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_run_order(self):
3671edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assert_runs_after('map', 'zip', 'filter')
3672edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3673edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3674edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_itertools_imports(FixerTestCase):
3675edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = 'itertools_imports'
3676edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3677edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_reduced(self):
3678edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "from itertools import imap, izip, foo"
3679edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "from itertools import foo"
3680edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3681edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3682edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "from itertools import bar, imap, izip, foo"
3683edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "from itertools import bar, foo"
3684edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3685edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3686edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "from itertools import chain, imap, izip"
3687edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "from itertools import chain"
3688edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3689edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3690edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_comments(self):
3691edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "#foo\nfrom itertools import imap, izip"
3692edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "#foo\n"
3693edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3694edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3695edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_none(self):
3696edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "from itertools import imap, izip"
3697edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = ""
3698edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3699edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3700edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "from itertools import izip"
3701edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = ""
3702edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3703edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3704edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_import_as(self):
3705edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "from itertools import izip, bar as bang, imap"
3706edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "from itertools import bar as bang"
3707edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3708edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3709edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "from itertools import izip as _zip, imap, bar"
3710edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "from itertools import bar"
3711edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3712edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3713edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "from itertools import imap as _map"
3714edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = ""
3715edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3716edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3717edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "from itertools import imap as _map, izip as _zip"
3718edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = ""
3719edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3720edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3721edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = "from itertools import bar as bang"
3722edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
3723edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3724edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_ifilter_and_zip_longest(self):
3725edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for name in "filterfalse", "zip_longest":
3726edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            b = "from itertools import i%s" % (name,)
3727edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            a = "from itertools import %s" % (name,)
3728edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.check(b, a)
3729edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3730edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            b = "from itertools import imap, i%s, foo" % (name,)
3731edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            a = "from itertools import %s, foo" % (name,)
3732edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.check(b, a)
3733edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3734edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            b = "from itertools import bar, i%s, foo" % (name,)
3735edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            a = "from itertools import bar, %s, foo" % (name,)
3736edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.check(b, a)
3737edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3738edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_import_star(self):
3739edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = "from itertools import *"
3740edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
3741edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3742edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3743edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged(self):
3744edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = "from itertools import foo"
3745edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
3746edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3747edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3748edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_import(FixerTestCase):
3749edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "import"
3750edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3751edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def setUp(self):
3752edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        super(Test_import, self).setUp()
3753edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # Need to replace fix_import's exists method
3754edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # so we can check that it's doing the right thing
3755edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.files_checked = []
3756edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.present_files = set()
3757edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.always_exists = True
3758edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def fake_exists(name):
3759edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.files_checked.append(name)
3760edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return self.always_exists or (name in self.present_files)
3761edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3762edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        from lib2to3.fixes import fix_import
3763edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        fix_import.exists = fake_exists
3764edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3765edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tearDown(self):
3766edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        from lib2to3.fixes import fix_import
3767edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        fix_import.exists = os.path.exists
3768edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3769edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def check_both(self, b, a):
3770edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.always_exists = True
3771edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        super(Test_import, self).check(b, a)
3772edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.always_exists = False
3773edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        super(Test_import, self).unchanged(b)
3774edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3775edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_files_checked(self):
3776edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def p(path):
3777edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # Takes a unix path and returns a path with correct separators
3778edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return os.path.pathsep.join(path.split("/"))
3779edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3780edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.always_exists = False
3781edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.present_files = set(['__init__.py'])
3782edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        expected_extensions = ('.py', os.path.sep, '.pyc', '.so', '.sl', '.pyd')
3783edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        names_to_test = (p("/spam/eggs.py"), "ni.py", p("../../shrubbery.py"))
3784edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3785edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for name in names_to_test:
3786edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.files_checked = []
3787edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.filename = name
3788edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.unchanged("import jam")
3789edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3790edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if os.path.dirname(name):
3791edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                name = os.path.dirname(name) + '/jam'
3792edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            else:
3793edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                name = 'jam'
3794edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            expected_checks = set(name + ext for ext in expected_extensions)
3795edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            expected_checks.add("__init__.py")
3796edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3797edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertEqual(set(self.files_checked), expected_checks)
3798edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3799edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_not_in_package(self):
3800edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = "import bar"
3801edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.always_exists = False
3802edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.present_files = set(["bar.py"])
3803edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
3804edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3805edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_with_absolute_import_enabled(self):
3806edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = "from __future__ import absolute_import\nimport bar"
3807edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.always_exists = False
3808edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.present_files = set(["__init__.py", "bar.py"])
3809edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
3810edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3811edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_in_package(self):
3812edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "import bar"
3813edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "from . import bar"
3814edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.always_exists = False
3815edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.present_files = set(["__init__.py", "bar.py"])
3816edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3817edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3818edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_import_from_package(self):
3819edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "import bar"
3820edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "from . import bar"
3821edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.always_exists = False
3822edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.present_files = set(["__init__.py", "bar" + os.path.sep])
3823edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3824edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3825edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_already_relative_import(self):
3826edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = "from . import bar"
3827edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
3828edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3829edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_comments_and_indent(self):
3830edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "import bar # Foo"
3831edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "from . import bar # Foo"
3832edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3833edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3834edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_from(self):
3835edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "from foo import bar, baz"
3836edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "from .foo import bar, baz"
3837edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check_both(b, a)
3838edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3839edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "from foo import bar"
3840edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "from .foo import bar"
3841edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check_both(b, a)
3842edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3843edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "from foo import (bar, baz)"
3844edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "from .foo import (bar, baz)"
3845edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check_both(b, a)
3846edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3847edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_dotted_from(self):
3848edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "from green.eggs import ham"
3849edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "from .green.eggs import ham"
3850edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check_both(b, a)
3851edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3852edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_from_as(self):
3853edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "from green.eggs import ham as spam"
3854edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "from .green.eggs import ham as spam"
3855edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check_both(b, a)
3856edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3857edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_import(self):
3858edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "import foo"
3859edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "from . import foo"
3860edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check_both(b, a)
3861edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3862edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "import foo, bar"
3863edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "from . import foo, bar"
3864edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check_both(b, a)
3865edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3866edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "import foo, bar, x"
3867edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "from . import foo, bar, x"
3868edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check_both(b, a)
3869edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3870edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "import x, y, z"
3871edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "from . import x, y, z"
3872edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check_both(b, a)
3873edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3874edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_import_as(self):
3875edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "import foo as x"
3876edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "from . import foo as x"
3877edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check_both(b, a)
3878edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3879edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "import a as b, b as c, c as d"
3880edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "from . import a as b, b as c, c as d"
3881edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check_both(b, a)
3882edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3883edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_local_and_absolute(self):
3884edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.always_exists = False
3885edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.present_files = set(["foo.py", "__init__.py"])
3886edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3887edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = "import foo, bar"
3888edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, "absolute and local imports together")
3889edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3890edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_dotted_import(self):
3891edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "import foo.bar"
3892edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "from . import foo.bar"
3893edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check_both(b, a)
3894edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3895edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_dotted_import_as(self):
3896edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "import foo.bar as bang"
3897edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "from . import foo.bar as bang"
3898edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check_both(b, a)
3899edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3900edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_prefix(self):
3901edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
3902edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # prefix
3903edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        import foo.bar
3904edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
3905edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
3906edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # prefix
3907edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        from . import foo.bar
3908edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
3909edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check_both(b, a)
3910edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3911edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3912edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_set_literal(FixerTestCase):
3913edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3914edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "set_literal"
3915edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3916edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_basic(self):
3917edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """set([1, 2, 3])"""
3918edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """{1, 2, 3}"""
3919edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3920edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3921edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """set((1, 2, 3))"""
3922edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """{1, 2, 3}"""
3923edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3924edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3925edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """set((1,))"""
3926edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """{1}"""
3927edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3928edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3929edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """set([1])"""
3930edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3931edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3932edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """set((a, b))"""
3933edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """{a, b}"""
3934edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3935edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3936edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """set([a, b])"""
3937edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3938edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3939edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """set((a*234, f(args=23)))"""
3940edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """{a*234, f(args=23)}"""
3941edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3942edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3943edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """set([a*23, f(23)])"""
3944edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """{a*23, f(23)}"""
3945edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3946edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3947edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """set([a-234**23])"""
3948edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """{a-234**23}"""
3949edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3950edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3951edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_listcomps(self):
3952edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """set([x for x in y])"""
3953edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """{x for x in y}"""
3954edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3955edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3956edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """set([x for x in y if x == m])"""
3957edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """{x for x in y if x == m}"""
3958edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3959edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3960edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """set([x for x in y for a in b])"""
3961edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """{x for x in y for a in b}"""
3962edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3963edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3964edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """set([f(x) - 23 for x in y])"""
3965edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """{f(x) - 23 for x in y}"""
3966edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3967edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3968edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_whitespace(self):
3969edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """set( [1, 2])"""
3970edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """{1, 2}"""
3971edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3972edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3973edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """set([1 ,  2])"""
3974edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """{1 ,  2}"""
3975edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3976edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3977edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """set([ 1 ])"""
3978edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """{ 1 }"""
3979edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3980edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3981edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """set( [1] )"""
3982edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """{1}"""
3983edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3984edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3985edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """set([  1,  2  ])"""
3986edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """{  1,  2  }"""
3987edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3988edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3989edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """set([x  for x in y ])"""
3990edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """{x  for x in y }"""
3991edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3992edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3993edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """set(
3994edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                   [1, 2]
3995edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep               )
3996edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
3997edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """{1, 2}\n"""
3998edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
3999edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4000edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_comments(self):
4001edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """set((1, 2)) # Hi"""
4002edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """{1, 2} # Hi"""
4003edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4004edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4005edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # This isn't optimal behavior, but the fixer is optional.
4006edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
4007edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # Foo
4008edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            set( # Bar
4009edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep               (1, 2)
4010edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            )
4011edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
4012edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
4013edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # Foo
4014edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            {1, 2}
4015edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
4016edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4017edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4018edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged(self):
4019edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """set()"""
4020edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
4021edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4022edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """set(a)"""
4023edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
4024edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4025edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """set(a, b, c)"""
4026edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
4027edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4028edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # Don't transform generators because they might have to be lazy.
4029edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """set(x for x in y)"""
4030edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
4031edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4032edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """set(x for x in y if z)"""
4033edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
4034edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4035edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """set(a*823-23**2 + f(23))"""
4036edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
4037edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4038edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4039edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_sys_exc(FixerTestCase):
4040edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "sys_exc"
4041edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4042edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_0(self):
4043edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "sys.exc_type"
4044edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "sys.exc_info()[0]"
4045edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4046edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4047edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_1(self):
4048edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "sys.exc_value"
4049edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "sys.exc_info()[1]"
4050edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4051edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4052edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_2(self):
4053edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "sys.exc_traceback"
4054edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "sys.exc_info()[2]"
4055edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4056edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4057edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_3(self):
4058edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "sys.exc_type # Foo"
4059edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "sys.exc_info()[0] # Foo"
4060edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4061edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4062edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_4(self):
4063edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "sys.  exc_type"
4064edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "sys.  exc_info()[0]"
4065edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4066edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4067edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_5(self):
4068edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "sys  .exc_type"
4069edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "sys  .exc_info()[0]"
4070edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4071edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4072edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4073edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_paren(FixerTestCase):
4074edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "paren"
4075edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4076edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_0(self):
4077edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """[i for i in 1, 2 ]"""
4078edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """[i for i in (1, 2) ]"""
4079edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4080edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4081edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_1(self):
4082edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """[i for i in 1, 2, ]"""
4083edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """[i for i in (1, 2,) ]"""
4084edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4085edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4086edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_2(self):
4087edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """[i for i  in     1, 2 ]"""
4088edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """[i for i  in     (1, 2) ]"""
4089edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4090edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4091edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_3(self):
4092edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """[i for i in 1, 2 if i]"""
4093edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """[i for i in (1, 2) if i]"""
4094edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4095edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4096edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_4(self):
4097edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """[i for i in 1,    2    ]"""
4098edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """[i for i in (1,    2)    ]"""
4099edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4100edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4101edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_5(self):
4102edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """(i for i in 1, 2)"""
4103edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """(i for i in (1, 2))"""
4104edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4105edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4106edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_6(self):
4107edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """(i for i in 1   ,2   if i)"""
4108edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """(i for i in (1   ,2)   if i)"""
4109edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4110edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4111edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_0(self):
4112edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """[i for i in (1, 2)]"""
4113edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
4114edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4115edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_1(self):
4116edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """[i for i in foo()]"""
4117edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
4118edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4119edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_2(self):
4120edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """[i for i in (1, 2) if nothing]"""
4121edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
4122edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4123edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_3(self):
4124edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """(i for i in (1, 2))"""
4125edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
4126edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4127edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged_4(self):
4128edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """[i for i in m]"""
4129edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
4130edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4131edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_metaclass(FixerTestCase):
4132edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4133edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = 'metaclass'
4134edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4135edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged(self):
4136edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged("class X(): pass")
4137edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged("class X(object): pass")
4138edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged("class X(object1, object2): pass")
4139edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged("class X(object1, object2, object3): pass")
4140edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged("class X(metaclass=Meta): pass")
4141edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged("class X(b, arg=23, metclass=Meta): pass")
4142edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged("class X(b, arg=23, metaclass=Meta, other=42): pass")
4143edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4144edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
4145edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class X:
4146edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def __metaclass__(self): pass
4147edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
4148edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
4149edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4150edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """
4151edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class X:
4152edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            a[23] = 74
4153edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
4154edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
4155edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4156edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_comments(self):
4157edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
4158edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class X:
4159edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # hi
4160edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            __metaclass__ = AppleMeta
4161edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
4162edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
4163edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class X(metaclass=AppleMeta):
4164edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # hi
4165edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass
4166edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
4167edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4168edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4169edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
4170edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class X:
4171edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            __metaclass__ = Meta
4172edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # Bedtime!
4173edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
4174edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
4175edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class X(metaclass=Meta):
4176edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass
4177edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # Bedtime!
4178edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
4179edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4180edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4181edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_meta(self):
4182edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # no-parent class, odd body
4183edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
4184edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class X():
4185edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            __metaclass__ = Q
4186edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass
4187edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
4188edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
4189edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class X(metaclass=Q):
4190edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass
4191edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
4192edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4193edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4194edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # one parent class, no body
4195edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """class X(object): __metaclass__ = Q"""
4196edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """class X(object, metaclass=Q): pass"""
4197edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4198edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4199edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4200edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # one parent, simple body
4201edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
4202edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class X(object):
4203edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            __metaclass__ = Meta
4204edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            bar = 7
4205edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
4206edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
4207edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class X(object, metaclass=Meta):
4208edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            bar = 7
4209edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
4210edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4211edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4212edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
4213edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class X:
4214edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            __metaclass__ = Meta; x = 4; g = 23
4215edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
4216edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
4217edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class X(metaclass=Meta):
4218edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            x = 4; g = 23
4219edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
4220edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4221edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4222edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # one parent, simple body, __metaclass__ last
4223edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
4224edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class X(object):
4225edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            bar = 7
4226edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            __metaclass__ = Meta
4227edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
4228edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
4229edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class X(object, metaclass=Meta):
4230edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            bar = 7
4231edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
4232edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4233edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4234edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # redefining __metaclass__
4235edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
4236edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class X():
4237edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            __metaclass__ = A
4238edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            __metaclass__ = B
4239edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            bar = 7
4240edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
4241edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
4242edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class X(metaclass=B):
4243edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            bar = 7
4244edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
4245edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4246edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4247edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # multiple inheritance, simple body
4248edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
4249edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class X(clsA, clsB):
4250edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            __metaclass__ = Meta
4251edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            bar = 7
4252edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
4253edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
4254edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class X(clsA, clsB, metaclass=Meta):
4255edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            bar = 7
4256edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
4257edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4258edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4259edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # keywords in the class statement
4260edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """class m(a, arg=23): __metaclass__ = Meta"""
4261edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """class m(a, arg=23, metaclass=Meta): pass"""
4262edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4263edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4264edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
4265edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class X(expression(2 + 4)):
4266edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            __metaclass__ = Meta
4267edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
4268edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
4269edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class X(expression(2 + 4), metaclass=Meta):
4270edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass
4271edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
4272edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4273edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4274edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
4275edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class X(expression(2 + 4), x**4):
4276edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            __metaclass__ = Meta
4277edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
4278edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
4279edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class X(expression(2 + 4), x**4, metaclass=Meta):
4280edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass
4281edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
4282edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4283edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4284edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
4285edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class X:
4286edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            __metaclass__ = Meta
4287edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            save.py = 23
4288edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
4289edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
4290edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class X(metaclass=Meta):
4291edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            save.py = 23
4292edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
4293edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4294edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4295edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4296edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_getcwdu(FixerTestCase):
4297edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4298edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = 'getcwdu'
4299edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4300edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_basic(self):
4301edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """os.getcwdu"""
4302edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """os.getcwd"""
4303edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4304edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4305edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """os.getcwdu()"""
4306edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """os.getcwd()"""
4307edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4308edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4309edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """meth = os.getcwdu"""
4310edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """meth = os.getcwd"""
4311edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4312edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4313edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """os.getcwdu(args)"""
4314edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """os.getcwd(args)"""
4315edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4316edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4317edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_comment(self):
4318edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """os.getcwdu() # Foo"""
4319edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """os.getcwd() # Foo"""
4320edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4321edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4322edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged(self):
4323edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """os.getcwd()"""
4324edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
4325edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4326edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """getcwdu()"""
4327edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
4328edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4329edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """os.getcwdb()"""
4330edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
4331edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4332edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_indentation(self):
4333edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
4334edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if 1:
4335edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                os.getcwdu()
4336edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
4337edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
4338edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if 1:
4339edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                os.getcwd()
4340edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
4341edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4342edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4343edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_multilation(self):
4344edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """os .getcwdu()"""
4345edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """os .getcwd()"""
4346edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4347edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4348edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """os.  getcwdu"""
4349edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """os.  getcwd"""
4350edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4351edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4352edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """os.getcwdu (  )"""
4353edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """os.getcwd (  )"""
4354edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4355edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4356edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4357edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_operator(FixerTestCase):
4358edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4359edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "operator"
4360edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4361edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_operator_isCallable(self):
4362edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "operator.isCallable(x)"
4363edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "hasattr(x, '__call__')"
4364edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4365edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4366edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_operator_sequenceIncludes(self):
4367edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "operator.sequenceIncludes(x, y)"
4368edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "operator.contains(x, y)"
4369edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4370edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4371edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "operator .sequenceIncludes(x, y)"
4372edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "operator .contains(x, y)"
4373edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4374edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4375edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "operator.  sequenceIncludes(x, y)"
4376edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "operator.  contains(x, y)"
4377edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4378edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4379edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_operator_isSequenceType(self):
4380edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "operator.isSequenceType(x)"
4381edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "import collections\nisinstance(x, collections.Sequence)"
4382edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4383edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4384edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_operator_isMappingType(self):
4385edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "operator.isMappingType(x)"
4386edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "import collections\nisinstance(x, collections.Mapping)"
4387edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4388edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4389edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_operator_isNumberType(self):
4390edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "operator.isNumberType(x)"
4391edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "import numbers\nisinstance(x, numbers.Number)"
4392edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4393edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4394edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_operator_repeat(self):
4395edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "operator.repeat(x, n)"
4396edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "operator.mul(x, n)"
4397edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4398edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4399edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "operator .repeat(x, n)"
4400edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "operator .mul(x, n)"
4401edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4402edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4403edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "operator.  repeat(x, n)"
4404edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "operator.  mul(x, n)"
4405edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4406edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4407edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_operator_irepeat(self):
4408edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "operator.irepeat(x, n)"
4409edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "operator.imul(x, n)"
4410edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4411edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4412edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "operator .irepeat(x, n)"
4413edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "operator .imul(x, n)"
4414edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4415edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4416edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = "operator.  irepeat(x, n)"
4417edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = "operator.  imul(x, n)"
4418edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4419edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4420edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_bare_isCallable(self):
4421edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = "isCallable(x)"
4422edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        t = "You should use 'hasattr(x, '__call__')' here."
4423edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, t)
4424edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4425edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_bare_sequenceIncludes(self):
4426edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = "sequenceIncludes(x, y)"
4427edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        t = "You should use 'operator.contains(x, y)' here."
4428edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, t)
4429edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4430edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_bare_operator_isSequenceType(self):
4431edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = "isSequenceType(z)"
4432edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        t = "You should use 'isinstance(z, collections.Sequence)' here."
4433edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, t)
4434edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4435edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_bare_operator_isMappingType(self):
4436edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = "isMappingType(x)"
4437edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        t = "You should use 'isinstance(x, collections.Mapping)' here."
4438edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, t)
4439edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4440edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_bare_operator_isNumberType(self):
4441edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = "isNumberType(y)"
4442edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        t = "You should use 'isinstance(y, numbers.Number)' here."
4443edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, t)
4444edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4445edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_bare_operator_repeat(self):
4446edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = "repeat(x, n)"
4447edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        t = "You should use 'operator.mul(x, n)' here."
4448edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, t)
4449edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4450edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_bare_operator_irepeat(self):
4451edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = "irepeat(y, 187)"
4452edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        t = "You should use 'operator.imul(y, 187)' here."
4453edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns_unchanged(s, t)
4454edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4455edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4456edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Test_exitfunc(FixerTestCase):
4457edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4458edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    fixer = "exitfunc"
4459edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4460edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_simple(self):
4461edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
4462edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            import sys
4463edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            sys.exitfunc = my_atexit
4464edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
4465edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
4466edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            import sys
4467edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            import atexit
4468edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            atexit.register(my_atexit)
4469edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
4470edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4471edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4472edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_names_import(self):
4473edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
4474edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            import sys, crumbs
4475edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            sys.exitfunc = my_func
4476edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
4477edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
4478edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            import sys, crumbs, atexit
4479edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            atexit.register(my_func)
4480edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
4481edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4482edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4483edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_complex_expression(self):
4484edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
4485edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            import sys
4486edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            sys.exitfunc = do(d)/a()+complex(f=23, g=23)*expression
4487edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
4488edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
4489edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            import sys
4490edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            import atexit
4491edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            atexit.register(do(d)/a()+complex(f=23, g=23)*expression)
4492edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
4493edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4494edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4495edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_comments(self):
4496edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
4497edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            import sys # Foo
4498edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            sys.exitfunc = f # Blah
4499edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
4500edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
4501edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            import sys
4502edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            import atexit # Foo
4503edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            atexit.register(f) # Blah
4504edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
4505edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4506edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4507edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
4508edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            import apples, sys, crumbs, larry # Pleasant comments
4509edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            sys.exitfunc = func
4510edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
4511edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
4512edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            import apples, sys, crumbs, larry, atexit # Pleasant comments
4513edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            atexit.register(func)
4514edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
4515edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4516edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4517edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_in_a_function(self):
4518edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """
4519edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            import sys
4520edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def f():
4521edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                sys.exitfunc = func
4522edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """
4523edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """
4524edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            import sys
4525edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            import atexit
4526edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def f():
4527edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                atexit.register(func)
4528edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep             """
4529edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.check(b, a)
4530edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4531edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_no_sys_import(self):
4532edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = """sys.exitfunc = f"""
4533edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = """atexit.register(f)"""
4534edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        msg = ("Can't find sys import; Please add an atexit import at the "
4535edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            "top of your file.")
4536edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.warns(b, a, msg)
4537edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4538edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4539edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_unchanged(self):
4540edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = """f(sys.exitfunc)"""
4541edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.unchanged(s)
4542