# HG changeset patch # User Patrick Mezard # Date 1226701104 21600 # Node ID 71de43e9f6140818ffa2337ef63df82adda51faf # Parent 85dcea81f22b5791b1bce191f8f81145ae459e7c Extract PushTest common code into test_util.TestBase diff --git a/tests/test_push_command.py b/tests/test_push_command.py --- a/tests/test_push_command.py +++ b/tests/test_push_command.py @@ -17,12 +17,9 @@ import test_util import time -class PushOverSvnserveTests(unittest.TestCase): +class PushOverSvnserveTests(test_util.TestBase): def setUp(self): - self.oldwd = os.getcwd() - self.tmpdir = tempfile.mkdtemp('svnwrap_test') - self.repo_path = '%s/testrepo' % self.tmpdir - self.wc_path = '%s/testrepo_wc' % self.tmpdir + test_util.TestBase.setUp(self) test_util.load_svndump_fixture(self.repo_path, 'simple_branch.svndump') open(os.path.join(self.repo_path, 'conf', 'svnserve.conf'), 'w').write('[general]\nanon-access=write\n[sasl]\n') @@ -48,14 +45,8 @@ class PushOverSvnserveTests(unittest.Tes hg_repo_path=self.wc_path) def tearDown(self): - test_util.rmtree(self.tmpdir) - os.chdir(self.oldwd) os.system('kill -9 %d' % self.svnserve_pid) - - # define this as a property so that it reloads anytime we need it - @property - def repo(self): - return hg.repository(ui.ui(), self.wc_path) + test_util.TestBase.tearDown(self) def test_push_to_default(self, commit=True): repo = self.repo @@ -91,30 +82,13 @@ class PushOverSvnserveTests(unittest.Tes self.assertEqual(tip.branch(), 'default') -class PushTests(unittest.TestCase): +class PushTests(test_util.TestBase): def setUp(self): - self.oldwd = os.getcwd() - self.tmpdir = tempfile.mkdtemp('svnwrap_test') - self.repo_path = '%s/testrepo' % self.tmpdir - self.wc_path = '%s/testrepo_wc' % self.tmpdir + test_util.TestBase.setUp(self) test_util.load_fixture_and_fetch('simple_branch.svndump', self.repo_path, self.wc_path) - # define this as a property so that it reloads anytime we need it - @property - def repo(self): - return hg.repository(ui.ui(), self.wc_path) - - def pushrevisions(self): - push_cmd.push_revisions_to_subversion( - ui.ui(), repo=self.repo, hg_repo_path=self.wc_path, - svn_url=test_util.fileurl(self.repo_path)) - - def tearDown(self): - test_util.rmtree(self.tmpdir) - os.chdir(self.oldwd) - def test_push_to_default(self, commit=True): repo = self.repo old_tip = repo['tip'].node() diff --git a/tests/test_push_renames.py b/tests/test_push_renames.py --- a/tests/test_push_renames.py +++ b/tests/test_push_renames.py @@ -14,26 +14,14 @@ import fetch_command import push_cmd import test_util -class TestPushRenames(unittest.TestCase): +class TestPushRenames(test_util.TestBase): def setUp(self): - self.oldwd = os.getcwd() - self.tmpdir = tempfile.mkdtemp('svnwrap_test') - self.repo_path = '%s/testrepo' % self.tmpdir - self.wc_path = '%s/testrepo_wc' % self.tmpdir + test_util.TestBase.setUp(self) test_util.load_fixture_and_fetch('pushrenames.svndump', self.repo_path, self.wc_path, True) - # define this as a property so that it reloads anytime we need it - @property - def repo(self): - return hg.repository(ui.ui(), self.wc_path) - - def tearDown(self): - test_util.rmtree(self.tmpdir) - os.chdir(self.oldwd) - def _commitchanges(self, repo, changes): parentctx = repo['tip'] diff --git a/tests/test_util.py b/tests/test_util.py --- a/tests/test_util.py +++ b/tests/test_util.py @@ -3,12 +3,15 @@ import os import subprocess import shutil import stat +import tempfile +import unittest import urllib from mercurial import ui from mercurial import hg import fetch_command +import push_cmd FIXTURES = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'fixtures') @@ -57,3 +60,24 @@ def rmtree(path): if (s.st_mode & stat.S_IWRITE) == 0: os.chmod(f, s.st_mode | stat.S_IWRITE) shutil.rmtree(path) + +class TestBase(unittest.TestCase): + def setUp(self): + self.oldwd = os.getcwd() + self.tmpdir = tempfile.mkdtemp('svnwrap_test') + self.repo_path = '%s/testrepo' % self.tmpdir + self.wc_path = '%s/testrepo_wc' % self.tmpdir + + def tearDown(self): + rmtree(self.tmpdir) + os.chdir(self.oldwd) + + # define this as a property so that it reloads anytime we need it + @property + def repo(self): + return hg.repository(ui.ui(), self.wc_path) + + def pushrevisions(self): + push_cmd.push_revisions_to_subversion( + ui.ui(), repo=self.repo, hg_repo_path=self.wc_path, + svn_url=fileurl(self.repo_path))