示例#1
0
 def _compare_messages(self, fs_original, fs_update):
     keys_original = set(fs_original.messages_map.keys())
     keys_update = set(fs_update.messages_map.keys())
     for name in keys_original - keys_update:
         DescriptorComparator(fs_original.messages_map.get(name),
                              None).compare()
     for name in keys_update - keys_original:
         DescriptorComparator(None,
                              fs_update.messages_map.get(name)).compare()
     for name in keys_update & keys_original:
         DescriptorComparator(
             fs_original.messages_map.get(name),
             fs_update.messages_map.get(name),
         ).compare()
示例#2
0
 def fieldChange(self):
     DescriptorComparator(self.addressBook_msg,
                          self.addressBook_msg_update).compare()
     finding = FindingContainer.getAllFindings()[0]
     self.assertEqual(finding.message,
                      'The Field deprecated is moved out of one-of')
     self.assertEqual(finding.category.name, 'FIELD_ONEOF_REMOVAL')
 def test_nested_enum_change(self):
     nested_enum1 = make_enum(
         name="Foo",
         values=(
             ("RED", 1),
             ("GREEN", 2),
         ),
     )
     nested_enum2 = make_enum(
         name="Foo",
         values=(
             ("RED", 1),
             ("GREEN", 2),
             ("BLUE", 3),
         ),
     )
     message1 = make_message(nested_enums=[nested_enum1])
     message2 = make_message(nested_enums=[nested_enum2])
     DescriptorComparator(message1,
                          message2,
                          self.finding_container,
                          context="ctx").compare()
     finding = next(f for f in self.finding_container.get_all_findings()
                    if f.category.name == "ENUM_VALUE_ADDITION")
     self.assertEqual(finding.change_type.name, "MINOR")
     self.assertEqual(finding.location.proto_file_name, "foo")
 def test_nested_enum_change(self):
     nested_enum1 = make_enum(
         name="Foo",
         values=(
             ("RED", 1),
             ("GREEN", 2),
         ),
     )
     nested_enum2 = make_enum(
         name="Foo",
         values=(
             ("RED", 1),
             ("GREEN", 2),
             ("BLUE", 3),
         ),
     )
     message1 = make_message(nested_enums=[nested_enum1])
     message2 = make_message(nested_enums=[nested_enum2])
     DescriptorComparator(message1, message2,
                          self.finding_container).compare()
     findings_map = {
         f.message: f
         for f in self.finding_container.getAllFindings()
     }
     finding = findings_map["A new EnumValue `BLUE` is added."]
     self.assertEqual(finding.category.name, "ENUM_VALUE_ADDITION")
     self.assertEqual(finding.change_type.name, "MINOR")
     self.assertEqual(finding.location.proto_file_name, "foo")
 def test_message_addition(self):
     DescriptorComparator(None, self.message_foo,
                          self.finding_container).compare()
     finding = self.finding_container.getAllFindings()[0]
     self.assertEqual(finding.message, "A new message `Message` is added.")
     self.assertEqual(finding.category.name, "MESSAGE_ADDITION")
     self.assertEqual(finding.change_type.name, "MINOR")
     self.assertEqual(finding.location.proto_file_name, "foo")
 def test_message_removal(self):
     DescriptorComparator(self.message_foo,
                          None,
                          self.finding_container,
                          context="ctx").compare()
     finding = self.finding_container.get_all_findings()[0]
     self.assertEqual(finding.category.name, "MESSAGE_REMOVAL")
     self.assertEqual(finding.change_type.name, "MAJOR")
     self.assertEqual(finding.location.proto_file_name, "foo")
 def test_nested_field_addition(self):
     field_int = make_field(proto_type="TYPE_INT32")
     message_update = make_message(fields=[field_int])
     DescriptorComparator(make_message(), message_update,
                          self.finding_container).compare()
     finding = self.finding_container.getAllFindings()[0]
     self.assertEqual(finding.category.name, "FIELD_ADDITION")
     self.assertEqual(finding.change_type.name, "MINOR")
     self.assertEqual(finding.location.proto_file_name, "foo")
 def test_message_removal(self):
     DescriptorComparator(self.message_foo, None,
                          self.finding_container).compare()
     finding = self.finding_container.getAllFindings()[0]
     self.assertEqual(finding.message,
                      "An existing message `Message` is removed.")
     self.assertEqual(finding.category.name, "MESSAGE_REMOVAL")
     self.assertEqual(finding.change_type.name, "MAJOR")
     self.assertEqual(finding.location.proto_file_name, "foo")
 def test_message_addition(self):
     DescriptorComparator(None,
                          self.message_foo,
                          self.finding_container,
                          context="ctx").compare()
     finding = self.finding_container.get_all_findings()[0]
     self.assertEqual(finding.category.name, "MESSAGE_ADDITION")
     self.assertEqual(finding.change_type.name, "MINOR")
     self.assertEqual(finding.location.proto_file_name, "foo")
示例#10
0
 def nestedMessageChange(self):
     # Field `type` in nested message `PhoneNumber` is re-numbered. So it is taken as one field removed and one field added.
     DescriptorComparator(self.person_msg, self.person_msg_update).compare()
     findingLength = len(FindingContainer.getAllFindings())
     self.assertEqual(
         FindingContainer.getAllFindings()[findingLength - 1].category.name,
         'FIELD_ADDITION')
     self.assertEqual(
         FindingContainer.getAllFindings()[findingLength - 2].category.name,
         'FIELD_REMOVAL')
 def test_nested_enum_addition(self):
     DescriptorComparator(
         make_message(),
         make_message(nested_enums=[make_enum(name="nested_message")]),
         self.finding_container,
     ).compare()
     finding = self.finding_container.getAllFindings()[0]
     self.assertEqual(finding.category.name, "ENUM_ADDITION")
     self.assertEqual(finding.change_type.name, "MINOR")
     self.assertEqual(finding.location.proto_file_name, "foo")
示例#12
0
 def _compare_messages(self):
     keys_original = set(self.fs_original.messages_map.keys())
     keys_update = set(self.fs_update.messages_map.keys())
     compared_update_keys = set()
     for name in keys_original:
         transformed_name = (name if name in keys_update else
                             self._get_version_update_name(name))
         if transformed_name in keys_update:
             # Common dependency or same message with version updates.
             DescriptorComparator(
                 self.fs_original.messages_map[name],
                 self.fs_update.messages_map[transformed_name],
                 self.finding_container,
                 context=name,
             ).compare()
             compared_update_keys.add(transformed_name)
         else:
             # Message only exits in the original version.
             message = self.fs_original.messages_map[name]
             if message.proto_file_name not in self.original_definition_files:
                 # The removed message is imported from dependency files.
                 # This should be caught at the fields level where this message is referenced.
                 continue
             DescriptorComparator(
                 self.fs_original.messages_map[name],
                 None,
                 self.finding_container,
                 context=name,
             ).compare()
     for name in keys_update - compared_update_keys:
         # Message only exits in the update version.
         message = self.fs_update.messages_map[name]
         if message.proto_file_name not in self.update_definition_files:
             # The added message is imported from dependency files.
             # This should be caught at the fields level where this message is referenced.
             continue
         DescriptorComparator(
             None,
             self.fs_update.messages_map[name],
             self.finding_container,
             context=name,
         ).compare()
 def test_nested_enum_removal(self):
     DescriptorComparator(
         make_message(nested_enums=[make_enum(name="nested_message")]),
         make_message(),
         self.finding_container,
         context="ctx",
     ).compare()
     finding = self.finding_container.get_all_findings()[0]
     self.assertEqual(finding.category.name, "ENUM_REMOVAL")
     self.assertEqual(finding.change_type.name, "MAJOR")
     self.assertEqual(finding.location.proto_file_name, "foo")
 def test_nested_message_removal(self):
     DescriptorComparator(
         make_message(nested_messages=[make_message(
             name="nested_message")]),
         make_message(),
         self.finding_container,
     ).compare()
     finding = self.finding_container.getAllFindings()[0]
     self.assertEqual(finding.category.name, "MESSAGE_REMOVAL")
     self.assertEqual(finding.change_type.name, "MAJOR")
     self.assertEqual(finding.location.proto_file_name, "foo")
 def test_nested_message_addition(self):
     DescriptorComparator(
         make_message(),
         make_message(nested_messages=[make_message(
             name="nested_message")]),
         self.finding_container,
         context="ctx",
     ).compare()
     finding = self.finding_container.get_all_findings()[0]
     self.assertEqual(finding.category.name, "MESSAGE_ADDITION")
     self.assertEqual(finding.change_type.name, "MINOR")
     self.assertEqual(finding.location.proto_file_name, "foo")
 def test_nested_field_type_change(self):
     field_int = make_field(proto_type="TYPE_INT32")
     field_string = make_field(proto_type="TYPE_STRING")
     message1 = make_message(fields=[field_int])
     message2 = make_message(fields=[field_string])
     DescriptorComparator(message1,
                          message2,
                          self.finding_container,
                          context="ctx").compare()
     finding = next(f for f in self.finding_container.get_all_findings()
                    if f.category.name == "FIELD_TYPE_CHANGE")
     self.assertEqual(finding.change_type.name, "MAJOR")
     self.assertEqual(finding.location.proto_file_name, "foo")
 def test_nested_field_type_change(self):
     field_int = make_field(proto_type="TYPE_INT32")
     field_string = make_field(proto_type="TYPE_STRING")
     message1 = make_message(fields=[field_int])
     message2 = make_message(fields=[field_string])
     DescriptorComparator(message1, message2,
                          self.finding_container).compare()
     findings_map = {
         f.message: f
         for f in self.finding_container.getAllFindings()
     }
     finding = findings_map[
         "Type of an existing field `my_field` is changed from `int32` to `string`."]
     self.assertEqual(finding.category.name, "FIELD_TYPE_CHANGE")
     self.assertEqual(finding.change_type.name, "MAJOR")
     self.assertEqual(finding.location.proto_file_name, "foo")
 def test_nested_message_change(self):
     nested_field = make_field(name="nested_field")
     nested_message_with_fields = make_message(name="nested_message",
                                               fields=[nested_field])
     nested_message_without_fields = make_message(name="nested_message")
     message1 = make_message(nested_messages=[nested_message_with_fields])
     message2 = make_message(
         nested_messages=[nested_message_without_fields])
     DescriptorComparator(message1,
                          message2,
                          self.finding_container,
                          context="ctx").compare()
     finding = next(f for f in self.finding_container.get_all_findings()
                    if f.category.name == "FIELD_REMOVAL")
     self.assertEqual(finding.change_type.name, "MAJOR")
     self.assertEqual(finding.location.proto_file_name, "foo")
 def test_nested_message_change(self):
     nested_field = make_field(name="nested_field")
     nested_message_with_fields = make_message(name="nested_message",
                                               fields=[nested_field])
     nested_message_without_fields = make_message(name="nested_message")
     message1 = make_message(nested_messages=[nested_message_with_fields])
     message2 = make_message(
         nested_messages=[nested_message_without_fields])
     DescriptorComparator(message1, message2,
                          self.finding_container).compare()
     findings_map = {
         f.message: f
         for f in self.finding_container.getAllFindings()
     }
     finding = findings_map["An existing field `nested_field` is removed."]
     self.assertEqual(finding.category.name, "FIELD_REMOVAL")
     self.assertEqual(finding.change_type.name, "MAJOR")
     self.assertEqual(finding.location.proto_file_name, "foo")
示例#20
0
 def messageAddition(self):
     DescriptorComparator(None, self.addressBook_msg).compare()
     finding = FindingContainer.getAllFindings()[0]
     self.assertEqual(finding.message,
                      'A new message AddressBook is added.')
     self.assertEqual(finding.category.name, 'MESSAGE_ADDITION')
示例#21
0
 def messageRemoval(self):
     DescriptorComparator(self.person_msg, None).compare()
     finding = FindingContainer.getAllFindings()[0]
     self.assertEqual(finding.message, 'A message Person is removed')
     self.assertEqual(finding.category.name, 'MESSAGE_REMOVAL')