Пример #1
0
   def testStringKwargs(self):
       expected_string = """def testFunc(a='b', c='d'):
 pass"""
       expected_node = GetNodeFromInput(expected_string).args
       test_node = create_node.arguments(
           keys=['a', 'c'],
           values=[create_node.Str('b'),
                   create_node.Str('d')])
       self.assertNodesEqual(expected_node, test_node)
Пример #2
0
   def testFunctionDefWithStringKwargs(self):
       expected_string = """def testFunc(a='b', c='d'):
 pass"""
       expected_node = GetNodeFromInput(expected_string)
       test_node = create_node.FunctionDef(
           'testFunc',
           keys=['a', 'c'],
           values=[create_node.Str('b'),
                   create_node.Str('d')])
       self.assertNodesEqual(expected_node, test_node)
Пример #3
0
 def testCallWithKwargs(self):
     expected_string = 'a(b="c")'
     expected_node = GetNodeFromInput(expected_string).value
     test_node = create_node.Call('a',
                                  keys=('b', ),
                                  values=(create_node.Str('c'), ))
     self.assertNodesEqual(expected_node, test_node)
Пример #4
0
 def testAssignWithTuple(self):
     expected_string = '(a, c) = "b"'
     expected_node = GetNodeFromInput(expected_string)
     test_node = create_node.Assign(
         create_node.Tuple('a', 'c', ctx_type=create_node.CtxEnum.STORE),
         create_node.Str('b'))
     self.assertNodesEqual(expected_node, test_node)
Пример #5
0
 def testStringAsFirst(self):
     expected_string = 'b = "a".c.d'
     expected_node = GetNodeFromInput(expected_string).value
     test_node = create_node.VarReference(create_node.Str('a'),
                                          'c',
                                          'd',
                                          ctx_type=create_node.CtxEnum.LOAD)
     self.assertNodesEqual(expected_node, test_node)
Пример #6
0
 def testTupleLoad(self):
     expected_string = 'a = ("b",)'
     expected_node = GetNodeFromInput(expected_string).value
     test_node = create_node.Tuple(create_node.Str('b'),
                                   ctx_type=create_node.CtxEnum.LOAD)
     self.assertNodesEqual(expected_node, test_node)
Пример #7
0
 def testStr(self):
     expected_string = '"a"'
     expected_node = GetNodeFromInput(expected_string).value
     test_node = create_node.Str('a')
     self.assertNodesEqual(expected_node, test_node)
Пример #8
0
 def testSet(self):
     expected_string = '{"a", "b"}'
     expected_node = GetNodeFromInput(expected_string).value
     test_node = create_node.Set(create_node.Str('a'), create_node.Str('b'))
     self.assertNodesEqual(expected_node, test_node)
Пример #9
0
 def testDictRaisesErrorIfNotMatchingLengths(self):
     with self.assertRaises(ValueError):
         unused_test_node = create_node.Dict([create_node.Str('a')], [])
Пример #10
0
 def testDictWithStringKeys(self):
     expected_string = '{"a": "b"}'
     expected_node = GetNodeFromInput(expected_string).value
     test_node = create_node.Dict([create_node.Str('a')],
                                  [create_node.Str('b')])
     self.assertNodesEqual(expected_node, test_node)
Пример #11
0
 def testAssignWithSimpleString(self):
     expected_string = 'a = "b"'
     expected_node = GetNodeFromInput(expected_string)
     test_node = create_node.Assign('a', create_node.Str('b'))
     self.assertNodesEqual(expected_node, test_node)
Пример #12
0
 def testAssertWithMessage(self):
     expected_string = 'assert a, "a failure"'
     expected_node = GetNodeFromInput(expected_string)
     test_node = create_node.Assert(create_node.Name('a'),
                                    create_node.Str('a failure'))
     self.assertNodesEqual(expected_node, test_node)