# HG changeset patch # User Patrick Mezard # Date 1334852970 -7200 # Node ID db3a651494f9ae1d096ceb784ba34248d77bc840 # Parent cc1c870f1758d0962f185e6a80397ff8422a2425 test_util: pass repo_path to svnls(), turn it into a function diff --git a/tests/test_externals.py b/tests/test_externals.py --- a/tests/test_externals.py +++ b/tests/test_externals.py @@ -329,8 +329,8 @@ class TestPushExternals(test_util.TestBa if subrepo is None: return - self._load_fixture_and_fetch('pushexternals.svndump', - externals='subrepos') + repo, repo_path = self.load_and_fetch('pushexternals.svndump', + externals='subrepos') # Add a new reference on an existing and non-existing directory changes = [ ('.hgsub', '.hgsub', """\ @@ -355,7 +355,7 @@ HEAD subdir2/deps/project2 # Check .hgsub and .hgsubstate were not pushed self.assertEqual(['dir', 'subdir1', 'subdir1/a', 'subdir2', - 'subdir2/a'], self.svnls('trunk')) + 'subdir2/a'], test_util.svnls(repo_path, 'trunk')) # Remove all references from one directory, add a new one # to the other (test multiline entries) diff --git a/tests/test_push_dirs.py b/tests/test_push_dirs.py --- a/tests/test_push_dirs.py +++ b/tests/test_push_dirs.py @@ -4,7 +4,7 @@ import unittest class TestPushDirectories(test_util.TestBase): def test_push_dirs(self): - self._load_fixture_and_fetch('emptyrepo.svndump') + repo_path = self.load_and_fetch('emptyrepo.svndump')[1] changes = [ # Single file in single directory @@ -18,7 +18,7 @@ class TestPushDirectories(test_util.Test ] self.commitchanges(changes) self.pushrevisions() - self.assertEqual(self.svnls('trunk'), + self.assertEqual(test_util.svnls(repo_path, 'trunk'), ['d1', 'd1/a', 'd2', 'd2/a', 'd2/b', 'd31', 'd31/d32', 'd31/d32/a', 'd31/d32/d33', 'd31/d32/d33/d34', 'd31/d32/d33/d34/a']) @@ -42,17 +42,17 @@ class TestPushDirectories(test_util.Test ] self.commitchanges(changes) self.pushrevisions() - self.assertEqual(self.svnls('trunk'), + self.assertEqual(test_util.svnls(repo_path, 'trunk'), ['d2', 'd2/b', 'd31', 'd31/d32', 'd31/d32/a', ]) def test_push_new_dir_project_root_not_repo_root(self): - self._load_fixture_and_fetch('fetch_missing_files_subdir.svndump', - subdir='foo') + repo_path = self.load_and_fetch('fetch_missing_files_subdir.svndump', + subdir='foo')[1] changes = [('magic_new/a', 'magic_new/a', 'ohai',), ] self.commitchanges(changes) self.pushrevisions() - self.assertEqual(self.svnls('foo/trunk'), ['bar', + self.assertEqual(test_util.svnls(repo_path, 'foo/trunk'), ['bar', 'bar/alpha', 'bar/beta', 'bar/delta', @@ -62,38 +62,38 @@ class TestPushDirectories(test_util.Test 'magic_new/a']) def test_push_new_file_existing_dir_root_not_repo_root(self): - self._load_fixture_and_fetch('empty_dir_in_trunk_not_repo_root.svndump', - subdir='project') + repo_path = self.load_and_fetch('empty_dir_in_trunk_not_repo_root.svndump', + subdir='project')[1] changes = [('narf/a', 'narf/a', 'ohai',), ] self.commitchanges(changes) - self.assertEqual(self.svnls('project/trunk'), ['a', + self.assertEqual(test_util.svnls(repo_path, 'project/trunk'), ['a', 'narf', ]) self.pushrevisions() - self.assertEqual(self.svnls('project/trunk'), ['a', + self.assertEqual(test_util.svnls(repo_path, 'project/trunk'), ['a', 'narf', 'narf/a']) changes = [('narf/a', None, None,), ] self.commitchanges(changes) self.pushrevisions() - self.assertEqual(self.svnls('project/trunk'), ['a']) + self.assertEqual(test_util.svnls(repo_path, 'project/trunk'), ['a']) def test_push_single_dir_change_in_subdir(self): # Tests simple pushing from default branch to a single dir repo # Changes a file in a subdir (regression). - repo = self._load_fixture_and_fetch('branch_from_tag.svndump', - stupid=False, - layout='single', - subdir='tags') + repo, repo_path = self.load_and_fetch('branch_from_tag.svndump', + stupid=False, + layout='single', + subdir='tags') changes = [('tag_r3/alpha', 'tag_r3/alpha', 'foo'), ('tag_r3/new', 'tag_r3/new', 'foo'), ('new_dir/new', 'new_dir/new', 'foo'), ] self.commitchanges(changes) self.pushrevisions() - self.assertEqual(self.svnls('tags'), + self.assertEqual(test_util.svnls(repo_path, 'tags'), ['copied_tag', 'copied_tag/alpha', 'copied_tag/beta', 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 @@ -108,9 +108,8 @@ class TestPushRenames(test_util.TestBase ] self.commitchanges(changes) self.pushrevisions() - # print '\n'.join(sorted(self.svnls('trunk'))) assert reduce(lambda x, y: x and y, - ('geek' not in f for f in self.svnls('trunk'))), ( + ('geek' not in f for f in test_util.svnls(self.repo_path, 'trunk'))), ( 'This failure means rename of an entire tree is broken.' ' There is a print on the preceding line commented out ' 'that should help you.') diff --git a/tests/test_single_dir_clone.py b/tests/test_single_dir_clone.py --- a/tests/test_single_dir_clone.py +++ b/tests/test_single_dir_clone.py @@ -80,10 +80,10 @@ class TestSingleDir(test_util.TestBase): def test_push_single_dir(self): # Tests simple pushing from default branch to a single dir repo - repo = self._load_fixture_and_fetch('branch_from_tag.svndump', - stupid=False, - layout='single', - subdir='') + repo, repo_path = self.load_and_fetch('branch_from_tag.svndump', + stupid=False, + layout='single', + subdir='') def file_callback(repo, memctx, path): if path == 'adding_file': return context.memfilectx(path=path, @@ -109,7 +109,7 @@ class TestSingleDir(test_util.TestBase): repo.commitctx(ctx) hg.update(repo, repo['tip'].node()) self.pushrevisions() - self.assertTrue('adding_file' in self.svnls('')) + self.assertTrue('adding_file' in test_util.svnls(repo_path, '')) self.assertEqual('application/octet-stream', self.svnpropget('adding_binary', 'svn:mime-type')) # Now add another commit and test mime-type being reset @@ -175,18 +175,18 @@ class TestSingleDir(test_util.TestBase): repo.commitctx(ctx) hg.update(repo, repo['tip'].node()) self.pushrevisions(expected_extra_back=1) - self.assertTrue('trunk/one' in self.svnls('')) - self.assertTrue('trunk/two' in self.svnls('')) + self.assertTrue('trunk/one' in test_util.svnls(repo_path, '')) + self.assertTrue('trunk/two' in test_util.svnls(repo_path, '')) def test_push_single_dir_branch(self): # Tests local branches pushing to a single dir repo. Creates a fork at # tip. The default branch adds a file called default, while branch foo # adds a file called foo, then tries to push the foo branch and default # branch in that order. - repo = self._load_fixture_and_fetch('branch_from_tag.svndump', - stupid=False, - layout='single', - subdir='') + repo, repo_path = self.load_and_fetch('branch_from_tag.svndump', + stupid=False, + layout='single', + subdir='') def file_callback(data): def cb(repo, memctx, path): if path == data: @@ -214,7 +214,7 @@ class TestSingleDir(test_util.TestBase): hg.update(repo, repo['foo'].node()) self.pushrevisions() repo = self.repo # repo is outdated after the rebase happens, refresh - self.assertTrue('foo' in self.svnls('')) + self.assertTrue('foo' in test_util.svnls(repo_path, '')) self.assertEqual(repo.branchtags().keys(), ['default']) # Have to cross to another branch head, so hg.update doesn't work commands.update(ui.ui(), @@ -222,7 +222,7 @@ class TestSingleDir(test_util.TestBase): self.repo.branchheads('default')[1], clean=True) self.pushrevisions() - self.assertTrue('default' in self.svnls('')) + self.assertTrue('default' in test_util.svnls(repo_path, '')) self.assertEquals(len(self.repo.branchheads('default')), 1) @test_util.requiresoption('branch') @@ -255,7 +255,7 @@ class TestSingleDir(test_util.TestBase): self.repo.commitctx(ctx) hg.update(self.repo, self.repo['tip'].node()) self.pushrevisions() - self.assertTrue('adding_file' in self.svnls('')) + self.assertTrue('adding_file' in test_util.svnls(repo_path, '')) self.assertEquals(set(['flaf']), set(self.repo[i].branch() for i in self.repo)) diff --git a/tests/test_util.py b/tests/test_util.py --- a/tests/test_util.py +++ b/tests/test_util.py @@ -207,6 +207,20 @@ def hgclone(ui, source, dest, update=Tru src, dest = hg.clone(ui, source, dest, update=update) return src, dest +def svnls(repo_path, path, rev='HEAD'): + path = repo_path + '/' + path + path = util.normalize_url(fileurl(path)) + args = ['svn', 'ls', '-r', rev, '-R', path] + p = subprocess.Popen(args, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT) + stdout, stderr = p.communicate() + if p.returncode: + raise Exception('svn ls failed on %s: %r' % (path, stderr)) + entries = [e.strip('/') for e in stdout.splitlines()] + entries.sort() + return entries + class TestBase(unittest.TestCase): def setUp(self): _verify_our_modules() @@ -339,20 +353,6 @@ class TestBase(unittest.TestCase): self.assertEqual(expected_extra_back, after - before) return res - def svnls(self, path, rev='HEAD'): - path = self.repo_path + '/' + path - path = util.normalize_url(fileurl(path)) - args = ['svn', 'ls', '-r', rev, '-R', path] - p = subprocess.Popen(args, - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT) - stdout, stderr = p.communicate() - if p.returncode: - raise Exception('svn ls failed on %s: %r' % (path, stderr)) - entries = [e.strip('/') for e in stdout.splitlines()] - entries.sort() - return entries - def svnco(self, svnpath, rev, path): path = os.path.join(self.wc_path, path) subpath = os.path.dirname(path)