コード例 #1
0
    def testOrganizeFindingsByFile(self):
        finding1 = findings_lib.Finding(
            'error1', findings_lib.FileContext(filepath='path1'))
        finding2 = findings_lib.Finding(
            'error2', findings_lib.FileContext(filepath='path1'))
        finding3 = findings_lib.Finding(
            'error3', findings_lib.FileContext(filepath='path2'))
        finding4 = findings_lib.Finding(
            'error4', findings_lib.FileContext(filepath='path3'))

        findings_list = [finding1, finding2, finding3, finding4]
        findings_map = presubmit_validate_types_lib.OrganizeFindingsByFile(
            findings_list)

        self.assertLen(findings_map, 3)
        path1_list = findings_map.get('path1')
        path2_list = findings_map.get('path2')
        path3_list = findings_map.get('path3')

        self.assertLen(path1_list, 2)
        self.assertIn(finding1, path1_list)
        self.assertIn(finding2, path1_list)
        self.assertLen(path2_list, 1)
        self.assertIn(finding3, path2_list)
        self.assertLen(path3_list, 1)
        self.assertIn(finding4, path3_list)
コード例 #2
0
    def testFindingsHandlesDeduplication(self):
        high = findings_lib.Finding('high', findings_lib.FileContext('f'), 2,
                                    2, 2, 'key', False)
        med = findings_lib.Finding('med', findings_lib.FileContext('f'), 3, 2,
                                   2, 'key', False)
        low = findings_lib.Finding('low', findings_lib.FileContext('f'), 3, 3,
                                   2, 'key', False)
        bottom = findings_lib.Finding('bottom', findings_lib.FileContext('f'),
                                      3, 3, 3, 'key', False)
        master = findings_lib.Finding('master', findings_lib.FileContext('f'),
                                      3, 3, 3, 'key', True)
        # Check each paired sort, working from lowest to highest
        self.findings_class.AddFinding(master)
        self.findings_class.AddFinding(bottom)
        findings = self.findings_class.GetFindings()
        self.assertLen(findings, 1)
        self.assertEqual('master', findings[0].message)

        self.findings_class.AddFinding(low)
        self.findings_class.AddFinding(bottom)
        findings = self.findings_class.GetFindings()
        self.assertLen(findings, 1)
        self.assertEqual('low', findings[0].message)

        self.findings_class.AddFinding(med)
        self.findings_class.AddFinding(low)
        findings = self.findings_class.GetFindings()
        self.assertLen(findings, 1)
        self.assertEqual('med', findings[0].message)

        self.findings_class.AddFinding(high)
        self.findings_class.AddFinding(med)
        findings = self.findings_class.GetFindings()
        self.assertLen(findings, 1)
        self.assertEqual('high', findings[0].message)
コード例 #3
0
    def testFindingBadFileContext(self):
        # no file context
        with self.assertRaises(TypeError):
            findings_lib.Finding('message')

        # wrong type
        with self.assertRaises(TypeError):
            findings_lib.Finding('message', 'filepath')
コード例 #4
0
    def testFindingBadMessage(self):
        # no message
        with self.assertRaises(TypeError):
            findings_lib.Finding(self.file_context)

        # message isn't string
        some_list = []
        with self.assertRaises(TypeError):
            findings_lib.Finding(some_list, self.file_context)
コード例 #5
0
    def testFindingEqualityKey(self):
        key = object()
        key2 = object()

        finding1 = findings_lib.Finding('',
                                        self.file_context,
                                        equality_key=key)
        finding2 = findings_lib.Finding('',
                                        self.file_context,
                                        equality_key=key)
        finding3 = findings_lib.Finding('',
                                        self.file_context,
                                        equality_key=key2)
        finding4 = findings_lib.Finding('', self.file_context)

        self.assertEqual(finding1, finding2)
        self.assertNotEqual(finding1, finding3)
        self.assertNotEqual(finding1, finding4)
        self.assertEqual(finding4, finding4)
コード例 #6
0
 def testFindingGood(self):
     findings_lib.Finding('message', self.file_context)