diff tests/test_util.py @ 689:35a1e93b6f78

tests: move _add_svn_rev to test_util for reuse
author Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
date Wed, 08 Sep 2010 09:57:06 +0200
parents c3900ad3bf69
children c11bf0dd38d3
line wrap: on
line diff
--- 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):