|
36 | 36 | LineComparison, |
37 | 37 | MissingComparisonReport, |
38 | 38 | PullRequestComparison, |
| 39 | + Segment, |
39 | 40 | ) |
40 | 41 |
|
41 | 42 | # Pulled from shared.django_apps.core.tests.factories.CommitFactory files. |
@@ -1784,6 +1785,52 @@ def test_file_has_changes(self): |
1784 | 1785 | ) |
1785 | 1786 | assert file.has_changes is True |
1786 | 1787 |
|
| 1788 | + def test_remove_unintended_changes(self): |
| 1789 | + lines = [ |
| 1790 | + LineComparison( |
| 1791 | + {"base": 1, "head": 1}, |
| 1792 | + {"base": 1, "head": 1}, |
| 1793 | + "line1", |
| 1794 | + added=False, |
| 1795 | + removed=False, |
| 1796 | + ), |
| 1797 | + LineComparison( |
| 1798 | + {"base": 1, "head": 0}, |
| 1799 | + {"base": 2, "head": 2}, |
| 1800 | + "line2", |
| 1801 | + added=False, |
| 1802 | + removed=False, |
| 1803 | + ), |
| 1804 | + LineComparison( |
| 1805 | + {"base": 0, "head": 0}, |
| 1806 | + {"base": None, "head": 3}, |
| 1807 | + "+line3", |
| 1808 | + added=True, |
| 1809 | + removed=False, |
| 1810 | + ), |
| 1811 | + LineComparison( |
| 1812 | + {"base": 0, "head": 0}, |
| 1813 | + {"base": 4, "head": None}, |
| 1814 | + "-line4", |
| 1815 | + added=False, |
| 1816 | + removed=True, |
| 1817 | + ), |
| 1818 | + LineComparison( |
| 1819 | + {"base": 1, "head": 0}, |
| 1820 | + {"base": 5, "head": 5}, |
| 1821 | + "line5", |
| 1822 | + added=False, |
| 1823 | + removed=False, |
| 1824 | + ), |
| 1825 | + ] |
| 1826 | + |
| 1827 | + segment = Segment(lines) |
| 1828 | + segment.remove_unintended_changes() |
| 1829 | + |
| 1830 | + # Only lines with code changes or no changes remain; coverage-only changes removed |
| 1831 | + assert len(segment.lines) == 3 |
| 1832 | + assert [line.value for line in segment.lines] == ["line1", "+line3", "-line4"] |
| 1833 | + |
1787 | 1834 |
|
1788 | 1835 | class CommitComparisonTests(TestCase): |
1789 | 1836 | def setUp(self): |
|
0 commit comments