Mercurial > hgsubversion
comparison test_svnwrap.py @ 0:f2636cfed115
Initial import of hgsubversion into a public repository.
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Tue, 30 Sep 2008 11:42:52 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f2636cfed115 |
---|---|
1 import os | |
2 import shutil | |
3 import tempfile | |
4 import unittest | |
5 | |
6 from nose import tools | |
7 | |
8 import svnwrap | |
9 | |
10 class TestBasicRepoLayout(unittest.TestCase): | |
11 def setUp(self): | |
12 self.oldwd = os.getcwd() | |
13 self.tmpdir = tempfile.mkdtemp('svnwrap_test') | |
14 self.repo_path = '%s/testrepo' % self.tmpdir | |
15 wc_path = '%s/testrepo_wc' % self.tmpdir | |
16 os.spawnvp(os.P_WAIT, 'svnadmin', ['svnadmin', 'create', | |
17 self.repo_path,]) | |
18 os.spawnvp(os.P_WAIT, 'svn', ['svn', 'checkout', | |
19 'file://%s' % self.repo_path, | |
20 wc_path,]) | |
21 os.chdir(wc_path) | |
22 for d in ['branches', 'tags', 'trunk']: | |
23 os.mkdir(os.path.join(wc_path, d)) | |
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) | |
59 | |
60 def tearDown(self): | |
61 shutil.rmtree(self.tmpdir) | |
62 os.chdir(self.oldwd) | |
63 | |
64 | |
65 def test_num_revs(self): | |
66 revs = list(self.repo.revisions()) | |
67 tools.eq_(len(revs), 7) | |
68 r = revs[1] | |
69 tools.eq_(r.revnum, 2) | |
70 tools.eq_(sorted(r.paths.keys()), | |
71 ['trunk/alpha', 'trunk/beta', 'trunk/delta']) | |
72 for r in revs: | |
73 for p in r.paths: | |
74 # make sure these paths are always non-absolute for sanity | |
75 if p: | |
76 assert p[0] != '/' | |
77 revs = list(self.repo.revisions(start=3)) | |
78 tools.eq_(len(revs), 4) | |
79 | |
80 | |
81 def test_branches(self): | |
82 tools.eq_(self.repo.branches.keys(), ['crazy', 'more_crazy']) | |
83 tools.eq_(self.repo.branches['crazy'], ('trunk', 2, 4)) | |
84 tools.eq_(self.repo.branches['more_crazy'], ('trunk', 5, 7)) | |
85 | |
86 | |
87 def test_tags(self): | |
88 tags = self.repo.tags | |
89 tools.eq_(tags.keys(), ['rev1']) | |
90 tools.eq_(tags['rev1'], ('trunk', 2)) | |
91 | |
92 class TestRootAsSubdirOfRepo(TestBasicRepoLayout): | |
93 def setUp(self): | |
94 self.oldwd = os.getcwd() | |
95 self.tmpdir = tempfile.mkdtemp('svnwrap_test') | |
96 self.repo_path = '%s/testrepo' % self.tmpdir | |
97 wc_path = '%s/testrepo_wc' % self.tmpdir | |
98 os.spawnvp(os.P_WAIT, 'svnadmin', ['svnadmin', 'create', | |
99 self.repo_path,]) | |
100 os.spawnvp(os.P_WAIT, 'svn', ['svn', 'checkout', | |
101 'file://%s' % self.repo_path, | |
102 wc_path,]) | |
103 self.repo_path += '/dummyproj' | |
104 os.chdir(wc_path) | |
105 os.mkdir('dummyproj') | |
106 os.chdir('dummyproj') | |
107 wc_path += '/dummyproj' | |
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)) |