def testTokens(self): """Test various token forms (int, float, n"...", etc.).""" # TODO: a test with '"' or "'" in a string data = textwrap.dedent(""" def `interface`(abcde: "xyz", foo: 'a"b', b: -1.0, c: 666) -> int """) result = self.Parse(data) f1 = result.Lookup("interface") f2 = pytd.Function( name="interface", signatures=(pytd.Signature( params=( pytd.Parameter(name="abcde", type=pytd.Scalar(value="xyz")), pytd.Parameter(name="foo", type=pytd.Scalar(value='a"b')), pytd.Parameter(name="b", type=pytd.Scalar(value=-1.0)), pytd.Parameter(name="c", type=pytd.Scalar(value=666))), return_type=pytd.NamedType("int"), exceptions=(), template=(), has_optional=False),)) self.assertEqual(f1, f2)
def testDecorator(self): decorator = decorate.Decorator() # Change pytd.NamedType to also have a method called "Test1" @decorator # pylint: disable=unused-variable class NamedType(pytd.NamedType): def Test1(self): pass # Change pytd.Scalar to also have a method called "Test2" @decorator # pylint: disable=unused-variable class Scalar(pytd.Scalar): def Test2(self): pass tree = pytd.Scalar(pytd.NamedType("test")) tree = decorator.Visit(tree) # test that we now have the "test2" method on pytd.Scalar tree.Test2() # test that we now have the "test1" method on pytd.NamedType tree.value.Test1()
def p_scalar_number(self, p): """scalar : NUMBER""" p[0] = pytd.Scalar(p[1].AsFloatOrInt())
def p_scalar_string(self, p): """scalar : STRING""" p[0] = pytd.Scalar(p[1])
def p_scalar_number(self, p): """scalar : NUMBER""" p[0] = pytd.Scalar(p[1])