Mercurial > hgsubversion
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 25:99f8e4b535e9 | 26:bfbce70a9a57 |
|---|---|
| 1 import os | 1 import os |
| 2 import popen2 | |
| 2 import shutil | 3 import shutil |
| 3 import tempfile | 4 import tempfile |
| 4 import unittest | 5 import unittest |
| 5 | 6 |
| 6 from nose import tools | 7 from nose import tools |
| 7 | 8 |
| 8 import svnwrap | 9 import svnwrap |
| 9 | 10 |
| 10 class TestBasicRepoLayout(unittest.TestCase): | 11 class TestBasicRepoLayout(unittest.TestCase): |
| 11 def setUp(self): | 12 def setUp(self): |
| 12 self.oldwd = os.getcwd() | |
| 13 self.tmpdir = tempfile.mkdtemp('svnwrap_test') | 13 self.tmpdir = tempfile.mkdtemp('svnwrap_test') |
| 14 self.repo_path = '%s/testrepo' % self.tmpdir | 14 self.repo_path = '%s/testrepo' % self.tmpdir |
| 15 wc_path = '%s/testrepo_wc' % self.tmpdir | 15 os.spawnvp(os.P_WAIT, 'svnadmin', ['svnadmin', 'create', |
| 16 os.spawnvp(os.P_WAIT, 'svnadmin', ['svnadmin', 'create', | |
| 17 self.repo_path,]) | 16 self.repo_path,]) |
| 18 os.spawnvp(os.P_WAIT, 'svn', ['svn', 'checkout', | 17 proc = popen2.Popen4(['svnadmin', 'load', self.repo_path,]) |
| 19 'file://%s' % self.repo_path, | 18 inp = open(os.path.join(os.path.dirname(__file__), 'fixtures', |
| 20 wc_path,]) | 19 'project_root_at_repo_root.svndump')) |
| 21 os.chdir(wc_path) | 20 proc.tochild.write(inp.read()) |
| 22 for d in ['branches', 'tags', 'trunk']: | 21 proc.tochild.close() |
| 23 os.mkdir(os.path.join(wc_path, d)) | 22 proc.wait() |
| 24 #r1 | |
| 25 os.spawnvp(os.P_WAIT, 'svn', ['svn', 'add', 'branches', 'tags', 'trunk']) | |
| 26 os.spawnvp(os.P_WAIT, 'svn', ['svn', 'ci', '-m', 'Empty dirs.']) | |
| 27 #r2 | |
| 28 files = ['alpha', 'beta', 'delta'] | |
| 29 for f in files: | |
| 30 open(os.path.join(wc_path, 'trunk', f), 'w').write('This is %s.\n' % f) | |
| 31 os.chdir('trunk') | |
| 32 os.spawnvp(os.P_WAIT, 'svn', ['svn', 'add']+files) | |
| 33 os.spawnvp(os.P_WAIT, 'svn', ['svn', 'ci', '-m', 'Initial Files.']) | |
| 34 os.chdir('..') | |
| 35 #r3 | |
| 36 os.spawnvp(os.P_WAIT, 'svn', ['svn', 'cp', 'trunk', 'tags/rev1']) | |
| 37 os.spawnvp(os.P_WAIT, 'svn', ['svn', 'ci', '-m', 'Tag rev 1.']) | |
| 38 #r4 | |
| 39 os.spawnvp(os.P_WAIT, 'svn', ['svn', 'cp', 'trunk', 'branches/crazy']) | |
| 40 os.spawnvp(os.P_WAIT, 'svn', ['svn', 'ci', '-m', 'Branch to crazy.']) | |
| 41 | |
| 42 #r5 | |
| 43 open(os.path.join(wc_path, 'trunk', 'gamma'), 'w').write('This is %s.\n' | |
| 44 % 'gamma') | |
| 45 os.spawnvp(os.P_WAIT, 'svn', ['svn', 'add', 'trunk/gamma', ]) | |
| 46 os.spawnvp(os.P_WAIT, 'svn', ['svn', 'ci', '-m', 'Add gamma']) | |
| 47 | |
| 48 #r6 | |
| 49 open(os.path.join(wc_path, 'branches', 'crazy', 'omega'), | |
| 50 'w').write('This is %s.\n' % 'omega') | |
| 51 os.spawnvp(os.P_WAIT, 'svn', ['svn', 'add', 'branches/crazy/omega', ]) | |
| 52 os.spawnvp(os.P_WAIT, 'svn', ['svn', 'ci', '-m', 'Add omega']) | |
| 53 | |
| 54 #r7 | |
| 55 os.spawnvp(os.P_WAIT, 'svn', ['svn', 'cp', 'trunk', 'branches/more_crazy']) | |
| 56 os.spawnvp(os.P_WAIT, 'svn', ['svn', 'ci', '-m', 'Branch to more_crazy.']) | |
| 57 | |
| 58 self.repo = svnwrap.SubversionRepo('file://%s' % self.repo_path) | 23 self.repo = svnwrap.SubversionRepo('file://%s' % self.repo_path) |
| 59 | 24 |
| 60 def tearDown(self): | 25 def tearDown(self): |
| 61 shutil.rmtree(self.tmpdir) | 26 shutil.rmtree(self.tmpdir) |
| 62 os.chdir(self.oldwd) | |
| 63 | 27 |
| 64 | 28 |
| 65 def test_num_revs(self): | 29 def test_num_revs(self): |
| 66 revs = list(self.repo.revisions()) | 30 revs = list(self.repo.revisions()) |
| 67 tools.eq_(len(revs), 7) | 31 tools.eq_(len(revs), 7) |
| 89 tools.eq_(tags.keys(), ['rev1']) | 53 tools.eq_(tags.keys(), ['rev1']) |
| 90 tools.eq_(tags['rev1'], ('trunk', 2)) | 54 tools.eq_(tags['rev1'], ('trunk', 2)) |
| 91 | 55 |
| 92 class TestRootAsSubdirOfRepo(TestBasicRepoLayout): | 56 class TestRootAsSubdirOfRepo(TestBasicRepoLayout): |
| 93 def setUp(self): | 57 def setUp(self): |
| 94 self.oldwd = os.getcwd() | |
| 95 self.tmpdir = tempfile.mkdtemp('svnwrap_test') | 58 self.tmpdir = tempfile.mkdtemp('svnwrap_test') |
| 96 self.repo_path = '%s/testrepo' % self.tmpdir | 59 self.repo_path = '%s/testrepo' % self.tmpdir |
| 97 wc_path = '%s/testrepo_wc' % self.tmpdir | 60 os.spawnvp(os.P_WAIT, 'svnadmin', ['svnadmin', 'create', |
| 98 os.spawnvp(os.P_WAIT, 'svnadmin', ['svnadmin', 'create', | |
| 99 self.repo_path,]) | 61 self.repo_path,]) |
| 100 os.spawnvp(os.P_WAIT, 'svn', ['svn', 'checkout', | 62 proc = popen2.Popen4(['svnadmin', 'load', self.repo_path,]) |
| 101 'file://%s' % self.repo_path, | 63 inp = open(os.path.join(os.path.dirname(__file__), 'fixtures', |
| 102 wc_path,]) | 64 'project_root_not_repo_root.svndump')) |
| 103 self.repo_path += '/dummyproj' | 65 proc.tochild.write(inp.read()) |
| 104 os.chdir(wc_path) | 66 proc.tochild.close() |
| 105 os.mkdir('dummyproj') | 67 proc.wait() |
| 106 os.chdir('dummyproj') | 68 self.repo = svnwrap.SubversionRepo('file://%s/dummyproj' % |
| 107 wc_path += '/dummyproj' | 69 self.repo_path) |
| 108 for d in ['branches', 'tags', 'trunk']: | |
| 109 os.mkdir(os.path.join(wc_path, d)) | |
| 110 #r1 | |
| 111 os.chdir('..') | |
| 112 os.spawnvp(os.P_WAIT, 'svn', ['svn', 'add', 'dummyproj']) | |
| 113 os.spawnvp(os.P_WAIT, 'svn', ['svn', 'ci', '-m', 'Empty dirs.']) | |
| 114 os.chdir('dummyproj') | |
| 115 #r2 | |
| 116 files = ['alpha', 'beta', 'delta'] | |
| 117 for f in files: | |
| 118 open(os.path.join(wc_path, 'trunk', f), 'w').write('This is %s.\n' % f) | |
| 119 os.chdir('trunk') | |
| 120 os.spawnvp(os.P_WAIT, 'svn', ['svn', 'add']+files) | |
| 121 os.spawnvp(os.P_WAIT, 'svn', ['svn', 'ci', '-m', 'Initial Files.']) | |
| 122 os.chdir('..') | |
| 123 #r3 | |
| 124 os.spawnvp(os.P_WAIT, 'svn', ['svn', 'cp', 'trunk', 'tags/rev1']) | |
| 125 os.spawnvp(os.P_WAIT, 'svn', ['svn', 'ci', '-m', 'Tag rev 1.']) | |
| 126 #r4 | |
| 127 os.spawnvp(os.P_WAIT, 'svn', ['svn', 'cp', 'trunk', 'branches/crazy']) | |
| 128 os.spawnvp(os.P_WAIT, 'svn', ['svn', 'ci', '-m', 'Branch to crazy.']) | |
| 129 | |
| 130 #r5 | |
| 131 open(os.path.join(wc_path, 'trunk', 'gamma'), 'w').write('This is %s.\n' | |
| 132 % 'gamma') | |
| 133 os.spawnvp(os.P_WAIT, 'svn', ['svn', 'add', 'trunk/gamma', ]) | |
| 134 os.spawnvp(os.P_WAIT, 'svn', ['svn', 'ci', '-m', 'Add gamma']) | |
| 135 | |
| 136 #r6 | |
| 137 open(os.path.join(wc_path, 'branches', 'crazy', 'omega'), | |
| 138 'w').write('This is %s.\n' % 'omega') | |
| 139 os.spawnvp(os.P_WAIT, 'svn', ['svn', 'add', 'branches/crazy/omega', ]) | |
| 140 os.spawnvp(os.P_WAIT, 'svn', ['svn', 'ci', '-m', 'Add omega']) | |
| 141 | |
| 142 #r7 | |
| 143 os.spawnvp(os.P_WAIT, 'svn', ['svn', 'cp', 'trunk', 'branches/more_crazy']) | |
| 144 os.spawnvp(os.P_WAIT, 'svn', ['svn', 'ci', '-m', 'Branch to more_crazy.']) | |
| 145 | |
| 146 self.repo = svnwrap.SubversionRepo('file://%s' % (self.repo_path)) |
