# HG changeset patch # User Peter Arrenbrecht # Date 1283932626 -7200 # Node ID 35a1e93b6f782bcb110c113b7998d528a04b6c8c # Parent 073132fc27f171f8c5b780583aaead951671e84f tests: move _add_svn_rev to test_util for reuse diff --git a/tests/test_pull.py b/tests/test_pull.py --- a/tests/test_pull.py +++ b/tests/test_pull.py @@ -9,35 +9,12 @@ from mercurial import commands class TestPull(test_util.TestBase): def setUp(self): super(TestPull, self).setUp() - self.svn_wc = None def _load_fixture_and_fetch(self, fixture_name): return test_util.load_fixture_and_fetch(fixture_name, self.repo_path, self.wc_path, stupid=False, noupdate=False) - def _add_svn_rev(self, changes): - # changes is a dict of filename -> contents - if self.svn_wc is None: - self.svn_wc = os.path.join(self.tmpdir, 'testsvn_wc') - subprocess.call([ - 'svn', 'co', '-q', test_util.fileurl(self.repo_path), - self.svn_wc - ], - stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - - for filename, contents in changes.iteritems(): - # filenames are / separated - filename = filename.replace('/', os.path.sep) - filename = os.path.join(self.svn_wc, filename) - open(filename, 'w').write(contents) - # may be redundant - subprocess.call(['svn', 'add', '-q', filename], - stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - subprocess.call([ - 'svn', 'commit', '-q', self.svn_wc, '-m', 'test changes'], - stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - def test_nochanges(self): self._load_fixture_and_fetch('single_rev.svndump') state = self.repo.parents() diff --git a/tests/test_util.py b/tests/test_util.py --- a/tests/test_util.py +++ b/tests/test_util.py @@ -184,6 +184,7 @@ class TestBase(unittest.TestCase): self.repo_path = '%s/testrepo' % self.tmpdir self.wc_path = '%s/testrepo_wc' % self.tmpdir + self.svn_wc = None # Previously, we had a MockUI class that wrapped ui, and giving access # to the stream. The ui.pushbuffer() and ui.popbuffer() can be used @@ -232,6 +233,28 @@ class TestBase(unittest.TestCase): stupid=stupid, layout=layout, startrev=startrev) + def _add_svn_rev(self, changes): + '''changes is a dict of filename -> contents''' + if self.svn_wc is None: + self.svn_wc = os.path.join(self.tmpdir, 'testsvn_wc') + subprocess.call([ + 'svn', 'co', '-q', fileurl(self.repo_path), + self.svn_wc + ], + stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + + for filename, contents in changes.iteritems(): + # filenames are / separated + filename = filename.replace('/', os.path.sep) + filename = os.path.join(self.svn_wc, filename) + open(filename, 'w').write(contents) + # may be redundant + subprocess.call(['svn', 'add', '-q', filename], + stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + subprocess.call([ + 'svn', 'commit', '-q', self.svn_wc, '-m', 'test changes'], + stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + # define this as a property so that it reloads anytime we need it @property def repo(self):