def test_normalizing_parameters_for_args_parameter_and_keywords(self):
     self.mod.write('def a_func(param, *args):\n    pass\na_func(*[1, 2, 3])\n')
     signature = ChangeSignature(self.project, self.mod,
                                 self.mod.read().index('a_func') + 1)
     signature.normalize().do()
     self.assertEquals('def a_func(param, *args):\n    pass\n'
                       'a_func(*[1, 2, 3])\n', self.mod.read())
 def test_normalizing_parameters_for_unsorted_keyword(self):
     self.mod.write('def a_func(p1, p2):\n    pass\na_func(p2=2, p1=1)')
     signature = ChangeSignature(self.project, self.mod,
                                 self.mod.read().index('a_func') + 1)
     signature.normalize().do()
     self.assertEquals('def a_func(p1, p2):\n    pass\na_func(1, 2)',
                       self.mod.read())
 def test_normalizing_parameters_for_trivial_case2(self):
     code = 'def a_func(param):\n    pass\na_func(2)'
     self.mod.write(code)
     signature = ChangeSignature(self.project, self.mod,
                                 self.mod.read().index('a_func') + 1)
     signature.normalize().do()
     self.assertEquals(code, self.mod.read())
 def test_normalizing_parameters_for_keyword_parameters(self):
     self.mod.write('def a_func(p1, **kwds):\n    pass\n'
                    'a_func(p2=2, p1=1)\n')
     signature = ChangeSignature(self.project, self.mod,
                                 self.mod.read().index('a_func') + 1)
     signature.normalize().do()
     self.assertEquals('def a_func(p1, **kwds):\n    pass\n'
                       'a_func(1, p2=2)\n', self.mod.read())
 def test_normalizing_functions_from_other_modules(self):
     mod1 = testutils.create_module(self.project, 'mod1')
     mod1.write('def a_func(param):\n    pass\n')
     self.mod.write('import mod1\nmod1.a_func(param=1)\n')
     signature = ChangeSignature(self.project, mod1,
                                 mod1.read().index('a_func') + 1)
     signature.normalize().do()
     self.assertEquals('import mod1\nmod1.a_func(1)\n', self.mod.read())
 def test_preserving_args_and_keywords_order(self):
     self.mod.write('def a_func(*args, **kwds):\n    pass\n'
                    'a_func(3, 1, 2, a=1, c=3, b=2)\n')
     signature = ChangeSignature(self.project, self.mod,
                                 self.mod.read().index('a_func') + 1)
     signature.normalize().do()
     self.assertEquals('def a_func(*args, **kwds):\n    pass\n'
                       'a_func(3, 1, 2, a=1, c=3, b=2)\n', self.mod.read())
 def test_normalizing_parameters_for_unneeded_keyword_for_methods(self):
     self.mod.write('class A(object):\n    def a_func(self, param):\n        pass\n'
                    'a_var = A()\na_var.a_func(param=1)')
     signature = ChangeSignature(self.project, self.mod,
                                 self.mod.read().index('a_func') + 1)
     signature.normalize().do()
     self.assertEquals(
         'class A(object):\n    def a_func(self, param):\n        pass\n'
         'a_var = A()\na_var.a_func(1)', self.mod.read())