def test_func(): # type: () -> None s = Simple1(a_string="hello") s = Simple1() s.a_string = "Hello" s.a_repeated_string.append("Hello") s2 = Simple1.FromString(s.SerializeToString()) assert s2.a_string == "Hello" s3 = Simple1() s3.ParseFromString(s.SerializeToString()) assert s3.a_string == "Hello" s4 = Simple1() s4.CopyFrom(s) assert s4.a_string == "Hello" e = FOO e = OuterEnum.Value('BAR') l = lower2() l.upper.Lower.a = 2 assert l == lower2(upper=Upper(Lower=lower(a=2)))
def test_has_field_proto2(): # type: () -> None """For HasField which is typed with Literal""" s = Simple1() s.a_string = "Hello" # Proto2 tests assert s.HasField(u"a_string") assert s.HasField("a_string") if six.PY2: assert s.HasField(b"a_string") assert not s.HasField("a_inner") assert not s.HasField("a_enum") assert not s.HasField("a_oneof") # Erase the types to verify that incorrect inputs fail at runtime # Each test here should be duplicated in test_negative to ensure mypy fails it too s_untyped = s # type: Any with pytest.raises(ValueError, match="Protocol message Simple1 has no field garbage."): s_untyped.HasField("garbage") with pytest.raises( ValueError, match= 'Protocol message Simple1 has no singular "a_repeated_string" field', ): s_untyped.HasField("a_repeated_string") if six.PY3: with pytest.raises(TypeError, match="bad argument type for built-in operation"): s_untyped.HasField(b"a_string")
def test_clear_field_proto2(): # type: () -> None """For ClearField which is typed with Literal""" s = Simple1() s.a_string = "Hello" # Proto2 tests if six.PY3: s.ClearField(u"a_string") else: s.ClearField(b"a_string") s.ClearField("a_string") s.ClearField("a_inner") s.ClearField("a_repeated_string") s.ClearField("a_oneof") # Erase the types to verify that incorrect inputs fail at runtime # Each test here should be duplicated in test_negative to ensure mypy fails it too s_untyped = s # type: Any with pytest.raises(ValueError, match='Protocol message has no "garbage" field.'): s_untyped.ClearField("garbage") # This error message is very inconsistent w/ how HasField works with pytest.raises(TypeError, match='field name must be a string'): if six.PY2: s_untyped.ClearField(u"a_string") else: s_untyped.ClearField(b"a_string")
def test_func(): # type: () -> None s = Simple1(a_string="hello") s = Simple1() s.a_string = "Hello" s.a_repeated_string.append("Hello") s2 = Simple1.FromString(s.SerializeToString()) assert s2.a_string == "Hello" s3 = Simple1() s3.ParseFromString(s.SerializeToString()) assert s3.a_string == "Hello" s4 = Simple1() s4.CopyFrom(s) assert s4.a_string == "Hello"
def test_which_oneof_proto2(): # type: () -> None s = Simple1() assert s.WhichOneof("a_oneof") is None s.a_oneof_1 = "hello" assert s.WhichOneof("a_oneof") == "a_oneof_1" assert s.WhichOneof(u"a_oneof") == "a_oneof_1" assert s.WhichOneof(b"a_oneof") == "a_oneof_1" assert type(s.WhichOneof("a_oneof")) == str assert s.HasField(s.WhichOneof("a_oneof")) # Erase the types to verify that incorrect inputs fail at runtime # Each test here should be duplicated in test_negative to ensure mypy fails it too s_untyped = s # type: Any with pytest.raises(ValueError, match='Protocol message has no oneof "garbage" field.'): s_untyped.WhichOneof("garbage")
""" This code is intended to have mypy failures which we will ensure show up in the output. """ from test.proto.test_pb2 import Simple1 s = Simple1() s.a_string = "Hello" s2 = Simple1.FromString(s.SerializeToStringg()) # failure assert s2.a_string == "Hello" s3 = Simple1() s3.ParseFromString( s) # will be a failure once typeshed marks this as taking `bytes` assert s3.a_string == "Hello" s4 = Simple1() s4.CopyFrom(s.SerializeToString()) # failure assert s4.a_string == "Hello"
def test_message_descriptor_proto2(): # type: () -> None assert Simple1().DESCRIPTOR.full_name == "test.Simple1" assert Simple1.DESCRIPTOR.full_name == "test.Simple1"
This code is intended to have mypy failures which we will ensure show up in the output. """ import six from typing import ( List, Text, ) from test.proto.test_pb2 import FOO, Simple1, Simple2 from test.proto.test3_pb2 import OuterEnum, SimpleProto3 from test.proto.dot.com.test_pb2 import TestMessage s = Simple1() s.a_string = "Hello" s2 = Simple1.FromString(s.SerializeToStringg()) # E:2.7 E:3.5 s3 = Simple1() s3.ParseFromString(s) # E:2.7 E:3.5 s4 = Simple1() s4.CopyFrom(s.SerializeToString()) # E:2.7 E:3.5 s5 = Simple1() l = [] # type: List[int] l.extend(s5.a_repeated_string) # E:2.7 E:3.5 tm = TestMessage(foo=55) # E:2.7 E:3.5