Beispiel #1
0
 def test_ast_args_to_str(self):
     call_node = ast.parse('foo(a, b)')
     args_str = b_utils.ast_args_to_str(call_node.body[0].value.args)
     expected = ("\n\tArgument/s:\n\t\tName(id='a', ctx=Load())"
                 "\n\t\tName(id='b', ctx=Load())")
     self.assertEqual(expected, args_str)
     call_node = ast.parse("foo(True, 1, 'cc')")
     args_str = b_utils.ast_args_to_str(call_node.body[0].value.args)
     if six.PY2:
         expected = ("\n\tArgument/s:\n\t\tName(id='True', ctx=Load())"
                     "\n\t\tNum(n=1)\n\t\tStr(s='cc')")
     else:
         expected = ("\n\tArgument/s:\n\t\tNameConstant(value=True)"
                     "\n\t\tNum(n=1)\n\t\tStr(s='cc')")
     self.assertEqual(expected, args_str)
Beispiel #2
0
    def call_args_string(self):
        '''Get a string representation of the call arguments

        :return: Returns a string representation of the call arguments
        '''
        if 'call' in self._context and hasattr(self._context, 'args'):
            return utils.ast_args_to_str(self._context['call'].args)
        else:
            return ''