def _compare_nested_enums(self, nested_enum_dict_original,
                              nested_enum_dict_update):
        enum_name_original = set(nested_enum_dict_original.keys())
        enum_name_update = set(nested_enum_dict_update.keys())

        for name in enum_name_original - enum_name_update:
            EnumComparator(
                nested_enum_dict_original[name],
                None,
                self.finding_container,
                context=self.context,
            ).compare()
        for name in enum_name_update - enum_name_original:
            EnumComparator(
                None,
                nested_enum_dict_update[name],
                self.finding_container,
                context=self.context,
            ).compare()
        for name in enum_name_original & enum_name_update:
            EnumComparator(
                nested_enum_dict_original[name],
                nested_enum_dict_update[name],
                self.finding_container,
                context=self.context,
            ).compare()
Пример #2
0
 def _compare_enums(self, fs_original, fs_update):
     keys_original = set(fs_original.enums_map.keys())
     keys_update = set(fs_update.enums_map.keys())
     for name in keys_original - keys_update:
         EnumComparator(fs_original.enums_map.get(name), None).compare()
     for name in keys_update - keys_original:
         EnumComparator(None, fs_update.enums_map.get(name)).compare()
     for name in keys_update & keys_original:
         EnumComparator(fs_original.enums_map.get(name),
                        fs_update.enums_map.get(name)).compare()
Пример #3
0
    def _compare_nested_enums(self, nested_enum_dict_original,
                              nested_enum_dict_update):
        enum_name_original = set(nested_enum_dict_original.keys())
        enum_name_update = set(nested_enum_dict_update.keys())

        for name in enum_name_original - enum_name_update:
            EnumComparator(nested_enum_dict_original[name], None).compare()
        for name in enum_name_update - enum_name_original:
            EnumComparator(None, nested_enum_dict_update[name]).compare()
        for name in enum_name_original & enum_name_update:
            EnumComparator(
                nested_enum_dict_original[name],
                nested_enum_dict_update[name],
            ).compare()
 def test_enum_addition(self):
     EnumComparator(None, self.enum_update).compare()
     finding = FindingContainer.getAllFindings()[0]
     self.assertEqual(finding.message, "A new Enum PhoneType is added.")
     self.assertEqual(finding.category.name, "ENUM_ADDITION")
     self.assertEqual(finding.location.path,
                      "message_v1beta1.proto Line: 10")
 def test_enum_value_change(self):
     EnumComparator(self.enum_original, self.enum_update).compare()
     finding = FindingContainer.getAllFindings()[0]
     self.assertEqual(finding.message, "A new EnumValue SCHOOL is added.")
     self.assertEqual(finding.category.name, "ENUM_VALUE_ADDITION")
     self.assertEqual(finding.location.path,
                      "message_v1beta1.proto Line: 14")
Пример #6
0
 def enumNameChange(self):
     EnumComparator(self.enum_original, self.enum_update).compare()
     finding = FindingContainer.getAllFindings()[0]
     self.assertEqual(
         finding.message,
         'Name of the Enum is changed, the original is PhoneType, but the updated is PhoneTypeUpdate'
     )
     self.assertEqual(finding.category.name, 'ENUM_NAME_CHANGE')
 def test_enum_value_change(self):
     EnumComparator(self.enum_foo, self.enum_bar, self.finding_container).compare()
     finding = self.finding_container.getAllFindings()[0]
     self.assertEqual(finding.message, "A new EnumValue `VALUE2` is added.")
     self.assertEqual(finding.category.name, "ENUM_VALUE_ADDITION")
     self.assertEqual(finding.change_type.name, "MINOR")
     self.assertEqual(finding.location.proto_file_name, "test_update.proto")
     self.assertEqual(finding.location.source_code_line, 3)
 def test_enum_removal(self):
     EnumComparator(self.enum_foo, None, self.finding_container).compare()
     finding = self.finding_container.getAllFindings()[0]
     self.assertEqual(finding.message, "An existing Enum `Foo` is removed.")
     self.assertEqual(finding.category.name, "ENUM_REMOVAL")
     self.assertEqual(finding.change_type.name, "MAJOR")
     self.assertEqual(finding.location.proto_file_name, "test.proto")
     self.assertEqual(finding.location.source_code_line, 2)
 def test_enum_removal(self):
     EnumComparator(self.enum_foo,
                    None,
                    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, "test.proto")
     self.assertEqual(finding.location.source_code_line, 2)
 def test_enum_value_change(self):
     EnumComparator(self.enum_foo,
                    self.enum_bar,
                    self.finding_container,
                    context="ctx").compare()
     finding = self.finding_container.get_all_findings()[0]
     self.assertEqual(finding.category.name, "ENUM_VALUE_ADDITION")
     self.assertEqual(finding.change_type.name, "MINOR")
     self.assertEqual(finding.location.proto_file_name, "test_update.proto")
     self.assertEqual(finding.location.source_code_line, 3)
Пример #11
0
 def _compare_enums(self):
     keys_original = set(self.fs_original.enums_map.keys())
     keys_update = set(self.fs_update.enums_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 enum with version updates.
             EnumComparator(
                 self.fs_original.enums_map[name],
                 self.fs_update.enums_map[transformed_name],
                 self.finding_container,
                 context=name,
             ).compare()
             compared_update_keys.add(transformed_name)
         else:
             # Enum only exits in the original version.
             removed_enum = self.fs_original.enums_map[name]
             if removed_enum.proto_file_name not in self.original_definition_files:
                 # The removed enum is imported from dependency files.
                 # This should be caught at the fields level where this enum is referenced.
                 continue
             EnumComparator(
                 self.fs_original.enums_map[name],
                 None,
                 self.finding_container,
                 context=name,
             ).compare()
     for name in keys_update - compared_update_keys:
         # Enum only exits in the update version.
         added_enum = self.fs_update.enums_map[name]
         if added_enum.proto_file_name not in self.update_definition_files:
             # The added enum is imported from dependency files.
             # This should be caught at the fields level where this enum is referenced.
             continue
         EnumComparator(
             None,
             self.fs_update.enums_map[name],
             self.finding_container,
             context=name,
         ).compare()
 def test_no_api_change(self):
     EnumComparator(self.enum_update, self.enum_update).compare()
     self.assertEqual(len(FindingContainer.getAllFindings()), 0)
 def test_no_api_change(self):
     EnumComparator(self.enum_foo, self.enum_foo, self.finding_container).compare()
     self.assertEqual(len(self.finding_container.getAllFindings()), 0)
 def test_enum_removal(self):
     EnumComparator(self.enum_original, None).compare()
     finding = FindingContainer.getAllFindings()[0]
     self.assertEqual(finding.message, "An Enum PhoneType is removed")
     self.assertEqual(finding.category.name, "ENUM_REMOVAL")
     self.assertEqual(finding.location.path, "message_v1.proto Line: 10")
 def test_no_api_change(self):
     EnumComparator(self.enum_foo,
                    self.enum_foo,
                    self.finding_container,
                    context="ctx").compare()
     self.assertEqual(len(self.finding_container.get_all_findings()), 0)
Пример #16
0
 def enumAddition(self):
     EnumComparator(None, self.enum_update).compare()
     finding = FindingContainer.getAllFindings()[0]
     self.assertEqual(finding.message,
                      'A new Enum PhoneTypeUpdate is added.')
     self.assertEqual(finding.category.name, 'ENUM_ADDITION')
Пример #17
0
 def enumRemoval(self):
     EnumComparator(self.enum_original, None).compare()
     finding = FindingContainer.getAllFindings()[0]
     self.assertEqual(finding.message, 'An Enum PhoneType is removed')
     self.assertEqual(finding.category.name, 'ENUM_REMOVAL')