Esempio n. 1
0
 def test_delete_one(self):
     ref = textwrap.dedent("""\
                 line1
                 deleteme
                 line2
             """).splitlines()
     new = textwrap.dedent("""\
                 line1
                 line2
             """).splitlines()
     syntax, = [
         i.strip() for i in difflib.unified_diff(ref, new, n=0)
         if i.startswith("@@")
     ]
     assert syntax == "@@ -2 +1,0 @@"
     expected = ("delete", 2, 1)  # "d",start1,start2
     actual = DiffList._translate_diff_syntax(syntax)
     assert actual == expected
Esempio n. 2
0
 def test_change_one(self):
     ref = textwrap.dedent("""\
                 line1
                 oldline
                 line2
             """).splitlines()
     new = textwrap.dedent("""\
                 line1
                 newline
                 line2
             """).splitlines()
     syntax, = [
         i.strip() for i in difflib.unified_diff(ref, new, n=0)
         if i.startswith("@@")
     ]
     assert syntax == "@@ -2 +2 @@"
     expected = ("change", 2, 2)  # "c",start1,start2
     actual = DiffList._translate_diff_syntax(syntax)
     assert actual == expected
Esempio n. 3
0
 def test_insert_many(self):
     ref = textwrap.dedent("""\
                 line1
                 line4
             """).splitlines()
     new = textwrap.dedent("""\
                 line1
                 line2
                 line3
                 line4
             """).splitlines()
     syntax, = [
         i.strip() for i in difflib.unified_diff(ref, new, n=0)
         if i.startswith("@@")
     ]
     assert syntax == "@@ -1,0 +2,2 @@"
     expected = ("insert", 1, 2)
     actual = DiffList._translate_diff_syntax(syntax)
     assert actual == expected
Esempio n. 4
0
    def test_malformed1(self):
        expected_msg = "malformed unified diff hunk syntax"

        syntax = "@@ 7 @@"
        with pytest.raises(ValueError) as excinfo:
            DiffList._translate_diff_syntax(syntax)
        assert expected_msg in str(excinfo.value)

        syntax = "@@ 7 10 0 @@"
        with pytest.raises(ValueError) as excinfo:
            DiffList._translate_diff_syntax(syntax)
        assert expected_msg in str(excinfo.value)

        syntax = "@@ 2,3 4,5"
        with pytest.raises(ValueError) as excinfo:
            DiffList._translate_diff_syntax(syntax)
        assert expected_msg in str(excinfo.value)
Esempio n. 5
0
    def test_insert_one(self):
        ref = textwrap.dedent("""\
                    line1
                    line2
                """).splitlines()
        new = textwrap.dedent("""\
                    line1
                    insert
                    line2
                """).splitlines()
        syntax, = [
            i.strip() for i in difflib.unified_diff(ref, new, n=0)
            if i.startswith("@@")
        ]

        # unified diff hunk format:
        # @@ -start,count +start,count @@
        # -start and +start are starting line numbers in first and second file
        # count is omitted if 1
        # see https://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html#Detailed-Unified
        assert syntax == "@@ -1,0 +2 @@"
        expected = ("insert", 1, 2)  # "i",start1,start2
        actual = DiffList._translate_diff_syntax(syntax)
        assert actual == expected