Example #1
0
    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')
Example #2
0
    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)
Example #3
0
    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)
Example #4
0
    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)
Example #5
0
    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)
Example #6
0
    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])))
Example #7
0
    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)
Example #8
0
    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)
Example #9
0
    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)
Example #10
0
    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)
Example #11
0
    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)