1 | n/a | """Fixer that replaces deprecated unittest method names.""" |
---|
2 | n/a | |
---|
3 | n/a | # Author: Ezio Melotti |
---|
4 | n/a | |
---|
5 | n/a | from ..fixer_base import BaseFix |
---|
6 | n/a | from ..fixer_util import Name |
---|
7 | n/a | |
---|
8 | n/a | NAMES = dict( |
---|
9 | n/a | assert_="assertTrue", |
---|
10 | n/a | assertEquals="assertEqual", |
---|
11 | n/a | assertNotEquals="assertNotEqual", |
---|
12 | n/a | assertAlmostEquals="assertAlmostEqual", |
---|
13 | n/a | assertNotAlmostEquals="assertNotAlmostEqual", |
---|
14 | n/a | assertRegexpMatches="assertRegex", |
---|
15 | n/a | assertRaisesRegexp="assertRaisesRegex", |
---|
16 | n/a | failUnlessEqual="assertEqual", |
---|
17 | n/a | failIfEqual="assertNotEqual", |
---|
18 | n/a | failUnlessAlmostEqual="assertAlmostEqual", |
---|
19 | n/a | failIfAlmostEqual="assertNotAlmostEqual", |
---|
20 | n/a | failUnless="assertTrue", |
---|
21 | n/a | failUnlessRaises="assertRaises", |
---|
22 | n/a | failIf="assertFalse", |
---|
23 | n/a | ) |
---|
24 | n/a | |
---|
25 | n/a | |
---|
26 | n/a | class FixAsserts(BaseFix): |
---|
27 | n/a | |
---|
28 | n/a | PATTERN = """ |
---|
29 | n/a | power< any+ trailer< '.' meth=(%s)> any* > |
---|
30 | n/a | """ % '|'.join(map(repr, NAMES)) |
---|
31 | n/a | |
---|
32 | n/a | def transform(self, node, results): |
---|
33 | n/a | name = results["meth"][0] |
---|
34 | n/a | name.replace(Name(NAMES[str(name)], prefix=name.prefix)) |
---|