예제 #1
0
    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())
예제 #2
0
    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.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.assertEquals(patch_list(["patchwith.patch", "patchwith.diff",
                           "patchwith", "lastpatch"]),
                          db.patches_after(thirdpatch))
        self.assertEquals([], db.patches_after(lastpatch))
        self.assertEquals(None, db.patch_after(lastpatch))
        self.assertEquals(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())
예제 #3
0
    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.assertEquals(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.assertEquals(patchline.get_comment(), " my comment")
예제 #4
0
    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())
예제 #5
0
    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")
예제 #6
0
    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())