Mercurial > hgsubversion
changeset 866:20e73b5ab6f7
test_util: merge load_svndump_fixture() into TestBase
author | Patrick Mezard <patrick@mezard.eu> |
---|---|
date | Thu, 19 Apr 2012 18:29:28 +0200 |
parents | 04729f3a3d17 |
children | 50c13e01c7e3 |
files | tests/test_fetch_branches.py tests/test_fetch_command.py tests/test_fetch_mappings.py tests/test_fetch_truncated.py tests/test_push_command.py tests/test_single_dir_clone.py tests/test_urls.py tests/test_util.py tests/test_utility_commands.py |
diffstat | 9 files changed, 64 insertions(+), 69 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/test_fetch_branches.py +++ b/tests/test_fetch_branches.py @@ -8,8 +8,8 @@ from mercurial import util as hgutil class TestFetchBranches(test_util.TestBase): def _load_fixture_and_fetch_with_anchor(self, fixture_name, anchor): - test_util.load_svndump_fixture(self.repo_path, fixture_name) - source = '%s#%s' % (test_util.fileurl(self.repo_path), anchor) + repo_path = self.load_svndump(fixture_name) + source = '%s#%s' % (test_util.fileurl(repo_path), anchor) test_util.hgclone(self.ui(), source, self.wc_path) return hg.repository(self.ui(), self.wc_path)
--- a/tests/test_fetch_command.py +++ b/tests/test_fetch_command.py @@ -152,12 +152,11 @@ class TestBasicRepoLayout(test_util.Test self.test_fetch_when_trunk_has_no_files(stupid=True) def test_path_quoting(self, stupid=False): - test_util.load_svndump_fixture(self.repo_path, - 'non_ascii_path_1.svndump') + repo_path = self.load_svndump('non_ascii_path_1.svndump') subdir = '/b\xC3\xB8b' quoted_subdir = urllib.quote(subdir) - repo_url = test_util.fileurl(self.repo_path) + repo_url = test_util.fileurl(repo_path) wc_path = self.wc_path wc2_path = wc_path + '-2'
--- a/tests/test_fetch_mappings.py +++ b/tests/test_fetch_mappings.py @@ -32,14 +32,14 @@ class MapTests(test_util.TestBase): return os.path.join(self.tmpdir, 'tagmap') def test_author_map(self, stupid=False): - test_util.load_svndump_fixture(self.repo_path, 'replace_trunk_with_branch.svndump') + repo_path = self.load_svndump('replace_trunk_with_branch.svndump') authormap = open(self.authors, 'w') authormap.write('Augie=Augie Fackler <durin42@gmail.com> # stuffy\n') authormap.write("Augie Fackler <durin42@gmail.com>\n") authormap.close() ui = self.ui(stupid) ui.setconfig('hgsubversion', 'authormap', self.authors) - commands.clone(ui, test_util.fileurl(self.repo_path), + commands.clone(ui, test_util.fileurl(repo_path), self.wc_path, authors=self.authors) self.assertEqual(self.repo[0].user(), 'Augie Fackler <durin42@gmail.com>') @@ -50,13 +50,13 @@ class MapTests(test_util.TestBase): self.test_author_map(True) def test_author_map_closing_author(self, stupid=False): - test_util.load_svndump_fixture(self.repo_path, 'replace_trunk_with_branch.svndump') + repo_path = self.load_svndump('replace_trunk_with_branch.svndump') authormap = open(self.authors, 'w') authormap.write("evil=Testy <test@test>") authormap.close() ui = self.ui(stupid) ui.setconfig('hgsubversion', 'authormap', self.authors) - commands.clone(ui, test_util.fileurl(self.repo_path), + commands.clone(ui, test_util.fileurl(repo_path), self.wc_path, authors=self.authors) self.assertEqual(self.repo[0].user(), 'Augie@5b65bade-98f3-4993-a01f-b7a6710da339') @@ -100,13 +100,13 @@ class MapTests(test_util.TestBase): self.assertEqual(fromself.symmetric_difference(all_tests), set()) def test_file_map(self, stupid=False): - test_util.load_svndump_fixture(self.repo_path, 'replace_trunk_with_branch.svndump') + repo_path = self.load_svndump('replace_trunk_with_branch.svndump') filemap = open(self.filemap, 'w') filemap.write("include alpha\n") filemap.close() ui = self.ui(stupid) ui.setconfig('hgsubversion', 'filemap', self.filemap) - commands.clone(ui, test_util.fileurl(self.repo_path), + commands.clone(ui, test_util.fileurl(repo_path), self.wc_path, filemap=self.filemap) self.assertEqual(node.hex(self.repo[0].node()), '88e2c7492d83e4bf30fbb2dcbf6aa24d60ac688d') self.assertEqual(node.hex(self.repo['default'].node()), 'e524296152246b3837fe9503c83b727075835155') @@ -116,13 +116,13 @@ class MapTests(test_util.TestBase): self.assertRaises(hgutil.Abort, self.test_file_map, True) def test_file_map_exclude(self, stupid=False): - test_util.load_svndump_fixture(self.repo_path, 'replace_trunk_with_branch.svndump') + repo_path = self.load_svndump('replace_trunk_with_branch.svndump') filemap = open(self.filemap, 'w') filemap.write("exclude alpha\n") filemap.close() ui = self.ui(stupid) ui.setconfig('hgsubversion', 'filemap', self.filemap) - commands.clone(ui, test_util.fileurl(self.repo_path), + commands.clone(ui, test_util.fileurl(repo_path), self.wc_path, filemap=self.filemap) self.assertEqual(node.hex(self.repo[0].node()), '2c48f3525926ab6c8b8424bcf5eb34b149b61841') self.assertEqual(node.hex(self.repo['default'].node()), 'b37a3c0297b71f989064d9b545b5a478bbed7cc1') @@ -132,7 +132,7 @@ class MapTests(test_util.TestBase): self.assertRaises(hgutil.Abort, self.test_file_map_exclude, True) def test_file_map_rule_order(self): - test_util.load_svndump_fixture(self.repo_path, 'replace_trunk_with_branch.svndump') + repo_path = self.load_svndump('replace_trunk_with_branch.svndump') filemap = open(self.filemap, 'w') filemap.write("exclude alpha\n") filemap.write("include .\n") @@ -140,7 +140,7 @@ class MapTests(test_util.TestBase): filemap.close() ui = self.ui(False) ui.setconfig('hgsubversion', 'filemap', self.filemap) - commands.clone(ui, test_util.fileurl(self.repo_path), + commands.clone(ui, test_util.fileurl(repo_path), self.wc_path, filemap=self.filemap) # The exclusion of alpha is overridden by the later rule to # include all of '.', whereas gamma should remain excluded @@ -151,14 +151,14 @@ class MapTests(test_util.TestBase): ['alpha', 'beta']) def test_branchmap(self, stupid=False): - test_util.load_svndump_fixture(self.repo_path, 'branchmap.svndump') + repo_path = self.load_svndump('branchmap.svndump') branchmap = open(self.branchmap, 'w') branchmap.write("badname = good-name # stuffy\n") branchmap.write("feature = default\n") branchmap.close() ui = self.ui(stupid) ui.setconfig('hgsubversion', 'branchmap', self.branchmap) - commands.clone(ui, test_util.fileurl(self.repo_path), + commands.clone(ui, test_util.fileurl(repo_path), self.wc_path, branchmap=self.branchmap) branches = set(self.repo[i].branch() for i in self.repo) self.assert_('badname' not in branches) @@ -170,13 +170,13 @@ class MapTests(test_util.TestBase): def test_branchmap_tagging(self, stupid=False): '''test tagging a renamed branch, which used to raise an exception''' - test_util.load_svndump_fixture(self.repo_path, 'commit-to-tag.svndump') + repo_path = self.load_svndump('commit-to-tag.svndump') branchmap = open(self.branchmap, 'w') branchmap.write("magic = art\n") branchmap.close() ui = self.ui(stupid) ui.setconfig('hgsubversion', 'branchmap', self.branchmap) - commands.clone(ui, test_util.fileurl(self.repo_path), + commands.clone(ui, test_util.fileurl(repo_path), self.wc_path, branchmap=self.branchmap) branches = set(self.repo[i].branch() for i in self.repo) self.assertEquals(sorted(branches), ['art', 'closeme']) @@ -186,13 +186,13 @@ class MapTests(test_util.TestBase): def test_branchmap_empty_commit(self, stupid=False): '''test mapping an empty commit on a renamed branch''' - test_util.load_svndump_fixture(self.repo_path, 'propset-branch.svndump') + repo_path = self.load_svndump('propset-branch.svndump') branchmap = open(self.branchmap, 'w') branchmap.write("the-branch = bob\n") branchmap.close() ui = self.ui(stupid) ui.setconfig('hgsubversion', 'branchmap', self.branchmap) - commands.clone(ui, test_util.fileurl(self.repo_path), + commands.clone(ui, test_util.fileurl(repo_path), self.wc_path, branchmap=self.branchmap) branches = set(self.repo[i].branch() for i in self.repo) self.assertEquals(sorted(branches), ['bob', 'default']) @@ -203,14 +203,14 @@ class MapTests(test_util.TestBase): def test_branchmap_combine(self, stupid=False): '''test combining two branches, but retaining heads''' - test_util.load_svndump_fixture(self.repo_path, 'branchmap.svndump') + repo_path = self.load_svndump('branchmap.svndump') branchmap = open(self.branchmap, 'w') branchmap.write("badname = default\n") branchmap.write("feature = default\n") branchmap.close() ui = self.ui(stupid) ui.setconfig('hgsubversion', 'branchmap', self.branchmap) - commands.clone(ui, test_util.fileurl(self.repo_path), + commands.clone(ui, test_util.fileurl(repo_path), self.wc_path, branchmap=self.branchmap) branches = set(self.repo[i].branch() for i in self.repo) self.assertEquals(sorted(branches), ['default']) @@ -228,14 +228,14 @@ class MapTests(test_util.TestBase): def test_branchmap_rebuildmeta(self, stupid=False): '''test rebuildmeta on a branchmapped clone''' - test_util.load_svndump_fixture(self.repo_path, 'branchmap.svndump') + repo_path = self.load_svndump('branchmap.svndump') branchmap = open(self.branchmap, 'w') branchmap.write("badname = dit\n") branchmap.write("feature = dah\n") branchmap.close() ui = self.ui(stupid) ui.setconfig('hgsubversion', 'branchmap', self.branchmap) - commands.clone(ui, test_util.fileurl(self.repo_path), + commands.clone(ui, test_util.fileurl(repo_path), self.wc_path, branchmap=self.branchmap) originfo = self.repo.svnmeta().branches @@ -244,7 +244,7 @@ class MapTests(test_util.TestBase): src, dest = test_util.hgclone(ui, self.wc_path, self.wc_path + '_clone', update=False) svncommands.rebuildmeta(ui, dest, - args=[test_util.fileurl(self.repo_path)]) + args=[test_util.fileurl(repo_path)]) # just check the keys; assume the contents are unaffected by the branch # map and thus properly tested by other tests @@ -257,14 +257,14 @@ class MapTests(test_util.TestBase): def test_branchmap_verify(self, stupid=False): '''test verify on a branchmapped clone''' - test_util.load_svndump_fixture(self.repo_path, 'branchmap.svndump') + repo_path = self.load_svndump('branchmap.svndump') branchmap = open(self.branchmap, 'w') branchmap.write("badname = dit\n") branchmap.write("feature = dah\n") branchmap.close() ui = self.ui(stupid) ui.setconfig('hgsubversion', 'branchmap', self.branchmap) - commands.clone(ui, test_util.fileurl(self.repo_path), + commands.clone(ui, test_util.fileurl(repo_path), self.wc_path, branchmap=self.branchmap) repo = self.repo @@ -283,7 +283,7 @@ class MapTests(test_util.TestBase): is to not convert the 'this' branches. Until we can do that, we settle with aborting. ''' - test_util.load_svndump_fixture(self.repo_path, 'propset-branch.svndump') + repo_path = self.load_svndump('propset-branch.svndump') branchmap = open(self.branchmap, 'w') branchmap.write("closeme =\n") branchmap.close() @@ -291,8 +291,7 @@ class MapTests(test_util.TestBase): maps.BranchMap, self.ui(), self.branchmap) def test_tagmap(self, stupid=False): - test_util.load_svndump_fixture(self.repo_path, - 'basic_tag_tests.svndump') + repo_path = self.load_svndump('basic_tag_tests.svndump') tagmap = open(self.tagmap, 'w') tagmap.write("tag_r3 = 3.x # stuffy\n") tagmap.write("copied_tag = \n") @@ -300,7 +299,7 @@ class MapTests(test_util.TestBase): ui = self.ui(stupid) ui.setconfig('hgsubversion', 'tagmap', self.tagmap) - commands.clone(ui, test_util.fileurl(self.repo_path), + commands.clone(ui, test_util.fileurl(repo_path), self.wc_path, tagmap=self.tagmap) tags = self.repo.tags() assert 'tag_r3' not in tags @@ -311,8 +310,7 @@ class MapTests(test_util.TestBase): self.test_tagmap(True) def test_tagren_changed(self, stupid=False): - test_util.load_svndump_fixture(self.repo_path, - 'commit-to-tag.svndump') + repo_path = self.load_svndump('commit-to-tag.svndump') tagmap = open(self.tagmap, 'w') tagmap.write("edit-at-create = edit-past\n") tagmap.write("also-edit = \n") @@ -321,7 +319,7 @@ class MapTests(test_util.TestBase): ui = self.ui(stupid) ui.setconfig('hgsubversion', 'tagmap', self.tagmap) - commands.clone(ui, test_util.fileurl(self.repo_path), + commands.clone(ui, test_util.fileurl(repo_path), self.wc_path, tagmap=self.tagmap) tags = self.repo.tags()
--- a/tests/test_fetch_truncated.py +++ b/tests/test_fetch_truncated.py @@ -8,8 +8,8 @@ from mercurial import hg class TestFetchTruncatedHistory(test_util.TestBase): def test_truncated_history(self, stupid=False): # Test repository does not follow the usual layout - test_util.load_svndump_fixture(self.repo_path, 'truncatedhistory.svndump') - svn_url = test_util.fileurl(self.repo_path + '/project2') + repo_path = self.load_svndump('truncatedhistory.svndump') + svn_url = test_util.fileurl(repo_path + '/project2') commands.clone(self.ui(stupid), svn_url, self.wc_path, noupdate=True) repo = hg.repository(self.ui(stupid), self.wc_path)
--- a/tests/test_push_command.py +++ b/tests/test_push_command.py @@ -76,15 +76,15 @@ class PushTests(test_util.TestBase): self.assertEqual(new_hash, tip.node()) def internal_push_over_svnserve(self, subdir='', commit=True): - test_util.load_svndump_fixture(self.repo_path, 'simple_branch.svndump') - open(os.path.join(self.repo_path, 'conf', 'svnserve.conf'), + repo_path = self.load_svndump('simple_branch.svndump') + open(os.path.join(repo_path, 'conf', 'svnserve.conf'), 'w').write('[general]\nanon-access=write\n[sasl]\n') self.port = random.randint(socket.IPPORT_USERRESERVED, 65535) self.host = 'localhost' args = ['svnserve', '--daemon', '--foreground', '--listen-port=%d' % self.port, '--listen-host=%s' % self.host, - '--root=%s' % self.repo_path] + '--root=%s' % repo_path] svnserve = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
--- a/tests/test_single_dir_clone.py +++ b/tests/test_single_dir_clone.py @@ -229,12 +229,11 @@ class TestSingleDir(test_util.TestBase): def test_push_single_dir_renamed_branch(self, stupid=False): # Tests pulling and pushing with a renamed branch # Based on test_push_single_dir - test_util.load_svndump_fixture(self.repo_path, - 'branch_from_tag.svndump') + repo_path = self.load_svndump('branch_from_tag.svndump') cmd = ['clone', '--layout=single', '--branch=flaf'] if stupid: cmd.append('--stupid') - cmd += [test_util.fileurl(self.repo_path), self.wc_path] + cmd += [test_util.fileurl(repo_path), self.wc_path] test_util.dispatch(cmd) def file_callback(repo, memctx, path):
--- a/tests/test_urls.py +++ b/tests/test_urls.py @@ -63,10 +63,9 @@ class TestSubversionUrls(test_util.TestB def test_quoting(self): ui = self.ui() - test_util.load_svndump_fixture(self.repo_path, - 'non_ascii_path_1.svndump') + repo_path = self.load_svndump('non_ascii_path_1.svndump') - repo_url = test_util.fileurl(self.repo_path) + repo_url = test_util.fileurl(repo_path) subdir = '/b\xC3\xB8b' quoted_subdir = urllib.quote(subdir)
--- a/tests/test_util.py +++ b/tests/test_util.py @@ -158,18 +158,6 @@ def testui(stupid=False, layout='auto', u.setconfig('hgsubversion', 'startrev', startrev) return u -def load_svndump_fixture(path, fixture_name): - '''Loads an svnadmin dump into a fresh repo at path, which should not - already exist. - ''' - if os.path.exists(path): rmtree(path) - subprocess.call(['svnadmin', 'create', path, ], - stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - inp = open(os.path.join(FIXTURES, fixture_name)) - proc = subprocess.Popen(['svnadmin', 'load', path, ], stdin=inp, - stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - proc.communicate() - def dispatch(cmd): try: req = dispatchmod.request(cmd) @@ -266,6 +254,21 @@ class TestBase(unittest.TestCase): def ui(self, stupid=False, layout='auto'): return testui(stupid, layout) + def load_svndump(self, fixture_name): + '''Loads an svnadmin dump into a fresh repo. Return the svn repo + path. + ''' + path = self.repo_path + if os.path.exists(path): + rmtree(path) + subprocess.call(['svnadmin', 'create', path,], + stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + inp = open(os.path.join(FIXTURES, fixture_name)) + proc = subprocess.Popen(['svnadmin', 'load', path,], stdin=inp, + stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + proc.communicate() + return path + def _load_fixture_and_fetch(self, fixture_name, subdir=None, stupid=False, layout='auto', startrev=0, externals=None, noupdate=True): @@ -274,8 +277,8 @@ class TestBase(unittest.TestCase): subdir = 'trunk' elif subdir is None: subdir = '' - load_svndump_fixture(self.repo_path, fixture_name) - projectpath = self.repo_path + repo_path = self.load_svndump(fixture_name) + projectpath = repo_path if subdir: projectpath += '/' + subdir
--- a/tests/test_utility_commands.py +++ b/tests/test_utility_commands.py @@ -228,24 +228,21 @@ class UtilityTests(test_util.TestBase): '.hgignore\nsyntax:glob\nblah\notherblah\nbaz/magic\n') def test_list_authors(self): - test_util.load_svndump_fixture(self.repo_path, - 'replace_trunk_with_branch.svndump') + repo_path = self.load_svndump('replace_trunk_with_branch.svndump') u = self.ui() u.pushbuffer() svncommands.listauthors(u, - args=[test_util.fileurl(self.repo_path)], + args=[test_util.fileurl(repo_path)], authors=None) actual = u.popbuffer() self.assertMultiLineEqual(actual, 'Augie\nevil\n') - def test_list_authors_map(self): - test_util.load_svndump_fixture(self.repo_path, - 'replace_trunk_with_branch.svndump') - author_path = os.path.join(self.repo_path, 'authors') + repo_path = self.load_svndump('replace_trunk_with_branch.svndump') + author_path = os.path.join(repo_path, 'authors') svncommands.listauthors(self.ui(), - args=[test_util.fileurl(self.repo_path)], - authors=author_path) + args=[test_util.fileurl(repo_path)], + authors=author_path) self.assertMultiLineEqual(open(author_path).read(), 'Augie=\nevil=\n')