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)
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)
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)
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)
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)
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)
def testStr(self): expected_string = '"a"' expected_node = GetNodeFromInput(expected_string).value test_node = create_node.Str('a') self.assertNodesEqual(expected_node, test_node)
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)
def testDictRaisesErrorIfNotMatchingLengths(self): with self.assertRaises(ValueError): unused_test_node = create_node.Dict([create_node.Str('a')], [])
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)
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)
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)