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