Example #1
0
    def test_keep_issues_in_diff(self):
        issues = [
            Issue("A.java", 10),
            Issue("B.java", 30),
            Issue("B.java", 15)
        ]

        diffFileA = ChangedFile("A.java")
        diffFileA.append(Range(3, 7))
        diffFileA.append(Range(13, 20))

        diffFileB = ChangedFile("B.java")
        diffFileB.append(Range(30, 32))
        diffFileB.append(Range(20, 24))

        diffFileC = ChangedFile("C.java")
        diffFileC.append(Range(27, 32))
        diffFileC.append(Range(31, 31))
        diffFileC.append(Range(40, 45))

        changedFiles = [diffFileA, diffFileB, diffFileC]

        diff = DiffFile("")
        setattr(diff, 'files', changedFiles)

        report = Report("")
        setattr(report, 'issues', issues)
        issuesInDiff = report.issuesIn(diff)

        self.assertEquals(len(issuesInDiff), 1)
        self.assertEquals(issuesInDiff[0].file_name, "B.java")
        self.assertEquals(issuesInDiff[0].line_number, 30)
Example #2
0
    def test_extract_line_range_extract_one_ranges_for_file_two(self):
        files = DiffFile("test/sa_diff/diff.txt").files

        self.assertEquals(files[1].name, "ILink.java")
        self.assertEquals(len(files[1].ranges), 1)

        self.assertEquals(files[1].ranges[0].lowerBound, 1)
        self.assertEquals(files[1].ranges[0].higherBound, 15)
Example #3
0
    def test_extract_line_range_extract_2_ranges_for_file_four(self):
        files = DiffFile("test/sa_diff/diff.txt").files

        self.assertEquals(files[3].name, "NcpLink.java")
        self.assertEquals(len(files[3].ranges), 2)

        self.assertEquals(files[3].ranges[0].lowerBound, 8)
        self.assertEquals(files[3].ranges[0].higherBound, 18)
        self.assertEquals(files[3].ranges[1].lowerBound, 705)
        self.assertEquals(files[3].ranges[1].higherBound, 729)
Example #4
0
    def test_extract_line_range_extract_2_ranges_for_file_three(self):
        files = DiffFile("test/sa_diff/diff.txt").files

        self.assertEquals(files[2].name, "CpoLink.java")
        self.assertEquals(len(files[2].ranges), 2)

        self.assertEquals(files[2].ranges[0].lowerBound, 9)
        self.assertEquals(files[2].ranges[0].higherBound, 19)
        self.assertEquals(files[2].ranges[1].lowerBound, 804)
        self.assertEquals(files[2].ranges[1].higherBound, 823)
Example #5
0
    def test_keep_issues_in_diff_when_issue_is_on_last_line(self):
        issues = [Issue("A.java", 22)]

        diffFile = ChangedFile("A.java")
        diffFile.append(Range(10, 15))
        diffFile.append(Range(20, 22))

        diff = DiffFile("")
        setattr(diff, 'files', [diffFile])

        report = Report("")
        setattr(report, 'issues', issues)
        issuesInDiff = report.issuesIn(diff)

        self.assertEquals(len(issuesInDiff), 1)
        self.assertEquals(issuesInDiff[0].file_name, "A.java")
        self.assertEquals(issuesInDiff[0].line_number, 22)
Example #6
0
    def test_keep_issues_in_diff_when_no_issue_in_diff(self):
        issues = [
            Issue("A.java", 70),
            Issue("A.java", 80),
            Issue("B.java", 40)
        ]

        diffFileA = ChangedFile("A.java")
        diffFileA.append(Range(10, 15))
        diffFileA.append(Range(20, 22))

        diffFileB = ChangedFile("B.java")
        diffFileB.append(Range(10, 15))
        diffFileB.append(Range(20, 22))

        diff = DiffFile("")
        setattr(diff, 'files', [diffFileA, diffFileB])

        report = Report("")
        setattr(report, 'issues', issues)
        issuesInDiff = report.issuesIn(diff)
        self.assertEquals(len(issuesInDiff), 0)
Example #7
0
    def test_extract_line_range_extract_4_files(self):
        files = DiffFile("test/sa_diff/diff.txt").files

        self.assertEquals(len(files), 4)