def test_replace(self): db = PatchSeries(os.path.join(test_dir, "data", "db"), "series_replace1") self.assertTrue(db.exists()) self.assertFalse(db.is_empty()) self.assertEqual(len(db.patches()), 3) patch1 = Patch("patch1") patch2 = Patch("patch2") patch4 = Patch("patch4") patch5 = Patch("patch5") self.assertTrue(db.is_patch(patch1)) db.replace(patch1, patch4) self.assertFalse(db.is_patch(patch1)) self.assertTrue(db.is_patch(patch4)) self.assertTrue(db.is_patch(patch2)) db.replace(patch2, patch5) self.assertFalse(db.is_patch(patch2)) self.assertTrue(db.is_patch(patch5)) patchline = db.patch2line[patch5] self.assertEqual(patchline.get_comment(), " my comment")
def test_patch_equivalence(self): a = Patch("same") self.assertTrue(a == a) self.assertFalse(a != a) b = Patch("same") self.assertTrue(a == b) self.assertFalse(a != b) self.assertEqual(hash(a), hash(b)) c = Patch("different") self.assertTrue(a != c) self.assertFalse(a == c)
def test_unreverted(self): """ Test when the patch modifies unreverted files """ with tmp_series() as [dir, series]: old_dir = os.getcwd() try: os.chdir(dir) db = Db(dir) db.add_patch(Patch("patch")) db.save() originals = os.path.join(db.dirname, "patch") os.mkdir(originals) make_file(b"unreverted original\n", originals, "unreverted") make_file(b"reverted original\n", originals, "reverted") make_file(b"unreverted patched\n", dir, "unreverted") make_file(b"reverted patched\n", dir, "reverted") Refresh(dir, db.dirname, series.dirname).refresh() make_file(b"unreverted change\n", dir, "unreverted") make_file(b"reverted change\n", dir, "reverted") cmd = quilt.revert.Revert(dir, db.dirname, series.dirname) cmd.revert_file("reverted") with open(os.path.join(dir, "reverted"), "rb") as file: self.assertEqual(file.read(), b"reverted patched\n") with open(os.path.join(dir, "unreverted"), "rb") as file: self.assertEqual(file.read(), b"unreverted change\n") finally: os.chdir(old_dir)
def test_series(self): firstpatch = Patch("firstpatch") lastpatch = Patch("lastpatch") secondpatch = Patch("secondpatch") thirdpatch = Patch("thirdpatch") db = PatchSeries(os.path.join(test_dir, "data", "db"), "series_test1") self.assertEqual( patch_list([ "firstpatch", "secondpatch", "thirdpatch", "patchwith.patch", "patchwith.diff", "patchwith", "lastpatch" ]), db.patches()) self.assertEqual(firstpatch, db.first_patch()) self.assertEqual(lastpatch, db.top_patch()) self.assertEqual(secondpatch, db.patch_after(firstpatch)) self.assertEqual(secondpatch, db.patch_before(thirdpatch)) self.assertTrue(db.is_patch(thirdpatch)) self.assertFalse(db.is_patch(Patch("notapatch"))) self.assertEqual([], db.patches_before(firstpatch)) self.assertEqual(patch_list(["firstpatch", "secondpatch"]), db.patches_before(thirdpatch)) self.assertEqual( patch_list([ "patchwith.patch", "patchwith.diff", "patchwith", "lastpatch" ]), db.patches_after(thirdpatch)) self.assertEqual([], db.patches_after(lastpatch)) self.assertEqual(None, db.patch_after(lastpatch)) self.assertEqual(thirdpatch, db.patch_after(secondpatch)) self.assertEqual( patch_list(["firstpatch", "secondpatch", "thirdpatch"]), db.patches_until(thirdpatch)) # test re-reading patches list db.read() self.assertEqual( patch_list([ "firstpatch", "secondpatch", "thirdpatch", "patchwith.patch", "patchwith.diff", "patchwith", "lastpatch" ]), db.patches())
def test_refresh(self): with TmpDirectory() as dir: old_dir = os.getcwd() try: os.chdir(dir.get_name()) db = Db(".pc") db.create() backup = os.path.join(".pc", "patch") os.mkdir(backup) make_file(b"", backup, "file") db.add_patch(Patch("patch")) db.save() make_file(b"", "patch") make_file(b"added\n", "file") cmd = quilt.refresh.Refresh(".", ".pc", ".") cmd.refresh() with open("patch", "r") as patch: self.assertTrue(patch.read(30)) finally: os.chdir(old_dir)
def patch_list(patch_names): return [Patch(name) for name in patch_names]
def test_save(self): with tmp_series() as [dir, series]: series.add_patch(Patch("test.patch")) series.save() with open(series.series_file, "rb") as file: self.assertEqual(file.read(), b"test.patch\n")
def test_add_remove(self): # test add, remove patches firstpatch = Patch("firstpatch") lastpatch = Patch("lastpatch") newlastpatch = Patch("newlastpatch") db = PatchSeries(os.path.join(test_dir, "data", "db"), "series_test1") db.add_patch(newlastpatch) self.assertTrue(db.is_patch(newlastpatch)) self.assertEqual( patch_list([ "firstpatch", "secondpatch", "thirdpatch", "patchwith.patch", "patchwith.diff", "patchwith", "lastpatch", "newlastpatch" ]), db.patches()) self.assertEqual(newlastpatch, db.top_patch()) db.remove_patch(newlastpatch) self.assertFalse(db.is_patch(newlastpatch)) self.assertEqual( patch_list([ "firstpatch", "secondpatch", "thirdpatch", "patchwith.patch", "patchwith.diff", "patchwith", "lastpatch" ]), db.patches()) self.assertEqual(lastpatch, db.top_patch()) newfirst1 = Patch("newfirst1") newfirst2 = Patch("newfirst2") db.add_patches([newfirst1, newfirst2]) self.assertTrue(db.is_patch(newfirst1)) self.assertTrue(db.is_patch(newfirst2)) self.assertEqual( patch_list([ "newfirst1", "newfirst2", "firstpatch", "secondpatch", "thirdpatch", "patchwith.patch", "patchwith.diff", "patchwith", "lastpatch" ]), db.patches()) self.assertEqual(lastpatch, db.top_patch()) newlast1 = Patch("newlast1") newlast2 = Patch("newlast2") db = PatchSeries(os.path.join(test_dir, "data", "db"), "series_test1") db.add_patches([newlast1, newlast2], firstpatch) self.assertTrue(db.is_patch(newlast1)) self.assertTrue(db.is_patch(newlast2)) self.assertEqual( patch_list([ "firstpatch", "newlast1", "newlast2", "secondpatch", "thirdpatch", "patchwith.patch", "patchwith.diff", "patchwith", "lastpatch" ]), db.patches()) self.assertEqual(lastpatch, db.top_patch()) db = PatchSeries(os.path.join(test_dir, "data", "db"), "series_test1") newfirst1 = Patch("newfirst1") newfirst2 = Patch("newfirst2") db.insert_patches([newfirst1, newfirst2]) self.assertTrue(db.is_patch(newfirst1)) self.assertTrue(db.is_patch(newfirst2)) self.assertEqual( patch_list([ "newfirst1", "newfirst2", "firstpatch", "secondpatch", "thirdpatch", "patchwith.patch", "patchwith.diff", "patchwith", "lastpatch" ]), db.patches()) self.assertEqual(newfirst1, db.first_patch()) self.assertEqual(lastpatch, db.top_patch())