Пример #1
0
 def test_enum_fields(self):
     self.assertEqual('pw.test3.Nested(an_enum=pw.test3.Enum.ONE)',
                      proto_repr(self.nested(an_enum=1)))
     self.assertEqual('pw.test3.Message(optional_enum=pw.test3.Enum.ONE)',
                      proto_repr(self.message(optional_enum=self.enum.ONE)))
     self.assertEqual(
         'pw.test3.Message(repeated_enum='
         '[pw.test3.Enum.ONE, pw.test3.Enum.ONE, pw.test3.Enum.ZERO])',
         proto_repr(self.message(repeated_enum=[1, 1, 0])))
Пример #2
0
    def test_oneof(self):
        self.assertEqual(proto_repr(self.message(oneof_1='test')),
                         "pw.test3.Message(oneof_1='test')")
        self.assertEqual(proto_repr(self.message(oneof_2=123)),
                         "pw.test3.Message(oneof_2=123)")
        self.assertEqual(proto_repr(self.message(oneof_3=123)),
                         "pw.test3.Message(oneof_3=123.0)")

        msg = self.message(oneof_1='test')
        msg.oneof_2 = 99
        self.assertEqual(proto_repr(msg), "pw.test3.Message(oneof_2=99)")
Пример #3
0
 def test_message_fields(self):
     self.assertEqual(
         'pw.test3.Message(message=pw.test3.Nested(value=[123]))',
         proto_repr(self.message(message=self.nested(value=[123]))))
     self.assertEqual(
         'pw.test3.Message('
         'repeated_message=[pw.test3.Nested(value=[123]), '
         'pw.test3.Nested()])',
         proto_repr(
             self.message(
                 repeated_message=[self.nested(
                     value=[123]), self.nested()])))
Пример #4
0
 def test_optional_shown_if_set_to_default(self):
     self.assertEqual(
         "pw.test3.Message("
         "optional_int=0, optional_bytes=b'', optional_string='', "
         "optional_enum=pw.test3.Enum.ZERO)",
         proto_repr(
             self.message(optional_int=0,
                          optional_bytes=b'',
                          optional_string='',
                          optional_enum=0)))
Пример #5
0
 def test_int_fields(self):
     self.assertEqual(
         'pw.test3.Message('
         'regular_int=999, '
         'optional_int=-1, '
         'repeated_int=[0, 1, 2])',
         proto_repr(
             self.message(repeated_int=[0, 1, 2],
                          regular_int=999,
                          optional_int=-1)))
Пример #6
0
    def test_map(self):
        msg = self.message()
        msg.mapping['zero'].MergeFrom(self.nested())
        msg.mapping['one'].MergeFrom(
            self.nested(an_enum=self.enum.ONE, value=[1]))

        result = proto_repr(msg)
        self.assertRegex(result, r'^pw.test3.Message\(mapping={.*}\)$')
        self.assertIn("'zero': pw.test3.Nested()", result)
        self.assertIn(
            "'one': pw.test3.Nested(value=[1], an_enum=pw.test3.Enum.ONE)",
            result)
Пример #7
0
 def test_string_fields(self):
     self.assertEqual(
         'pw.test3.Message('
         "regular_string='hi', "
         "optional_string='', "
         'repeated_string=["\'"])',
         proto_repr(
             self.message(
                 regular_string='hi',
                 optional_string='',
                 repeated_string=[b"'"],
             )))
Пример #8
0
 def test_bytes_fields(self):
     self.assertEqual(
         'pw.test3.Message('
         r"regular_bytes=b'\xFE\xED\xBE\xEF', "
         r"optional_bytes=b'', "
         r"repeated_bytes=[b'Hello\'\'\''])",
         proto_repr(
             self.message(
                 regular_bytes=b'\xfe\xed\xbe\xef',
                 optional_bytes=b'',
                 repeated_bytes=[b"Hello'''"],
             )))
Пример #9
0
 def test_empty(self):
     self.assertEqual('pw.test3.Nested()', proto_repr(self.nested()))
     self.assertEqual('pw.test3.Message()', proto_repr(self.message()))