# HG changeset patch # User Augie Fackler # Date 1223514568 18000 # Node ID 95d0109e495e1d3baf40752d565f2a01ce804506 # Parent 8626f3d2e50be930e6750cdfae6fa8517677c0a1 Refactor tests so I can reuse code more. diff --git a/tests/test_fetch_command.py b/tests/test_fetch_command.py --- a/tests/test_fetch_command.py +++ b/tests/test_fetch_command.py @@ -21,23 +21,19 @@ class TestBasicRepoLayout(unittest.TestC def tearDown(self): shutil.rmtree(self.tmpdir) os.chdir(self.oldwd) + + def _load_fixture_and_fetch(self, fixture_name): + return test_util.load_fixture_and_fetch(fixture_name, self.repo_path, + self.wc_path) def test_fresh_fetch_single_rev(self): - test_util.load_svndump_fixture(self.repo_path, 'single_rev.svndump') - fetch_command.fetch_revisions(ui.ui(), - svn_url='file://%s' % self.repo_path, - hg_repo_path=self.wc_path) - repo = hg.repository(ui.ui(), self.wc_path) + repo = self._load_fixture_and_fetch('single_rev.svndump') self.assertEqual(node.hex(repo['tip'].node()), 'a47d0ce778660a91c31bf2c21c448e9ee296ac90') self.assertEqual(repo['tip'], repo[0]) def test_fresh_fetch_two_revs(self): - test_util.load_svndump_fixture(self.repo_path, 'two_revs.svndump') - fetch_command.fetch_revisions(ui.ui(), - svn_url='file://%s' % self.repo_path, - hg_repo_path=self.wc_path) - repo = hg.repository(ui.ui(), self.wc_path) + repo = self._load_fixture_and_fetch('two_revs.svndump') # TODO there must be a better way than repo[0] for this check self.assertEqual(node.hex(repo[0].node()), 'a47d0ce778660a91c31bf2c21c448e9ee296ac90') @@ -46,11 +42,7 @@ class TestBasicRepoLayout(unittest.TestC self.assertEqual(repo['tip'], repo[1]) def test_branches(self): - test_util.load_svndump_fixture(self.repo_path, 'simple_branch.svndump') - fetch_command.fetch_revisions(ui.ui(), - svn_url='file://%s' % self.repo_path, - hg_repo_path=self.wc_path) - repo = hg.repository(ui.ui(), self.wc_path) + repo = self._load_fixture_and_fetch('simple_branch.svndump') # TODO there must be a better way than repo[0] for this check self.assertEqual(node.hex(repo[0].node()), 'a47d0ce778660a91c31bf2c21c448e9ee296ac90') @@ -61,11 +53,7 @@ class TestBasicRepoLayout(unittest.TestC self.assertEqual(len(repo.heads()), 1) def test_two_branches_with_heads(self): - test_util.load_svndump_fixture(self.repo_path, 'two_heads.svndump') - fetch_command.fetch_revisions(ui.ui(), - svn_url='file://%s' % self.repo_path, - hg_repo_path=self.wc_path) - repo = hg.repository(ui.ui(), self.wc_path) + repo = self._load_fixture_and_fetch('two_heads.svndump') # TODO there must be a better way than repo[0] for this check self.assertEqual(node.hex(repo[0].node()), 'a47d0ce778660a91c31bf2c21c448e9ee296ac90') @@ -80,24 +68,13 @@ class TestBasicRepoLayout(unittest.TestC self.assertEqual(len(repo.heads()), 2) def test_many_special_cases_replay(self): - test_util.load_svndump_fixture(self.repo_path, - 'many_special_cases.svndump') - fetch_command.fetch_revisions(ui.ui(), - svn_url='file://%s' % self.repo_path, - hg_repo_path=self.wc_path) - repo = hg.repository(ui.ui(), self.wc_path) + repo = self._load_fixture_and_fetch('many_special_cases.svndump') # TODO there must be a better way than repo[0] for this check self._many_special_cases_checks(repo) def test_many_special_cases_diff(self): - test_util.load_svndump_fixture(self.repo_path, - 'many_special_cases.svndump') - fetch_command.fetch_revisions(ui.ui(), - svn_url='file://%s' % self.repo_path, - hg_repo_path=self.wc_path, - stupid = True) - repo = hg.repository(ui.ui(), self.wc_path) + repo = self._load_fixture_and_fetch('many_special_cases.svndump') # TODO there must be a better way than repo[0] for this check self._many_special_cases_checks(repo) @@ -115,8 +92,6 @@ class TestBasicRepoLayout(unittest.TestC self.assertEqual(len(repo.heads()), 2) - - class TestStupidPull(unittest.TestCase): def setUp(self): self.oldwd = os.getcwd() diff --git a/tests/test_util.py b/tests/test_util.py --- a/tests/test_util.py +++ b/tests/test_util.py @@ -1,6 +1,11 @@ import os import popen2 +from mercurial import ui +from mercurial import hg + +import fetch_command + FIXTURES = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'fixtures') @@ -14,3 +19,11 @@ def load_svndump_fixture(path, fixture_n proc.tochild.write(inp.read()) proc.tochild.close() proc.wait() + +def load_fixture_and_fetch(fixture_name, repo_path, wc_path): + load_svndump_fixture(repo_path, fixture_name) + fetch_command.fetch_revisions(ui.ui(), + svn_url='file://%s' % repo_path, + hg_repo_path=wc_path) + repo = hg.repository(ui.ui(), wc_path) + return repo