示例#1
0
文件: wc.py 项目: zsiddique/ubuntu
    def setUp(self):
        dumpfile = open(os.path.join(os.path.split(__file__)[0],
                        'test.dumpfile'))

        # Just in case a preivous test instance was not properly cleaned up
        self.tearDown()
        self.repos = LocalRepository(repos_location, create=True)
        self.repos.load(dumpfile)

        self.wc = WC(wc_location)
        self.wc.checkout(repo_url)
示例#2
0
class WCTestCase(unittest.TestCase):
    """Test case for Subversion WC layer."""

    def setUp(self):
        dumpfile = open(os.path.join(os.path.split(__file__)[0],
                        'test.dumpfile'))

        # Just in case a previous test instance was not properly cleaned up
        self.remove_from_disk()

        self.repos = LocalRepository(repos_location, create=True)
        self.repos.load(dumpfile)

        self.wc = WC(wc_location)
        self.wc.checkout(repo_url)

    def tearDown(self):
        self.repos.close()
        self.wc.close()
        self.remove_from_disk()
        self.wc = None

    def remove_from_disk(self):
        """Remove anything left on disk"""
        pool = Pool()
        if os.path.exists(wc_location):
            svn_io_remove_dir(wc_location, pool)
        if os.path.exists(repos_location):
            svn_repos_delete(repos_location, pool)

    def _info_receiver(self, path, info):
        self.last_info = info

    def test_info(self):
        self.wc.info(path="trunk/README.txt",info_func=self._info_receiver)
        self.assertEqual(9, self.last_info.rev)
        self.assertEqual(svn_node_file, self.last_info.kind)
        self.assertEqual(repo_url, self.last_info.repos_root_URL)
        self.assertEqual("890f2569-e600-4cfc-842a-f574dec58d87",
            self.last_info.repos_UUID)
        self.assertEqual(9, self.last_info.last_changed_rev)
        self.assertEqual("bruce", self.last_info.last_changed_author)
        self.assertEqual(-1, self.last_info.copyfrom_rev)

    def test_copy(self):
        self.wc.copy("trunk/README.txt", "trunk/DONTREADME.txt")
        self.wc.info(path="trunk/DONTREADME.txt",
            info_func=self._info_receiver)
        self.assertEqual(svn_wc_schedule_add, self.last_info.schedule)
        self.wc.info(path="trunk/README.txt")
        self.assertEqual(svn_wc_schedule_normal, self.last_info.schedule)

    def test_move(self):
        self.wc.move("trunk/README.txt", "trunk/DONTREADMEEITHER.txt")
        self.wc.info(path="trunk/DONTREADMEEITHER.txt",
            info_func=self._info_receiver)
        self.assertEqual(svn_wc_schedule_add, self.last_info.schedule)
        self.wc.info(path="trunk/README.txt")
        self.assertEqual(svn_wc_schedule_delete, self.last_info.schedule)

    def test_delete(self):
        self.wc.delete(["trunk/README.txt"])
        self.wc.info(path="trunk/README.txt",
            info_func=self._info_receiver)
        self.assertEqual(svn_wc_schedule_delete, self.last_info.schedule)

    def test_mkdir(self):
        self.wc.mkdir(["trunk/plank"])
        self.wc.info(path="trunk/plank",
            info_func=self._info_receiver)
        self.assertEqual(svn_wc_schedule_add, self.last_info.schedule)

    def test_add(self):
        f = open("%s/trunk/ADDED.txt" % wc_location, "w")
        f.write("Something")
        f.close()

        self.wc.add("trunk/ADDED.txt")
        self.wc.info(path="trunk/ADDED.txt",
            info_func=self._info_receiver)
        self.assertEqual(svn_wc_schedule_add, self.last_info.schedule)

    def test_revert(self):
        self.wc.revert([""],True)
        self.wc.info(path="trunk/README.txt",
            info_func=self._info_receiver)
        self.assertEqual(svn_wc_schedule_normal, self.last_info.schedule)

    def test_diff(self):
        path = "%s/trunk/README.txt" % wc_location

        diffstring="""Index: """+path+"""
===================================================================
--- """+path+"""\t(revision 9)
+++ """+path+"""\t(working copy)
@@ -1,7 +0,0 @@
-This repository is for test purposes only. Any resemblance to any other
-repository, real or imagined, is purely coincidental.
-
-Contributors:
-Clark
-Bruce
-Henry
"""
        f = open(path, "w")
        f.truncate(0)
        f.close()
        difffile = StringIO()
        self.wc.diff("trunk", outfile=difffile)
        difffile.seek(0)
        diffresult = difffile.read().replace("\r","")
        self.assertEqual(diffstring, diffresult)

        path = "%s/branches/0.x/README.txt" % wc_location
        diffstring="""Index: """+path+"""
===================================================================
--- """+path+"""\t(nonexistent)
+++ """+path+"""\t(revision 5)
@@ -0,0 +1,9 @@
+This repository is for test purposes only. Any resemblance to any other
+repository, real or imagined, is purely coincidental.
+
+This branch preserves and refines the code of the excellent pre-1.0 days.
+
+Contributors:
+Clark
+Bruce
+Henry
"""
        difffile.seek(0)
        self.wc.diff(revnum1=4, revnum2=5, outfile=difffile)
        difffile.seek(0)
        diffresult = difffile.read().replace("\r","")
        self.assertEqual(diffstring, diffresult)


    def test_export(self):
        export_location = os.path.join(tempfile.gettempdir(), "svn_export")
        self.wc.export("", export_location)
        if not os.path.exists(export_location):
            self.fail("Export directory does not exist")
        else:
            shutil.rmtree(export_location)

    def test_propget(self):
        props = self.wc.propget("Awesome")
        path = "%s/trunk/README.txt" % wc_location
        if not path in props.keys():
            self.fail("File missing in propget")

    def test_propset(self):
        self.wc.propset("testprop", "testval", "branches/0.x/README.txt")
        props = self.wc.propget("testprop", "branches/0.x/README.txt")
        if not "%s/branches/0.x/README.txt" % wc_location in \
                props.keys():

            self.fail("Property not set")

    def test_update(self):
        path = "trunk/README.txt"
        results = self.wc.update([path], revnum=7)
        self.assertEqual(results[0], 7)
        props = self.wc.propget("Awesome")
        if "%s/%s" % (wc_location, path) in \
                props.keys():
            self.fail("File not updated to old revision")
        results = self.wc.update([path])
        self.assertEqual(results[0], 9)
        self.test_propget()

    def test_switch(self):
        self.wc.switch("trunk", "%s/tags" % repo_url)
        if os.path.exists("%s/trunk/README.txt" % wc_location):
            self.fail("Switch did not happen")

    def test_lock(self):
        self.wc.lock(["%s/trunk/README.txt" % wc_location],
                        "Test lock")
        self.wc.info(path="trunk/README.txt",
            info_func=self._info_receiver)
        if not self.last_info.lock:
            self.fail("Lock not acquired")

    def test_unlock(self):
        path = "%s/trunk/README.txt" % wc_location
        self.wc.lock([path], "Test lock")
        self.wc.info(path=path,
            info_func=self._info_receiver)
        if not self.last_info.lock:
            self.fail("Lock not acquired")
        self.wc.unlock([path])

        self.wc.info(path="trunk/README.txt",
            info_func=self._info_receiver)
        if self.last_info.lock:
            self.fail("Lock not released")
示例#3
0
class WCTestCase(unittest.TestCase):
    """Test case for Subversion WC layer."""

    def setUp(self):
        dumpfile = open(os.path.join(os.path.split(__file__)[0],
                        'test.dumpfile'))

        # Just in case a previous test instance was not properly cleaned up
        self.remove_from_disk()

        self.repos = LocalRepository(repos_location, create=True)
        self.repos.load(dumpfile)

        self.wc = WC(wc_location)
        self.wc.checkout(repo_url)

    def tearDown(self):
        self.repos.close()
        self.wc.close()
        self.remove_from_disk()
        self.wc = None

    def remove_from_disk(self):
        """Remove anything left on disk"""
        pool = Pool()
        if os.path.exists(wc_location):
            svn_io_remove_dir(wc_location, pool)
        if os.path.exists(repos_location):
            svn_repos_delete(repos_location, pool)

    def _info_receiver(self, path, info):
        self.last_info = info

    def test_info(self):
        self.wc.info(path="trunk/README.txt",info_func=self._info_receiver)
        self.assertEqual(9, self.last_info.rev)
        self.assertEqual(svn_node_file, self.last_info.kind)
        self.assertEqual(repo_url, self.last_info.repos_root_URL)
        self.assertEqual("890f2569-e600-4cfc-842a-f574dec58d87",
            self.last_info.repos_UUID)
        self.assertEqual(9, self.last_info.last_changed_rev)
        self.assertEqual("bruce", self.last_info.last_changed_author)
        self.assertEqual(-1, self.last_info.copyfrom_rev)

    def test_copy(self):
        self.wc.copy("trunk/README.txt", "trunk/DONTREADME.txt")
        self.wc.info(path="trunk/DONTREADME.txt",
            info_func=self._info_receiver)
        self.assertEqual(svn_wc_schedule_add, self.last_info.schedule)
        self.wc.info(path="trunk/README.txt")
        self.assertEqual(svn_wc_schedule_normal, self.last_info.schedule)

    def test_move(self):
        self.wc.move("trunk/README.txt", "trunk/DONTREADMEEITHER.txt")
        self.wc.info(path="trunk/DONTREADMEEITHER.txt",
            info_func=self._info_receiver)
        self.assertEqual(svn_wc_schedule_add, self.last_info.schedule)
        self.wc.info(path="trunk/README.txt")
        self.assertEqual(svn_wc_schedule_delete, self.last_info.schedule)

    def test_delete(self):
        self.wc.delete(["trunk/README.txt"])
        self.wc.info(path="trunk/README.txt",
            info_func=self._info_receiver)
        self.assertEqual(svn_wc_schedule_delete, self.last_info.schedule)

    def test_mkdir(self):
        self.wc.mkdir(["trunk/plank"])
        self.wc.info(path="trunk/plank",
            info_func=self._info_receiver)
        self.assertEqual(svn_wc_schedule_add, self.last_info.schedule)

    def test_add(self):
        f = open("%s/trunk/ADDED.txt" % wc_location, "w")
        f.write("Something")
        f.close()

        self.wc.add("trunk/ADDED.txt")
        self.wc.info(path="trunk/ADDED.txt",
            info_func=self._info_receiver)
        self.assertEqual(svn_wc_schedule_add, self.last_info.schedule)

    def test_revert(self):
        self.wc.revert([""],True)
        self.wc.info(path="trunk/README.txt",
            info_func=self._info_receiver)
        self.assertEqual(svn_wc_schedule_normal, self.last_info.schedule)

    def test_diff(self):
        path = "%s/trunk/README.txt" % wc_location

        diffstring="""Index: """+path+"""
===================================================================
--- """+path+"""\t(revision 9)
+++ """+path+"""\t(working copy)
@@ -1,7 +0,0 @@
-This repository is for test purposes only. Any resemblance to any other
-repository, real or imagined, is purely coincidental.
-
-Contributors:
-Clark
-Bruce
-Henry
"""
        f = open(path, "w")
        f.truncate(0)
        f.close()
        difffile = StringIO()
        self.wc.diff("trunk", outfile=difffile)
        difffile.seek(0)
        diffresult = difffile.read().replace("\r","")
        self.assertEqual(diffstring, diffresult)

        path = "%s/branches/0.x/README.txt" % wc_location
        diffstring="""Index: """+path+"""
===================================================================
--- """+path+"""\t(revision 0)
+++ """+path+"""\t(revision 5)
@@ -0,0 +1,9 @@
+This repository is for test purposes only. Any resemblance to any other
+repository, real or imagined, is purely coincidental.
+
+This branch preserves and refines the code of the excellent pre-1.0 days.
+
+Contributors:
+Clark
+Bruce
+Henry
"""
        difffile.seek(0)
        self.wc.diff(revnum1=4, revnum2=5, outfile=difffile)
        difffile.seek(0)
        diffresult = difffile.read().replace("\r","")
        self.assertEqual(diffstring, diffresult)


    def test_export(self):
        export_location = os.path.join(tempfile.gettempdir(), "svn_export")
        self.wc.export("", export_location)
        if not os.path.exists(export_location):
            self.fail("Export directory does not exist")
        else:
            shutil.rmtree(export_location)

    def test_propget(self):
        props = self.wc.propget("Awesome")
        path = "%s/trunk/README.txt" % wc_location
        if not path in props.keys():
            self.fail("File missing in propget")

    def test_propset(self):
        self.wc.propset("testprop", "testval", "branches/0.x/README.txt")
        props = self.wc.propget("testprop", "branches/0.x/README.txt")
        if not "%s/branches/0.x/README.txt" % wc_location in \
                props.keys():

            self.fail("Property not set")

    def test_update(self):
        path = "trunk/README.txt"
        results = self.wc.update([path], revnum=7)
        self.assertEqual(results[0], 7)
        props = self.wc.propget("Awesome")
        if "%s/%s" % (wc_location, path) in \
                props.keys():
            self.fail("File not updated to old revision")
        results = self.wc.update([path])
        self.assertEqual(results[0], 9)
        self.test_propget()

    def test_switch(self):
        self.wc.switch("trunk", "%s/tags" % repo_url)
        if os.path.exists("%s/trunk/README.txt" % wc_location):
            self.fail("Switch did not happen")

    def test_lock(self):
        self.wc.lock(["%s/trunk/README.txt" % wc_location],
                        "Test lock")
        self.wc.info(path="trunk/README.txt",
            info_func=self._info_receiver)
        if not self.last_info.lock:
            self.fail("Lock not acquired")

    def test_unlock(self):
        path = "%s/trunk/README.txt" % wc_location
        self.wc.lock([path], "Test lock")
        self.wc.info(path=path,
            info_func=self._info_receiver)
        if not self.last_info.lock:
            self.fail("Lock not acquired")
        self.wc.unlock([path])

        self.wc.info(path="trunk/README.txt",
            info_func=self._info_receiver)
        if self.last_info.lock:
            self.fail("Lock not released")