Refactor some of dulwich.tests.compat.server_utils.
authorDave Borowitz <dborowitz@google.com>
Sun, 8 Aug 2010 19:34:23 +0000 (21:34 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Sun, 8 Aug 2010 19:34:23 +0000 (21:34 +0200)
NEWS
dulwich/tests/compat/server_utils.py

diff --git a/NEWS b/NEWS
index f44d155e10dcc703a9f6c9b07ff8294df1389273..1fba2e6066214474da21b105d20cf20b42f65652 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -37,6 +37,8 @@
 
   * Add trivial test for write_pack_header. (Jelmer Vernooij)
 
+  * Refactor some of dulwich.tests.compat.server_utils. (Dave Borowitz)
+
  API CHANGES
 
   * ObjectStore.iter_tree_contents now walks contents in depth-first, sorted
index 2230d2c9d34c7584e7431f9cc482d1bb6b62a66c..0c5dce398e3eaea44c698ebe759bece1d139915d 100644 (file)
@@ -43,36 +43,46 @@ class ServerTests(object):
     """
 
     def setUp(self):
-        self._old_repo = import_repo('server_old.export')
-        self._new_repo = import_repo('server_new.export')
+        self._old_repo = None
+        self._new_repo = None
         self._server = None
 
     def tearDown(self):
         if self._server is not None:
             self._server.shutdown()
             self._server = None
-        tear_down_repo(self._old_repo)
-        tear_down_repo(self._new_repo)
+        if self._old_repo is not None:
+            tear_down_repo(self._old_repo)
+        if self._new_repo is not None:
+            tear_down_repo(self._new_repo)
+
+    def import_repos(self):
+        self._old_repo = import_repo('server_old.export')
+        self._new_repo = import_repo('server_new.export')
+
+    def url(self, port):
+        return '%s://localhost:%s/' % (self.protocol, port)
+
+    def branch_args(self, branches=None):
+        if branches is None:
+            branches = ['master', 'branch']
+        return ['%s:%s' % (b, b) for b in branches]
 
     def test_push_to_dulwich(self):
+        self.import_repos()
         self.assertReposNotEqual(self._old_repo, self._new_repo)
         port = self._start_server(self._old_repo)
 
-        all_branches = ['master', 'branch']
-        branch_args = ['%s:%s' % (b, b) for b in all_branches]
-        url = '%s://localhost:%s/' % (self.protocol, port)
-        run_git_or_fail(['push', url] + branch_args,
+        run_git_or_fail(['push', self.url(port)] + self.branch_args(),
                         cwd=self._new_repo.path)
         self.assertReposEqual(self._old_repo, self._new_repo)
 
     def test_fetch_from_dulwich(self):
+        self.import_repos()
         self.assertReposNotEqual(self._old_repo, self._new_repo)
         port = self._start_server(self._new_repo)
 
-        all_branches = ['master', 'branch']
-        branch_args = ['%s:%s' % (b, b) for b in all_branches]
-        url = '%s://localhost:%s/' % (self.protocol, port)
-        run_git_or_fail(['fetch', url] + branch_args,
+        run_git_or_fail(['fetch', self.url(port)] + self.branch_args(),
                         cwd=self._old_repo.path)
         # flush the pack cache so any new packs are picked up
         self._old_repo.object_store._pack_cache = None