예제 #1
0
 def setUp(self):
     self.p = PatchBuffer(name="patch.txt",
                          filters=[],
                          tpl="data in this file: %(data)s",
                          ctx={'x':'y'},
                          version_filename=True)
예제 #2
0
 def setUp(self):
     self.p = PatchBuffer(name="patch.txt",
                          filters=[],
                          tpl="data in this file: %(data)s",
                          ctx={'x': 'y'},
                          version_filename=True)
예제 #3
0
class TestPatchBuffer(unittest.TestCase):

    def setUp(self):
        self.p = PatchBuffer(name="patch.txt",
                             filters=[],
                             tpl="data in this file: %(data)s",
                             ctx={'x':'y'},
                             version_filename=True)

    def tearDown(self):
        if (os.path.isfile(self.p.name)):
            os.unlink(self.p.name)

    def test_loaded(self):
        self.assertEqual("patch.txt", self.p.name)
        self.assertEqual([], self.p.filters)
        self.assertEqual("data in this file: %(data)s", self.p.tpl)
        self.assertEqual({'x':'y'}, self.p.ctx)
        self.assertEqual(True, self.p.version_filename)
        self.assertEqual(False, self.p.modified)

    def test_write(self):
        self.assertEqual(False, self.p.modified)
        self.p.write("hello world")
        self.assertEqual(True, self.p.modified)

    def test_save(self):
        self.assertEqual(False, os.path.isfile(self.p.name))
        self.p.write("hello, world")
        self.p.save()
        self.assertEqual(True, os.path.isfile(self.p.name))
        f= open(self.p.name, 'r')
        self.assertEqual("data in this file: hello, world", f.readline())

    def test_save_versioned(self):
        self.p.version_filename = True
        self.assertEqual(False, os.path.isfile(self.p.name))
        self.p.write("hello, world")

        self.p.save()
        self.assertEqual(self.p.name, "patch.txt")
        self.assertEqual(True, os.path.isfile(self.p.name))
        f= open(self.p.name, 'r')
        self.assertEqual("data in this file: hello, world", f.readline())

        self.p.save()
        self.assertEqual(self.p.name, "patch_1.txt")
        self.assertEqual(True, os.path.isfile(self.p.name))
        f= open(self.p.name, 'r')
        self.assertEqual("data in this file: hello, world", f.readline())

        os.unlink("patch.txt")
        self.assertEqual(False, os.path.isfile("patch.txt"))

        os.unlink("patch_1.txt")
        self.assertEqual(False, os.path.isfile("patch_1.txt"))

    def test_delete(self):
        self.assertEqual(False, os.path.isfile(self.p.name))
        self.p.write("hello, world")
        self.p.save()
        self.assertEqual(self.p.name, "patch.txt")
        self.assertEqual(True, os.path.isfile(self.p.name))
        self.p.delete()
        self.assertEqual(False, os.path.isfile(self.p.name))
예제 #4
0
class TestPatchBuffer(unittest.TestCase):
    def setUp(self):
        self.p = PatchBuffer(name="patch.txt",
                             filters=[],
                             tpl="data in this file: %(data)s",
                             ctx={'x': 'y'},
                             version_filename=True)

    def tearDown(self):
        if (os.path.isfile(self.p.name)):
            os.unlink(self.p.name)

    def test_loaded(self):
        self.assertEqual("patch.txt", self.p.name)
        self.assertEqual([], self.p.filters)
        self.assertEqual("data in this file: %(data)s", self.p.tpl)
        self.assertEqual({'x': 'y'}, self.p.ctx)
        self.assertEqual(True, self.p.version_filename)
        self.assertEqual(False, self.p.modified)

    def test_write(self):
        self.assertEqual(False, self.p.modified)
        self.p.write("hello world")
        self.assertEqual(True, self.p.modified)

    def test_save(self):
        self.assertEqual(False, os.path.isfile(self.p.name))
        self.p.write("hello, world")
        self.p.save()
        self.assertEqual(True, os.path.isfile(self.p.name))
        f = open(self.p.name, 'r')
        self.assertEqual("data in this file: hello, world", f.readline())

    def test_save_versioned(self):
        self.p.version_filename = True
        self.assertEqual(False, os.path.isfile(self.p.name))
        self.p.write("hello, world")

        self.p.save()
        self.assertEqual(self.p.name, "patch.txt")
        self.assertEqual(True, os.path.isfile(self.p.name))
        f = open(self.p.name, 'r')
        self.assertEqual("data in this file: hello, world", f.readline())

        self.p.save()
        self.assertEqual(self.p.name, "patch_1.txt")
        self.assertEqual(True, os.path.isfile(self.p.name))
        f = open(self.p.name, 'r')
        self.assertEqual("data in this file: hello, world", f.readline())

        os.unlink("patch.txt")
        self.assertEqual(False, os.path.isfile("patch.txt"))

        os.unlink("patch_1.txt")
        self.assertEqual(False, os.path.isfile("patch_1.txt"))

    def test_delete(self):
        self.assertEqual(False, os.path.isfile(self.p.name))
        self.p.write("hello, world")
        self.p.save()
        self.assertEqual(self.p.name, "patch.txt")
        self.assertEqual(True, os.path.isfile(self.p.name))
        self.p.delete()
        self.assertEqual(False, os.path.isfile(self.p.name))