Lines Matching refs:proto

116     proto = unittest_pb2.TestAllTypes(
121 self.assertEqual(24, proto.optional_int32)
122 self.assertEqual(54.321, proto.optional_double)
123 self.assertEqual('optional_string', proto.optional_string)
127 proto = unittest_pb2.TestAllTypes(
133 self.assertEquals([1, 2, 3, 4], list(proto.repeated_int32))
134 self.assertEquals([1.23, 54.321], list(proto.repeated_double))
135 self.assertEquals([True, False, False], list(proto.repeated_bool))
136 self.assertEquals(["optional_string"], list(proto.repeated_string))
140 proto = unittest_pb2.TestAllTypes(
160 list(proto.repeated_nested_message))
165 list(proto.repeated_foreign_message))
170 list(proto.repeatedgroup))
174 proto = unittest_pb2.TestAllTypes(
189 self.assertEqual(24, proto.optional_int32)
190 self.assertEqual('optional_string', proto.optional_string)
191 self.assertEquals([1.23, 54.321], list(proto.repeated_double))
192 self.assertEquals([True, False, False], list(proto.repeated_bool))
198 list(proto.repeated_nested_message))
203 list(proto.repeated_foreign_message))
242 proto = unittest_pb2.TestAllTypes()
243 self.assertTrue(not proto.HasField('optional_int32'))
244 self.assertEqual(0, proto.optional_int32)
247 self.assertTrue(not proto.HasField('optional_int32'))
248 proto.optional_int32 = 1
250 self.assertTrue(proto.HasField('optional_int32'))
251 proto.ClearField('optional_int32')
253 self.assertTrue(not proto.HasField('optional_int32'))
290 proto = unittest_pb2.TestAllTypes()
294 composite_field = getattr(proto, composite_field_name)
300 self.assertTrue(not proto.HasField(composite_field_name))
312 self.assertTrue(proto.HasField(composite_field_name))
315 proto.ClearField(composite_field_name)
318 composite_field = getattr(proto, composite_field_name)
320 self.assertTrue(not proto.HasField(composite_field_name))
327 self.assertTrue(not proto.HasField(composite_field_name))
337 proto = unittest_pb2.TestAllTypes()
338 nested = proto.optional_nested_message
339 del proto
345 proto = unittest_pb2.TestAllTypes()
346 nested = proto.optional_nested_message
347 proto.ClearField('optional_nested_message') # Should disconnect from parent
348 self.assertTrue(nested is not proto.optional_nested_message)
350 self.assertTrue(not proto.HasField('optional_nested_message'))
351 self.assertEqual(0, proto.optional_nested_message.bb)
354 proto = unittest_pb2.TestAllTypes()
355 nested = proto.optional_nested_message
356 proto.ClearField('optional_nested_message')
357 del proto
363 proto = unittest_pb2.TestAllTypes()
364 nested = proto.optional_nested_message
367 proto = unittest_pb2.TestAllTypes()
368 nested = proto.optional_nested_message
370 self.assertTrue(proto.HasField('optional_nested_message'))
371 proto.ClearField('optional_nested_message') # Should disconnect from parent
373 self.assertEqual(0, proto.optional_nested_message.bb)
374 self.assertTrue(nested is not proto.optional_nested_message)
376 self.assertTrue(not proto.HasField('optional_nested_message'))
377 self.assertEqual(0, proto.optional_nested_message.bb)
380 proto = unittest_pb2.TestAllTypes()
381 self.assertTrue(not proto.HasField('optional_nested_message'))
382 proto.ClearField('optional_nested_message')
383 self.assertTrue(not proto.HasField('optional_nested_message'))
405 proto = unittest_pb2.TestAllTypes()
406 proto.optional_lazy_message.bb = 5
407 proto.ClearField('optional_lazy_message')
408 del proto
413 proto = unittest_pb2.TestNestedMessageHasBits()
414 proto.optional_nested_message.nestedmessage_repeated_int32.append(5)
416 [5], proto.optional_nested_message.nestedmessage_repeated_int32)
417 self.assertTrue(proto.HasField('optional_nested_message'))
421 proto.ClearField('optional_nested_message')
422 self.assertTrue(not proto.HasField('optional_nested_message'))
423 proto.optional_nested_message.nestedmessage_repeated_foreignmessage.add()
424 self.assertTrue(proto.HasField('optional_nested_message'))
443 proto = unittest_pb2.TestAllTypes()
444 proto.optional_fixed32 = 1
445 proto.optional_int32 = 5
446 proto.optional_string = 'foo'
448 nested_message = proto.optional_nested_message
450 [ (proto.DESCRIPTOR.fields_by_name['optional_int32' ], 5),
451 (proto.DESCRIPTOR.fields_by_name['optional_fixed32'], 1),
452 (proto.DESCRIPTOR.fields_by_name['optional_string' ], 'foo') ],
453 proto.ListFields())
455 proto.optional_nested_message.bb = 123
457 [ (proto.DESCRIPTOR.fields_by_name['optional_int32' ], 5),
458 (proto.DESCRIPTOR.fields_by_name['optional_fixed32'], 1),
459 (proto.DESCRIPTOR.fields_by_name['optional_string' ], 'foo'),
460 (proto.DESCRIPTOR.fields_by_name['optional_nested_message' ],
462 proto.ListFields())
465 proto = unittest_pb2.TestAllTypes()
466 proto.repeated_fixed32.append(1)
467 proto.repeated_int32.append(5)
468 proto.repeated_int32.append(11)
469 proto.repeated_string.extend(['foo', 'bar'])
470 proto.repeated_string.extend([])
471 proto.repeated_string.append('baz')
472 proto.repeated_string.extend(str(x) for x in xrange(2))
473 proto.optional_int32 = 21
474 proto.repeated_bool # Access but don't set anything; should not be listed.
476 [ (proto.DESCRIPTOR.fields_by_name['optional_int32' ], 21),
477 (proto.DESCRIPTOR.fields_by_name['repeated_int32' ], [5, 11]),
478 (proto.DESCRIPTOR.fields_by_name['repeated_fixed32'], [1]),
479 (proto.DESCRIPTOR.fields_by_name['repeated_string' ],
481 proto.ListFields())
484 proto = unittest_pb2.TestAllExtensions()
485 proto.Extensions[unittest_pb2.optional_fixed32_extension] = 1
486 proto.Extensions[unittest_pb2.optional_int32_extension ] = 5
487 proto.Extensions[unittest_pb2.optional_string_extension ] = 'foo'
492 proto.ListFields())
495 proto = unittest_pb2.TestAllExtensions()
496 proto.Extensions[unittest_pb2.repeated_fixed32_extension].append(1)
497 proto.Extensions[unittest_pb2.repeated_int32_extension ].append(5)
498 proto.Extensions[unittest_pb2.repeated_int32_extension ].append(11)
499 proto.Extensions[unittest_pb2.repeated_string_extension ].append('foo')
500 proto.Extensions[unittest_pb2.repeated_string_extension ].append('bar')
501 proto.Extensions[unittest_pb2.repeated_string_extension ].append('baz')
502 proto.Extensions[unittest_pb2.optional_int32_extension ] = 21
508 proto.ListFields())
511 proto = unittest_pb2.TestFieldOrderings()
512 test_util.SetAllFieldsAndExtensions(proto)
515 [ (proto.DESCRIPTOR.fields_by_name['my_int' ], 1),
517 (proto.DESCRIPTOR.fields_by_name['my_string'], 'foo'),
519 (proto.DESCRIPTOR.fields_by_name['my_float' ], 1.0) ],
520 proto.ListFields())
523 proto = unittest_pb2.TestAllTypes()
524 self.assertEqual(0, proto.optional_int32)
525 self.assertEqual(0, proto.optional_int64)
526 self.assertEqual(0, proto.optional_uint32)
527 self.assertEqual(0, proto.optional_uint64)
528 self.assertEqual(0, proto.optional_sint32)
529 self.assertEqual(0, proto.optional_sint64)
530 self.assertEqual(0, proto.optional_fixed32)
531 self.assertEqual(0, proto.optional_fixed64)
532 self.assertEqual(0, proto.optional_sfixed32)
533 self.assertEqual(0, proto.optional_sfixed64)
534 self.assertEqual(0.0, proto.optional_float)
535 self.assertEqual(0.0, proto.optional_double)
536 self.assertEqual(False, proto.optional_bool)
537 self.assertEqual('', proto.optional_string)
538 self.assertEqual(b'', proto.optional_bytes)
540 self.assertEqual(41, proto.default_int32)
541 self.assertEqual(42, proto.default_int64)
542 self.assertEqual(43, proto.default_uint32)
543 self.assertEqual(44, proto.default_uint64)
544 self.assertEqual(-45, proto.default_sint32)
545 self.assertEqual(46, proto.default_sint64)
546 self.assertEqual(47, proto.default_fixed32)
547 self.assertEqual(48, proto.default_fixed64)
548 self.assertEqual(49, proto.default_sfixed32)
549 self.assertEqual(-50, proto.default_sfixed64)
550 self.assertEqual(51.5, proto.default_float)
551 self.assertEqual(52e3, proto.default_double)
552 self.assertEqual(True, proto.default_bool)
553 self.assertEqual('hello', proto.default_string)
554 self.assertEqual(b'world', proto.default_bytes)
555 self.assertEqual(unittest_pb2.TestAllTypes.BAR, proto.default_nested_enum)
556 self.assertEqual(unittest_pb2.FOREIGN_BAR, proto.default_foreign_enum)
558 proto.default_import_enum)
560 proto = unittest_pb2.TestExtremeDefaultValues()
561 self.assertEqual(u'\u1234', proto.utf8_string)
564 proto = unittest_pb2.TestAllTypes()
565 self.assertRaises(ValueError, proto.HasField, 'nonexistent_field')
568 proto = unittest_pb2.TestAllTypes()
569 self.assertRaises(ValueError, proto.ClearField, 'nonexistent_field')
575 proto = unittest_pb2.TestRequiredForeign()
577 proto.repeated_message.add()
579 proto.CopyFrom(proto2)
580 self.assertRaises(IndexError, lambda: proto.repeated_message[5])
585 proto = unittest_pb2.TestAllTypes()
587 self.assertRaises(AttributeError, setattr, proto, 'repeated_int32', 10)
589 self.assertRaises(AttributeError, setattr, proto, 'repeated_int32', [10])
591 self.assertRaises(AttributeError, setattr, proto,
595 self.assertRaises(AttributeError, setattr, proto.repeated_nested_message,
598 self.assertRaises(AttributeError, setattr, proto.repeated_float,
601 self.assertRaises(AttributeError, setattr, proto, 'nonexistent_field', 23)
604 proto = unittest_pb2.TestAllTypes()
605 self.assertRaises(TypeError, setattr, proto, 'optional_int32', 1.1)
606 self.assertRaises(TypeError, setattr, proto, 'optional_int32', 'foo')
607 self.assertRaises(TypeError, setattr, proto, 'optional_string', 10)
608 self.assertRaises(TypeError, setattr, proto, 'optional_bytes', 10)
612 proto = unittest_pb2.TestAllTypes()
613 setattr(proto, field_name, value)
614 self.assertTrue(isinstance(getattr(proto, field_name), expected_type))
616 proto2.ParseFromString(proto.SerializeToString())
654 proto = unittest_pb2.TestAllTypes()
655 self.assertRaises(TypeError, proto.repeated_int32.append, 1.1)
656 self.assertRaises(TypeError, proto.repeated_int32.append, 'foo')
657 self.assertRaises(TypeError, proto.repeated_string, 10)
658 self.assertRaises(TypeError, proto.repeated_bytes, 10)
660 proto.repeated_int32.append(10)
661 proto.repeated_int32[0] = 23
662 self.assertRaises(IndexError, proto.repeated_int32.__setitem__, 500, 23)
663 self.assertRaises(TypeError, proto.repeated_int32.__setitem__, 0, 'abc')
669 proto = unittest_pb2.TestAllTypes()
670 self.assertEqual(0, proto.optional_int32)
671 proto.optional_int32 = 1
672 self.assertEqual(1, proto.optional_int32)
674 proto.optional_uint64 = 0xffffffffffff
675 self.assertEqual(0xffffffffffff, proto.optional_uint64)
676 proto.optional_uint64 = 0xffffffffffffffff
677 self.assertEqual(0xffffffffffffffff, proto.optional_uint64)
681 proto = unittest_pb2.TestAllTypes()
683 proto.ClearField('optional_int32')
684 proto.optional_int32 = 1
685 self.assertTrue(proto.HasField('optional_int32'))
686 proto.ClearField('optional_int32')
687 self.assertEqual(0, proto.optional_int32)
688 self.assertTrue(not proto.HasField('optional_int32'))
692 proto = unittest_pb2.TestAllTypes()
693 self.assertEqual(1, proto.FOO)
695 self.assertEqual(2, proto.BAR)
697 self.assertEqual(3, proto.BAZ)
710 proto = unittest_pb2.TestAllTypes()
712 proto.NestedEnum.Name(proto.FOO))
714 unittest_pb2.TestAllTypes.NestedEnum.Name(proto.FOO))
716 proto.NestedEnum.Name(proto.BAR))
718 unittest_pb2.TestAllTypes.NestedEnum.Name(proto.BAR))
720 proto.NestedEnum.Name(proto.BAZ))
722 unittest_pb2.TestAllTypes.NestedEnum.Name(proto.BAZ))
724 proto.NestedEnum.Name, 11312)
738 proto = unittest_pb2.TestAllTypes()
739 self.assertEqual(proto.FOO,
740 proto.NestedEnum.Value('FOO'))
741 self.assertEqual(proto.FOO,
743 self.assertEqual(proto.BAR,
744 proto.NestedEnum.Value('BAR'))
745 self.assertEqual(proto.BAR,
747 self.assertEqual(proto.BAZ,
748 proto.NestedEnum.Value('BAZ'))
749 self.assertEqual(proto.BAZ,
752 proto.NestedEnum.Value, 'Foo')
765 proto = unittest_pb2.TestAllTypes()
766 self.assertEqual(['FOO', 'BAR', 'BAZ', 'NEG'], proto.NestedEnum.keys())
767 self.assertEqual([1, 2, 3, -1], proto.NestedEnum.values())
769 proto.NestedEnum.items())
772 proto = unittest_pb2.TestAllTypes()
774 self.assertTrue(not proto.repeated_int32)
775 self.assertEqual(0, len(proto.repeated_int32))
776 proto.repeated_int32.append(5)
777 proto.repeated_int32.append(10)
778 proto.repeated_int32.append(15)
779 self.assertTrue(proto.repeated_int32)
780 self.assertEqual(3, len(proto.repeated_int32))
782 self.assertEqual([5, 10, 15], proto.repeated_int32)
785 self.assertEqual(5, proto.repeated_int32[0])
786 self.assertEqual(15, proto.repeated_int32[-1])
788 self.assertRaises(IndexError, proto.repeated_int32.__getitem__, 1234)
789 self.assertRaises(IndexError, proto.repeated_int32.__getitem__, -1234)
791 self.assertRaises(TypeError, proto.repeated_int32.__getitem__, 'foo')
792 self.assertRaises(TypeError, proto.repeated_int32.__getitem__, None)
795 proto.repeated_int32[1] = 20
796 self.assertEqual([5, 20, 15], proto.repeated_int32)
799 proto.repeated_int32.insert(1, 25)
800 self.assertEqual([5, 25, 20, 15], proto.repeated_int32)
803 proto.repeated_int32.append(30)
804 self.assertEqual([25, 20, 15], proto.repeated_int32[1:4])
805 self.assertEqual([5, 25, 20, 15, 30], proto.repeated_int32[:])
808 proto.repeated_int32[1:4] = (i for i in xrange(3))
809 self.assertEqual([5, 0, 1, 2, 30], proto.repeated_int32)
812 proto.repeated_int32[1:4] = [35, 40, 45]
813 self.assertEqual([5, 35, 40, 45, 30], proto.repeated_int32)
817 for i in proto.repeated_int32:
822 del proto.repeated_int32[2]
823 self.assertEqual([5, 35, 45, 30], proto.repeated_int32)
826 del proto.repeated_int32[2:]
827 self.assertEqual([5, 35], proto.repeated_int32)
830 proto.repeated_int32.extend([3, 13])
831 self.assertEqual([5, 35, 3, 13], proto.repeated_int32)
834 proto.ClearField('repeated_int32')
835 self.assertTrue(not proto.repeated_int32)
836 self.assertEqual(0, len(proto.repeated_int32))
838 proto.repeated_int32.append(1)
839 self.assertEqual(1, proto.repeated_int32[-1])
841 proto.repeated_int32[-1] = 2
842 self.assertEqual(2, proto.repeated_int32[-1])
845 proto.repeated_int32[:] = [0, 1, 2, 3]
846 del proto.repeated_int32[-1]
847 self.assertEqual([0, 1, 2], proto.repeated_int32)
849 del proto.repeated_int32[-2]
850 self.assertEqual([0, 2], proto.repeated_int32)
852 self.assertRaises(IndexError, proto.repeated_int32.__delitem__, -3)
853 self.assertRaises(IndexError, proto.repeated_int32.__delitem__, 300)
855 del proto.repeated_int32[-2:-1]
856 self.assertEqual([2], proto.repeated_int32)
858 del proto.repeated_int32[100:10000]
859 self.assertEqual([2], proto.repeated_int32)
862 proto = unittest_pb2.TestAllTypes()
864 self.assertTrue(not proto.repeated_int32)
865 self.assertEqual(0, len(proto.repeated_int32))
866 proto.repeated_int32.append(5)
867 proto.repeated_int32.append(10)
868 proto.repeated_int32.append(5)
869 proto.repeated_int32.append(5)
871 self.assertEqual(4, len(proto.repeated_int32))
872 proto.repeated_int32.remove(5)
873 self.assertEqual(3, len(proto.repeated_int32))
874 self.assertEqual(10, proto.repeated_int32[0])
875 self.assertEqual(5, proto.repeated_int32[1])
876 self.assertEqual(5, proto.repeated_int32[2])
878 proto.repeated_int32.remove(5)
879 self.assertEqual(2, len(proto.repeated_int32))
880 self.assertEqual(10, proto.repeated_int32[0])
881 self.assertEqual(5, proto.repeated_int32[1])
883 proto.repeated_int32.remove(10)
884 self.assertEqual(1, len(proto.repeated_int32))
885 self.assertEqual(5, proto.repeated_int32[0])
888 self.assertRaises(ValueError, proto.repeated_int32.remove, 123)
891 proto = unittest_pb2.TestAllTypes()
892 self.assertTrue(not proto.repeated_nested_message)
893 self.assertEqual(0, len(proto.repeated_nested_message))
894 m0 = proto.repeated_nested_message.add()
895 m1 = proto.repeated_nested_message.add()
896 self.assertTrue(proto.repeated_nested_message)
897 self.assertEqual(2, len(proto.repeated_nested_message))
898 self.assertListsEqual([m0, m1], proto.repeated_nested_message)
902 self.assertRaises(IndexError, proto.repeated_nested_message.__getitem__,
904 self.assertRaises(IndexError, proto.repeated_nested_message.__getitem__,
908 self.assertRaises(TypeError, proto.repeated_nested_message.__getitem__,
910 self.assertRaises(TypeError, proto.repeated_nested_message.__getitem__,
914 m2 = proto.repeated_nested_message.add()
915 m3 = proto.repeated_nested_message.add()
916 m4 = proto.repeated_nested_message.add()
918 [m1, m2, m3], proto.repeated_nested_message[1:4])
920 [m0, m1, m2, m3, m4], proto.repeated_nested_message[:])
922 [m0, m1], proto.repeated_nested_message[:2])
924 [m2, m3, m4], proto.repeated_nested_message[2:])
926 m0, proto.repeated_nested_message[0])
928 [m0], proto.repeated_nested_message[:1])
932 for i in proto.repeated_nested_message:
937 del proto.repeated_nested_message[2]
938 self.assertListsEqual([m0, m1, m3, m4], proto.repeated_nested_message)
941 del proto.repeated_nested_message[2:]
942 self.assertListsEqual([m0, m1], proto.repeated_nested_message)
947 proto.repeated_nested_message.extend([n1,n2])
948 self.assertEqual(4, len(proto.repeated_nested_message))
949 self.assertEqual(n1, proto.repeated_nested_message[2])
950 self.assertEqual(n2, proto.repeated_nested_message[3])
953 proto.ClearField('repeated_nested_message')
954 self.assertTrue(not proto.repeated_nested_message)
955 self.assertEqual(0, len(proto.repeated_nested_message))
958 proto.repeated_nested_message.add(bb=23)
959 self.assertEqual(1, len(proto.repeated_nested_message))
960 self.assertEqual(23, proto.repeated_nested_message[0].bb)
963 proto = unittest_pb2.TestAllTypes()
965 self.assertEqual(0, len(proto.repeated_nested_message))
966 m0 = proto.repeated_nested_message.add()
968 m0.bb = len(proto.repeated_nested_message)
969 m1 = proto.repeated_nested_message.add()
970 m1.bb = len(proto.repeated_nested_message)
972 m2 = proto.repeated_nested_message.add()
973 m2.bb = len(proto.repeated_nested_message)
974 self.assertListsEqual([m0, m1, m2], proto.repeated_nested_message)
976 self.assertEqual(3, len(proto.repeated_nested_message))
977 proto.repeated_nested_message.remove(m0)
978 self.assertEqual(2, len(proto.repeated_nested_message))
979 self.assertEqual(m1, proto.repeated_nested_message[0])
980 self.assertEqual(m2, proto.repeated_nested_message[1])
983 self.assertRaises(ValueError, proto.repeated_nested_message.remove, m0)
984 self.assertRaises(ValueError, proto.repeated_nested_message.remove, None)
985 self.assertEqual(2, len(proto.repeated_nested_message))
987 proto.repeated_nested_message.remove(m2)
988 self.assertEqual(1, len(proto.repeated_nested_message))
989 self.assertEqual(m1, proto.repeated_nested_message[0])
1027 def AddDescriptorField(proto, field_name, field_type): argument
1029 new_field = proto.field.add()
1490 proto = unittest_pb2.TestAllTypes()
1494 test_util.SetAllFields(proto)
1496 test_util.SetAllNonLazyFields(proto)
1498 proto.Clear()
1499 self.assertEquals(proto.ByteSize(), 0)
1501 self.assertEquals(proto, empty_proto)
1504 proto = unittest_pb2.TestAllExtensions()
1505 test_util.SetAllExtensions(proto)
1507 proto.Clear()
1508 self.assertEquals(proto.ByteSize(), 0)
1510 self.assertEquals(proto, empty_proto)
1513 proto = unittest_pb2.TestAllTypes()
1514 nested = proto.optional_nested_message
1515 proto.Clear()
1516 self.assertTrue(nested is not proto.optional_nested_message)
1518 self.assertTrue(not proto.HasField('optional_nested_message'))
1519 self.assertEqual(0, proto.optional_nested_message.bb)
1521 proto = unittest_pb2.TestAllTypes()
1522 nested = proto.optional_nested_message
1524 foreign = proto.optional_foreign_message
1527 proto.Clear()
1528 self.assertTrue(nested is not proto.optional_nested_message)
1529 self.assertTrue(foreign is not proto.optional_foreign_message)
1534 self.assertFalse(proto.HasField('optional_nested_message'))
1535 self.assertEqual(0, proto.optional_nested_message.bb)
1536 self.assertFalse(proto.HasField('optional_foreign_message'))
1537 self.assertEqual(0, proto.optional_foreign_message.c)
1540 proto = unittest_pb2.TestAllTypes()
1541 proto.oneof_uint32 = 10
1542 proto.oneof_nested_message.bb = 11
1543 self.assertEqual(11, proto.oneof_nested_message.bb)
1544 self.assertFalse(proto.HasField('oneof_uint32'))
1545 nested = proto.oneof_nested_message
1546 proto.oneof_string = 'abc'
1547 self.assertEqual('abc', proto.oneof_string)
1549 self.assertFalse(proto.HasField('oneof_nested_message'))
1551 def assertInitialized(self, proto): argument
1552 self.assertTrue(proto.IsInitialized())
1554 proto.SerializeToString()
1555 proto.SerializePartialToString()
1557 def assertNotInitialized(self, proto): argument
1558 self.assertFalse(proto.IsInitialized())
1559 self.assertRaises(message.EncodeError, proto.SerializeToString)
1561 proto.SerializePartialToString()
1565 proto = unittest_pb2.TestAllTypes()
1566 self.assertInitialized(proto)
1567 proto = unittest_pb2.TestAllExtensions()
1568 self.assertInitialized(proto)
1571 proto = unittest_pb2.TestRequired()
1572 self.assertNotInitialized(proto)
1573 proto.a = proto.b = proto.c = 2
1574 self.assertInitialized(proto)
1577 proto = unittest_pb2.TestRequiredForeign()
1578 self.assertInitialized(proto)
1579 proto.optional_message.a = 1
1580 self.assertNotInitialized(proto)
1581 proto.optional_message.b = 0
1582 proto.optional_message.c = 0
1583 self.assertInitialized(proto)
1586 message1 = proto.repeated_message.add()
1587 self.assertNotInitialized(proto)
1589 self.assertInitialized(proto)
1592 proto = unittest_pb2.TestAllExtensions()
1594 message1 = proto.Extensions[extension].add()
1595 message2 = proto.Extensions[extension].add()
1596 self.assertNotInitialized(proto)
1600 self.assertNotInitialized(proto)
1604 self.assertInitialized(proto)
1607 proto = unittest_pb2.TestAllExtensions()
1609 proto.Extensions[extension].a = 1
1610 self.assertNotInitialized(proto)
1611 proto.Extensions[extension].b = 2
1612 proto.Extensions[extension].c = 3
1613 self.assertInitialized(proto)
1617 proto = unittest_pb2.TestRequired()
1618 self.assertFalse(proto.IsInitialized(errors))
1656 proto = unittest_pb2.TestAllTypes()
1660 setattr, proto, 'optional_bytes', u'unicode object')
1663 self.assertEqual(type(proto.optional_string), unicode)
1665 proto.optional_string = unicode('Testing')
1666 self.assertEqual(proto.optional_string, str('Testing'))
1669 proto.optional_string = str('Testing')
1670 self.assertEqual(proto.optional_string, unicode('Testing'))
1674 setattr, proto, 'optional_string', b'a\x80a')
1678 setattr, proto, 'optional_string', 'Тест')
1680 proto.optional_string = 'Тест'
1682 proto.optional_string = 'abc'
1685 proto = unittest_mset_pb2.TestMessageSet()
1693 proto.Extensions[extension].str = test_utf8
1697 serialized = proto.SerializeToString()
1700 self.assertEqual(proto.ByteSize(), len(serialized))
1740 proto = unittest_pb2.TestAllTypes(optional_bytes=b'\x00\x7f\x80\xff')
1742 unicode(proto))
1745 proto = unittest_pb2.TestAllTypes()
1746 proto.optional_nested_message.MergeFrom(
1748 self.assertTrue(proto.HasField('optional_nested_message'))
1750 proto = unittest_pb2.TestAllTypes()
1751 proto.optional_nested_message.CopyFrom(
1753 self.assertTrue(proto.HasField('optional_nested_message'))
1755 proto = unittest_pb2.TestAllTypes()
1756 bytes_read = proto.optional_nested_message.MergeFromString(b'')
1758 self.assertTrue(proto.HasField('optional_nested_message'))
1760 proto = unittest_pb2.TestAllTypes()
1761 proto.optional_nested_message.ParseFromString(b'')
1762 self.assertTrue(proto.HasField('optional_nested_message'))
1764 serialized = proto.SerializeToString()
1772 proto = unittest_pb2.TestAllTypes()
1773 self.assertFalse(proto.HasField('optionalgroup'))
1774 proto.optionalgroup.SetInParent()
1775 self.assertTrue(proto.HasField('optionalgroup'))
1932 self.proto = unittest_pb2.TestAllTypes()
1938 return self.proto.ByteSize()
1941 self.assertEqual(0, self.proto.ByteSize())
1945 proto = unittest_pb2.TestAllTypes()
1946 self.assertEqual(0, proto.ByteSize())
1953 self.proto.Clear()
1954 self.proto.optional_int64 = i
1967 self.proto.optional_string = ''
1971 self.proto.optional_string = 'abc'
1973 self.assertEqual(2 + len(self.proto.optional_string), self.Size())
1975 self.proto.optional_string = 'x' * 128
1977 self.assertEqual(3 + len(self.proto.optional_string), self.Size())
1980 self.proto.optional_fixed32 = 1234
1983 self.proto = unittest_pb2.TestAllTypes()
1985 self.proto.optional_fixed64 = 1234
1988 self.proto = unittest_pb2.TestAllTypes()
1990 self.proto.optional_float = 1.234
1993 self.proto = unittest_pb2.TestAllTypes()
1995 self.proto.optional_double = 1.234
1998 self.proto = unittest_pb2.TestAllTypes()
2000 self.proto.optional_sint32 = 64
2003 self.proto = unittest_pb2.TestAllTypes()
2007 self.proto.optional_nested_message.bb = (1 << 14)
2015 self.proto.optionalgroup.a = (1 << 21)
2021 self.proto.repeated_int32.append(10) # 1 byte.
2022 self.proto.repeated_int32.append(128) # 2 bytes.
2027 self.proto.repeated_int32.extend([10, 128]) # 3 bytes.
2032 self.proto.repeated_int32.append(10) # 1 byte.
2033 self.proto.repeated_int32.append(128) # 2 bytes.
2036 self.proto.repeated_int32.remove(128)
2041 foreign_message_0 = self.proto.repeated_nested_message.add()
2043 foreign_message_1 = self.proto.repeated_nested_message.add()
2049 foreign_message_0 = self.proto.repeated_nested_message.add()
2051 foreign_message_1 = self.proto.repeated_nested_message.add()
2056 del self.proto.repeated_nested_message[0]
2060 foreign_message_2 = self.proto.repeated_nested_message.add()
2068 del self.proto.repeated_nested_message[1]
2071 del self.proto.repeated_nested_message[0]
2076 group_0 = self.proto.repeatedgroup.add()
2079 group_1 = self.proto.repeatedgroup.add()
2084 proto = unittest_pb2.TestAllExtensions()
2085 self.assertEqual(0, proto.ByteSize())
2087 proto.Extensions[extension] = 23
2089 self.assertEqual(2, proto.ByteSize())
2093 self.proto.optional_int32 = 1
2094 self.assertEqual(2, self.proto.ByteSize())
2095 self.proto.optional_int32 = 128
2096 self.assertEqual(3, self.proto.ByteSize())
2097 self.proto.ClearField('optional_int32')
2098 self.assertEqual(0, self.proto.ByteSize())
2111 self.proto.repeated_int32.append(1)
2112 self.assertEqual(3, self.proto.ByteSize())
2113 self.proto.repeated_int32.append(1)
2114 self.assertEqual(6, self.proto.ByteSize())
2115 self.proto.repeated_int32[1] = 128
2116 self.assertEqual(7, self.proto.ByteSize())
2117 self.proto.ClearField('repeated_int32')
2118 self.assertEqual(0, self.proto.ByteSize())
2134 self.proto.optional_foreign_message.c = 1
2135 self.assertEqual(5, self.proto.ByteSize())
2136 self.proto.optional_foreign_message.c = 128
2137 self.assertEqual(6, self.proto.ByteSize())
2138 self.proto.optional_foreign_message.ClearField('c')
2139 self.assertEqual(3, self.proto.ByteSize())
2140 self.proto.ClearField('optional_foreign_message')
2141 self.assertEqual(0, self.proto.ByteSize())
2145 child = self.proto.optional_foreign_message
2146 self.proto.ClearField('optional_foreign_message')
2148 self.assertEqual(0, self.proto.ByteSize())
2163 child0 = self.proto.repeated_foreign_message.add()
2164 self.assertEqual(3, self.proto.ByteSize())
2165 self.proto.repeated_foreign_message.add()
2166 self.assertEqual(6, self.proto.ByteSize())
2168 self.assertEqual(8, self.proto.ByteSize())
2169 self.proto.ClearField('repeated_foreign_message')
2170 self.assertEqual(0, self.proto.ByteSize())
2314 proto = more_messages_pb2.OutOfOrderFields()
2318 proto.optional_sint32 = 5
2319 proto.Extensions[more_messages_pb2.optional_uint64] = 4
2320 proto.optional_uint32 = 3
2321 proto.Extensions[more_messages_pb2.optional_int64] = 2
2322 proto.optional_int32 = 1
2323 serialized = proto.SerializeToString()
2324 self.assertEqual(proto.ByteSize(), len(serialized))
2340 proto = unittest_pb2.TestFieldOrderings()
2341 test_util.SetAllFieldsAndExtensions(proto)
2342 serialized = proto.SerializeToString()
2369 proto = unittest_mset_pb2.TestMessageSet()
2374 proto.Extensions[extension1].i = 123
2375 proto.Extensions[extension2].str = 'foo'
2379 serialized = proto.SerializeToString()
2411 self.assertEqual(proto.ByteSize(), len(serialized))
2444 proto = unittest_mset_pb2.TestMessageSet()
2447 proto.MergeFromString(serialized))
2452 self.assertEquals(12345, proto.Extensions[extension1].i)
2455 proto = unittest_pb2.TestAllTypes()
2456 test_util.SetAllFields(proto)
2458 serialized = proto.SerializeToString()
2470 proto = unittest_pb2.TestAllTypes()
2471 proto.optional_int64 = 0x0fffffffffffffff
2472 serialized = proto.SerializeToString()
2493 proto = unittest_pb2.TestRequired()
2496 proto.SerializeToString,
2500 partial = proto.SerializePartialToString()
2508 proto.a = 1
2511 proto.SerializeToString,
2514 partial = proto.SerializePartialToString()
2516 proto.b = 2
2519 proto.SerializeToString,
2522 partial = proto.SerializePartialToString()
2524 proto.c = 3
2525 serialized = proto.SerializeToString()
2527 partial = proto.SerializePartialToString()
2544 proto = unittest_pb2.TestRequiredForeign()
2547 proto.SerializeToString()
2549 proto.optional_message.a = 1
2552 proto.SerializeToString,
2557 proto.optional_message.b = 2
2558 proto.optional_message.c = 3
2559 proto.SerializeToString()
2561 proto.repeated_message.add().a = 1
2562 proto.repeated_message.add().b = 2
2565 proto.SerializeToString,
2570 proto.repeated_message[0].b = 2
2571 proto.repeated_message[0].c = 3
2572 proto.repeated_message[1].a = 1
2573 proto.repeated_message[1].c = 3
2574 proto.SerializeToString()
2614 proto = unittest_pb2.TestPackedTypes()
2615 proto.packed_int32.extend([1, 2, 150, 3]) # 1 + 1 + 2 + 1 bytes
2616 proto.packed_double.extend([1.0, 1000.0]) # 8 + 8 bytes
2617 proto.packed_float.append(2.0) # 4 bytes, will be before double
2618 serialized = proto.SerializeToString()
2619 self.assertEqual(proto.ByteSize(), len(serialized))
2662 proto = unittest_pb2.TestAllTypes()
2704 proto = unittest_pb2.TestAllTypes(
2714 self.assertTrue(proto.IsInitialized())
2715 self.assertTrue(proto.HasField('optional_int32'))
2716 self.assertTrue(proto.HasField('optional_string'))
2717 self.assertTrue(proto.HasField('optional_bool'))
2718 self.assertTrue(proto.HasField('optional_bytes'))
2719 self.assertTrue(proto.HasField('optional_nested_message'))
2720 self.assertTrue(proto.HasField('optional_foreign_message'))
2721 self.assertTrue(proto.HasField('optional_nested_enum'))
2722 self.assertTrue(proto.HasField('optional_foreign_enum'))
2723 self.assertEqual(1, proto.optional_int32)
2724 self.assertEqual('foo', proto.optional_string)
2725 self.assertEqual(True, proto.optional_bool)
2726 self.assertEqual(b'bar', proto.optional_bytes)
2727 self.assertEqual(1, proto.optional_nested_message.bb)
2728 self.assertEqual(1, proto.optional_foreign_message.c)
2730 proto.optional_nested_enum)
2731 self.assertEqual(unittest_pb2.FOREIGN_FOO, proto.optional_foreign_enum)
2732 self.assertEqual([1, 2, 3], proto.repeated_int32)
2742 proto = unittest_pb2.TestRequired(a=1, b=1, c=1)
2743 self.assertTrue(proto.IsInitialized())
2744 self.assertTrue(proto.HasField('a'))
2745 self.assertTrue(proto.HasField('b'))
2746 self.assertTrue(proto.HasField('c'))
2747 self.assertTrue(not proto.HasField('dummy2'))
2748 self.assertEqual(1, proto.a)
2749 self.assertEqual(1, proto.b)
2750 self.assertEqual(1, proto.c)
2753 proto = unittest_pb2.TestRequiredForeign(
2755 self.assertTrue(proto.IsInitialized())
2756 self.assertTrue(proto.HasField('optional_message'))
2757 self.assertTrue(proto.optional_message.IsInitialized())
2758 self.assertTrue(proto.optional_message.HasField('a'))
2759 self.assertTrue(proto.optional_message.HasField('b'))
2760 self.assertTrue(proto.optional_message.HasField('c'))
2761 self.assertTrue(not proto.optional_message.HasField('dummy2'))
2763 proto.optional_message)
2764 self.assertEqual(1, proto.optional_message.a)
2765 self.assertEqual(1, proto.optional_message.b)
2766 self.assertEqual(1, proto.optional_message.c)
2769 proto = unittest_pb2.TestAllTypes(repeated_int32=[1, 2, 3])
2770 self.assertTrue(proto.IsInitialized())
2771 self.assertEqual(1, proto.repeated_int32[0])
2772 self.assertEqual(2, proto.repeated_int32[1])
2773 self.assertEqual(3, proto.repeated_int32[2])
2779 proto = unittest_mset_pb2.TestMessageSet()
2781 proto.DESCRIPTOR.GetOptions().message_set_wire_format)
2782 proto = unittest_pb2.TestAllTypes()
2784 proto.DESCRIPTOR.GetOptions().message_set_wire_format)
2787 proto = unittest_pb2.TestAllTypes()
2788 proto.optional_int32 = 1
2789 proto.optional_double = 3.0
2790 for field_descriptor, _ in proto.ListFields():
2793 proto = unittest_pb2.TestPackedTypes()
2794 proto.packed_int32.append(1)
2795 proto.packed_double.append(3.0)
2796 for field_descriptor, _ in proto.ListFields():