Пример #1
0
 def test_nested(self):
     message = test_pb2.Nested()
     message.child.value = 1.2
     record = proto_to_json.get_database_json(message)
     self.assertLen(record, 1)
     self.assertLen(record['child'], 1)
     self.assertAlmostEqual(record['child']['value'], 1.2, places=3)
Пример #2
0
 def setUp(self):
     super().setUp()
     self.messages = [
         test_pb2.Scalar(int32_value=3, float_value=4.5),
         test_pb2.RepeatedScalar(values=[1.2, 3.4]),
         test_pb2.Enum(value='FIRST'),
         test_pb2.RepeatedEnum(values=['FIRST', 'SECOND']),
         test_pb2.Nested(child=test_pb2.Nested.Child(value=1.2)),
     ]
Пример #3
0
 def test_nested(self):
     message = test_pb2.Nested()
     self.assertEmpty(
         message_helpers.find_submessages(message, test_pb2.Nested.Child))
     message.child.value = 5.6
     submessages = message_helpers.find_submessages(message,
                                                    test_pb2.Nested.Child)
     self.assertLen(submessages, 1)
     # Show that the returned submessages work as references.
     submessages[0].value = 7.8
     self.assertAlmostEqual(message.child.value, 7.8, places=4)