def test_add(self): patcher = LinePatcher() patch = Patch('', 1, 1, 1, 1) patcher.add(patch) assert patcher._patches == [patch] assert patcher._sorted is False
def test_patch_empty(self): content = trim_docstring(""" """, strip_leading=True, as_string=False) patcher = LinePatcher() assert patcher.patch(content) is content
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]
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
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)
def test_construct(self): patcher = LinePatcher() assert patcher._patches == [] assert patcher._sorted is False
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)
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)