diff svnwrap/tests/test_svnwrap.py @ 26:bfbce70a9a57

Reworked the svnwrap tests to use the same fixture system as I created for the hgsubversion tests since it is much much faster.
author Augie Fackler <durin42@gmail.com>
date Thu, 09 Oct 2008 23:37:22 -0500
parents 79b0e059319d
children 9ad5cf45e30c
line wrap: on
line diff
--- a/svnwrap/tests/test_svnwrap.py
+++ b/svnwrap/tests/test_svnwrap.py
@@ -1,4 +1,5 @@
 import os
+import popen2
 import shutil
 import tempfile
 import unittest
@@ -9,57 +10,20 @@ import svnwrap
 
 class TestBasicRepoLayout(unittest.TestCase):
     def setUp(self):
-        self.oldwd = os.getcwd()
         self.tmpdir = tempfile.mkdtemp('svnwrap_test')
         self.repo_path = '%s/testrepo' % self.tmpdir
-        wc_path = '%s/testrepo_wc' % self.tmpdir
-        os.spawnvp(os.P_WAIT, 'svnadmin', ['svnadmin', 'create',
+        os.spawnvp(os.P_WAIT, 'svnadmin', ['svnadmin', 'create', 
                                            self.repo_path,])
-        os.spawnvp(os.P_WAIT, 'svn', ['svn', 'checkout',
-                                      'file://%s' % self.repo_path,
-                                      wc_path,])
-        os.chdir(wc_path)
-        for d in ['branches', 'tags', 'trunk']:
-            os.mkdir(os.path.join(wc_path, d))
-        #r1
-        os.spawnvp(os.P_WAIT, 'svn', ['svn', 'add', 'branches', 'tags', 'trunk'])
-        os.spawnvp(os.P_WAIT, 'svn', ['svn', 'ci', '-m', 'Empty dirs.'])
-        #r2
-        files = ['alpha', 'beta', 'delta']
-        for f in files:
-            open(os.path.join(wc_path, 'trunk', f), 'w').write('This is %s.\n' % f)
-        os.chdir('trunk')
-        os.spawnvp(os.P_WAIT, 'svn', ['svn', 'add']+files)
-        os.spawnvp(os.P_WAIT, 'svn', ['svn', 'ci', '-m', 'Initial Files.'])
-        os.chdir('..')
-        #r3
-        os.spawnvp(os.P_WAIT, 'svn', ['svn', 'cp', 'trunk', 'tags/rev1'])
-        os.spawnvp(os.P_WAIT, 'svn', ['svn', 'ci', '-m', 'Tag rev 1.'])
-        #r4
-        os.spawnvp(os.P_WAIT, 'svn', ['svn', 'cp', 'trunk', 'branches/crazy'])
-        os.spawnvp(os.P_WAIT, 'svn', ['svn', 'ci', '-m', 'Branch to crazy.'])
-
-        #r5
-        open(os.path.join(wc_path, 'trunk', 'gamma'), 'w').write('This is %s.\n'
-                                                                 % 'gamma')
-        os.spawnvp(os.P_WAIT, 'svn', ['svn', 'add', 'trunk/gamma', ])
-        os.spawnvp(os.P_WAIT, 'svn', ['svn', 'ci', '-m', 'Add gamma'])
-
-        #r6
-        open(os.path.join(wc_path, 'branches', 'crazy', 'omega'),
-             'w').write('This is %s.\n' % 'omega')
-        os.spawnvp(os.P_WAIT, 'svn', ['svn', 'add', 'branches/crazy/omega', ])
-        os.spawnvp(os.P_WAIT, 'svn', ['svn', 'ci', '-m', 'Add omega'])
-
-        #r7
-        os.spawnvp(os.P_WAIT, 'svn', ['svn', 'cp', 'trunk', 'branches/more_crazy'])
-        os.spawnvp(os.P_WAIT, 'svn', ['svn', 'ci', '-m', 'Branch to more_crazy.'])
-
+        proc = popen2.Popen4(['svnadmin', 'load', self.repo_path,])
+        inp = open(os.path.join(os.path.dirname(__file__), 'fixtures', 
+                                'project_root_at_repo_root.svndump'))
+        proc.tochild.write(inp.read())
+        proc.tochild.close()
+        proc.wait()
         self.repo = svnwrap.SubversionRepo('file://%s' % self.repo_path)
 
     def tearDown(self):
         shutil.rmtree(self.tmpdir)
-        os.chdir(self.oldwd)
 
 
     def test_num_revs(self):
@@ -91,56 +55,15 @@ class TestBasicRepoLayout(unittest.TestC
 
 class TestRootAsSubdirOfRepo(TestBasicRepoLayout):
     def setUp(self):
-        self.oldwd = os.getcwd()
         self.tmpdir = tempfile.mkdtemp('svnwrap_test')
         self.repo_path = '%s/testrepo' % self.tmpdir
-        wc_path = '%s/testrepo_wc' % self.tmpdir
-        os.spawnvp(os.P_WAIT, 'svnadmin', ['svnadmin', 'create',
+        os.spawnvp(os.P_WAIT, 'svnadmin', ['svnadmin', 'create', 
                                            self.repo_path,])
-        os.spawnvp(os.P_WAIT, 'svn', ['svn', 'checkout',
-                                      'file://%s' % self.repo_path,
-                                      wc_path,])
-        self.repo_path += '/dummyproj'
-        os.chdir(wc_path)
-        os.mkdir('dummyproj')
-        os.chdir('dummyproj')
-        wc_path += '/dummyproj'
-        for d in ['branches', 'tags', 'trunk']:
-            os.mkdir(os.path.join(wc_path, d))
-        #r1
-        os.chdir('..')
-        os.spawnvp(os.P_WAIT, 'svn', ['svn', 'add', 'dummyproj'])
-        os.spawnvp(os.P_WAIT, 'svn', ['svn', 'ci', '-m', 'Empty dirs.'])
-        os.chdir('dummyproj')
-        #r2
-        files = ['alpha', 'beta', 'delta']
-        for f in files:
-            open(os.path.join(wc_path, 'trunk', f), 'w').write('This is %s.\n' % f)
-        os.chdir('trunk')
-        os.spawnvp(os.P_WAIT, 'svn', ['svn', 'add']+files)
-        os.spawnvp(os.P_WAIT, 'svn', ['svn', 'ci', '-m', 'Initial Files.'])
-        os.chdir('..')
-        #r3
-        os.spawnvp(os.P_WAIT, 'svn', ['svn', 'cp', 'trunk', 'tags/rev1'])
-        os.spawnvp(os.P_WAIT, 'svn', ['svn', 'ci', '-m', 'Tag rev 1.'])
-        #r4
-        os.spawnvp(os.P_WAIT, 'svn', ['svn', 'cp', 'trunk', 'branches/crazy'])
-        os.spawnvp(os.P_WAIT, 'svn', ['svn', 'ci', '-m', 'Branch to crazy.'])
-
-        #r5
-        open(os.path.join(wc_path, 'trunk', 'gamma'), 'w').write('This is %s.\n'
-                                                                 % 'gamma')
-        os.spawnvp(os.P_WAIT, 'svn', ['svn', 'add', 'trunk/gamma', ])
-        os.spawnvp(os.P_WAIT, 'svn', ['svn', 'ci', '-m', 'Add gamma'])
-
-        #r6
-        open(os.path.join(wc_path, 'branches', 'crazy', 'omega'),
-             'w').write('This is %s.\n' % 'omega')
-        os.spawnvp(os.P_WAIT, 'svn', ['svn', 'add', 'branches/crazy/omega', ])
-        os.spawnvp(os.P_WAIT, 'svn', ['svn', 'ci', '-m', 'Add omega'])
-
-        #r7
-        os.spawnvp(os.P_WAIT, 'svn', ['svn', 'cp', 'trunk', 'branches/more_crazy'])
-        os.spawnvp(os.P_WAIT, 'svn', ['svn', 'ci', '-m', 'Branch to more_crazy.'])
-
-        self.repo = svnwrap.SubversionRepo('file://%s' % (self.repo_path))
+        proc = popen2.Popen4(['svnadmin', 'load', self.repo_path,])
+        inp = open(os.path.join(os.path.dirname(__file__), 'fixtures', 
+                                'project_root_not_repo_root.svndump'))
+        proc.tochild.write(inp.read())
+        proc.tochild.close()
+        proc.wait()
+        self.repo = svnwrap.SubversionRepo('file://%s/dummyproj' % 
+                                           self.repo_path)