Example #1
0
    def test_add(self):
        patcher = LinePatcher()

        patch = Patch('', 1, 1, 1, 1)
        patcher.add(patch)

        assert patcher._patches == [patch]
        assert patcher._sorted is False
Example #2
0
    def test_add_multiple(self):
        patcher = LinePatcher()

        patch = Patch('', 1, 1, 1, 1)
        patcher.add(patch)

        patch2 = Patch('', 1, 1, 1, 1)
        patcher.add(patch2)

        assert patcher._patches == [patch, patch2]
        assert patcher._sorted is False
Example #3
0
    def test_sort(self):
        patcher = LinePatcher()

        p1 = Patch('', 1, 1, 1, 1)
        p2 = Patch('', 4, 1, 5, 1)
        p3 = Patch('', 2, 1, 2, 1)

        patcher.add(p1)
        patcher.add(p2)
        patcher.add(p3)
        patcher._sort_patches()

        assert patcher._sorted is True
        assert patcher._patches == [p2, p3, p1]
Example #4
0
 def test_patch_indented(self, patches, expected):
     patcher = LinePatcher()
     for p in patches:
         patcher.add(p)
     assert '\n'.join(patcher.patch(
         self.content_indented)) == trim(expected)
Example #5
0
 def test_insert_after(self, patches, expected):
     patcher = LinePatcher()  # Insert after the line is default.
     for p in patches:
         patcher.add(p)
     assert '\n'.join(patcher.patch(self.content)) == trim(expected)
Example #6
0
 def test_insert_before(self, patches, expected):
     patcher = LinePatcher(insert_after=False)
     for p in patches:
         patcher.add(p)
     assert '\n'.join(patcher.patch(self.content)) == trim(expected)