def testLongOptionCommand (self): c= castt.CrazyASTTransformer ({ 'o': o}) t= ayrton.parse ("""foo (--long-option=True)""") node= c.visit_Call (t.body[0].value) self.assertEqual (node.args[0].keywords[0].arg, '--long-option')
def testMinusMinusCommand (self): c= castt.CrazyASTTransformer ({ 'o': o}) t= ayrton.parse ("""foo (--p=True)""") node= c.visit_Call (t.body[0].value) self.assertEqual (node.args[0].keywords[0].arg, '--p') self.check_attrs (node)
def testLongOptionCommand(self): c = castt.CrazyASTTransformer({'o': o}) t = ayrton.parse("""foo (--long-option=True)""") node = c.visit_Call(t.body[0].value) self.assertEqual(node.args[0].keywords[0].arg, '--long-option') self.check_attrs(node)
def testWithCd (self): code= """with cd() as e: pass""" t= ast.parse (code) self.check_attrs (t.body[0]) c= castt.CrazyASTTransformer ({ 'o': o, 'cd': cd}) t= ayrton.parse (code) self.check_attrs (t.body[0]) node= c.visit_With (t.body[0]) self.assertEqual (node.items[0].context_expr.func.id, 'cd') self.check_attrs (node)
def testWithCd(self): code = """with cd() as e: pass""" t = ast.parse(code) self.check_attrs(t.body[0]) c = castt.CrazyASTTransformer({'o': o, 'cd': cd}) t = ayrton.parse(code) self.check_attrs(t.body[0]) node = c.visit_With(t.body[0]) self.assertEqual(node.items[0].context_expr.func.id, 'cd') self.check_attrs(node)
def testDoubleKeywordCommand (self): c= castt.CrazyASTTransformer ({ 'o': o}) t= ayrton.parse ("""foo (p= True, p=False)""") node= c.visit_Call (t.body[0].value) # Call(func=Call(func=Name(id='Command', ctx=Load()), args=[Str(s='foo')], keywords=[], starargs=None, kwargs=None), # args=[Call(func=Name(id='o', ctx=Load()), args=[], keywords=[keyword(arg='p', value=Name(id='True', ctx=Load()))], starargs=None, kwargs=None), # Call(func=Name(id='o', ctx=Load()), args=[], keywords=[keyword(arg='p', value=Name(id='False', ctx=Load()))], starargs=None, kwargs=None)], # keywords=[], starargs=None, kwargs=None) # both arguments have the same name! self.assertEqual (node.args[0].keywords[0].arg, node.args[1].keywords[0].arg, "\n%s\n%s\n" % (ast.dump (node.args[0]), ast.dump (node.args[1])))
def testDoubleKeywordCommand(self): c = castt.CrazyASTTransformer({'o': o}) t = ayrton.parse("""foo (p= True, p=False)""") node = c.visit_Call(t.body[0].value) # Call(func=Call(func=Name(id='Command', ctx=Load()), args=[Str(s='foo')], keywords=[], starargs=None, kwargs=None), # args=[Call(func=Name(id='o', ctx=Load()), args=[], keywords=[keyword(arg='p', value=Name(id='True', ctx=Load()))], starargs=None, kwargs=None), # Call(func=Name(id='o', ctx=Load()), args=[], keywords=[keyword(arg='p', value=Name(id='False', ctx=Load()))], starargs=None, kwargs=None)], # keywords=[], starargs=None, kwargs=None) # both arguments have the same name! self.assertEqual( node.args[0].keywords[0].arg, node.args[1].keywords[0].arg, "\n%s\n%s\n" % (ast.dump(node.args[0]), ast.dump(node.args[1]))) self.check_attrs(node)
def testMinusMinusFunction (self): c= castt.CrazyASTTransformer ({ 'o': o, 'dict': dict}) t= ayrton.parse ("""dict (--p=True)""") self.assertRaises (SyntaxError, c.visit_Call, t.body[0].value)
def testDoubleKeywordFunction (self): c= castt.CrazyASTTransformer ({ 'o': o, 'dict': dict}) t= ayrton.parse ("""dict (p=True, p=False)""") self.assertRaises (SyntaxError, c.visit_Call, t.body[0].value)
def testMinusMinusFunction(self): c = castt.CrazyASTTransformer({'o': o, 'dict': dict}) t = ayrton.parse("""dict (--p=True)""") self.assertRaises(SyntaxError, c.visit_Call, t.body[0].value)
def testDoubleKeywordFunction(self): c = castt.CrazyASTTransformer({'o': o, 'dict': dict}) t = ayrton.parse("""dict (p=True, p=False)""") self.assertRaises(SyntaxError, c.visit_Call, t.body[0].value)