-
Notifications
You must be signed in to change notification settings - Fork 3
/
SvnSandbox_test.py
executable file
·214 lines (182 loc) · 6.62 KB
/
SvnSandbox_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/usr/bin/python
from SvnSandbox import SvnSandbox
import utils
import os
import unittest
class SvnSandboxTest(unittest.TestCase) :
def x(self, command) :
return utils.run(command%self.defs)
def inSandbox(self, file) :
return os.path.join(self.defs['sandbox'],file)
def addFile(self, file, commit=True) :
self.x('touch %%(sandbox)s/%s'%file)
self.x('svn add %%(sandbox)s/%s'%file)
if commit :
self.commitFile(file, "added %s" % file)
def removeFile(self, file, commit=True) :
self.x('svn rm %%(sandbox)s/%s'%file)
if commit :
self.commitFile(file, "removed %s" % file)
def addRevisions(self, file, n, commit=True) :
for i in xrange(n) :
self.x('echo Change %s >> %%(sandbox)s/%s'%(i,file))
if commit :
self.commitFile(file, "change %i of %s"%(i,file))
def pushRevision(self) :
self.revisions.append(str(len(self.revisions)))
print "REVISIONS", self.revisions
def commitFile(self, file, message) :
self.x('svn commit %%(sandbox)s/%s -m"%s"'%(file,message))
self.x('svn up %(sandbox)s')
self.pushRevision()
def commitAll(self, message) :
self.x('svn commit %%(sandbox)s/ -m"%s"'%(message))
self.x('svn up %(sandbox)s')
self.pushRevision()
def rewind(self, revisions=1) :
target = int(self.current())-revisions
self.x('svn up -r%s %%(sandbox)s'%(target))
def current(self) :
output = utils.output('svn info -r BASE %(sandbox)s | grep ^Revision: '%self.defs)
print "CURRENT",output.split()
return output.split()[-1]
def setUp(self) :
self.defs = dict(
username = "myuser",
testdir = os.path.join(os.getcwd(),'testdir'),
repo = os.path.join(os.getcwd(),'testdir/repo'),
sandbox = os.path.join(os.getcwd(),'testdir/sandbox1'),
)
self.x('rm -rf %(testdir)s')
self.x('mkdir -p %(testdir)s')
self.revisions = ['0']
self.x('svnadmin create %(repo)s')
self.x('svn co --username %(username)s file://%(repo)s %(sandbox)s')
def tearDown(self) :
""" """
# self.x('svn log %(sandbox)s')
self.x('rm -rf %(testdir)s')
def test_state(self) :
self.addFile('file')
self.addRevisions('file',3)
s = SvnSandbox(self.defs['sandbox'])
self.assertEquals(self.revisions[4], s.state())
self.rewind(3)
self.assertEquals(self.revisions[1], s.state())
def test_remoteState(self) :
self.addFile('file')
self.addRevisions('file',3)
s = SvnSandbox(self.defs['sandbox'])
self.assertEquals(self.revisions[4], s.remoteState())
self.rewind(3)
self.assertEquals(self.revisions[4], s.remoteState())
def test_update(self) :
self.addFile('file')
self.addRevisions('file',3)
s = SvnSandbox(self.defs['sandbox'])
self.rewind(3)
s.update()
self.assertEquals(self.revisions[4], s.state())
def test_update_withConflictPostpones(self) :
self.addFile('file')
self.addRevisions('file',3)
s = SvnSandbox(self.defs['sandbox'])
self.rewind(2)
self.addRevisions('file',1, False) # local conflicting change
s.update()
self.assertEquals(self.revisions[4], s.state())
# TODO: Check that file is left in conflict
def test_pendingCommits(self) :
self.addFile('file')
self.addRevisions('file',3)
self.rewind(3)
s = SvnSandbox(self.defs['sandbox'])
self.assertEquals(
self.revisions[-3:], s.pendingUpdates())
def test_guilty(self) :
self.addFile('file')
self.addRevisions('file',3)
self.rewind(3)
s = SvnSandbox(self.defs['sandbox'])
self.assertEquals(
[
(rev, self.defs['username'], "change %i of file"%i)
for i, rev in enumerate(self.revisions[-3:])
], s.guilty())
def test_pendingChanges(self) :
self.addFile('remoteChange', False)
self.addFile('remoteRemove', False)
self.addFile('localRemove', False)
self.addFile('localChange', False)
self.addFile('nonsvnRemove', False)
self.commitAll("State were we want to go back")
self.addRevisions('remoteChange',1, False)
self.addFile('remoteAdd', False)
self.removeFile('remoteRemove', False)
self.commitAll("State we want to update to")
self.rewind(1)
# local modifications
self.addRevisions('localChange', 1, False)
self.removeFile('localRemove', False)
self.addFile('localAdd', False)
self.x('echo nonsvnAdd > %(sandbox)s/nonsvnAdd')
self.x('rm %(sandbox)s/nonsvnRemove')
s = SvnSandbox(self.defs['sandbox'])
self.maxDiff = None
self.assertEquals(
[
(self.defs['sandbox'], ('normal', 'none', 'modified', 'none')),
(self.inSandbox('localAdd'), ('added', 'none', 'none', 'none')),
(self.inSandbox('localChange'), ('modified', 'none', 'none', 'none')),
(self.inSandbox('localRemove'), ('deleted', 'none', 'none', 'none')),
(self.inSandbox('nonsvnAdd'), ('unversioned', 'none', 'none', 'none')),
(self.inSandbox('nonsvnRemove'), ('missing', 'none', 'none', 'none')),
(self.inSandbox('remoteAdd'), ('none', 'none', 'added', 'none')),
(self.inSandbox('remoteChange'), ('normal', 'none', 'modified', 'none')),
(self.inSandbox('remoteRemove'), ('normal', 'none', 'deleted', 'none')),
], sorted(s._pendingChanges()))
def test_hasPendingChanges_whenNoPendingChanges(self) :
self.addFile('remoteChange', False)
self.addFile('remoteRemove', False)
self.addFile('localRemove', False)
self.addFile('localChange', False)
self.addFile('nonsvnRemove', False)
self.commitAll("State were we want to go back")
s = SvnSandbox(self.defs['sandbox'])
self.assertFalse(s.hasPendingChanges())
def test_hasPendingChanges_whenMissingFile(self) :
self.addFile('nonsvnRemove')
self.x('rm %(sandbox)s/nonsvnRemove')
s = SvnSandbox(self.defs['sandbox'])
self.assertTrue(s.hasPendingChanges())
def test_hasPendingChanges_whenPendingModification(self) :
self.addFile('remoteChange')
self.addRevisions('remoteChange',1)
self.rewind(1)
s = SvnSandbox(self.defs['sandbox'])
self.assertTrue(s.hasPendingChanges())
def test_hasPendingChanges_whenPendingRemove(self) :
self.addFile('remoteRemove')
self.removeFile('remoteRemove')
self.rewind(1)
s = SvnSandbox(self.defs['sandbox'])
self.assertTrue(s.hasPendingChanges())
def test_hasPendingChanges_whenPendingAdd(self) :
self.addFile('remoteAdd')
self.rewind(1)
s = SvnSandbox(self.defs['sandbox'])
self.assertTrue(s.hasPendingChanges())
def test_hasPendingChanges_whenLocalChanges(self) :
self.addFile('localRemove', False)
self.addFile('localChange', False)
self.commitAll("State were we want to go back")
# any local modifications (but non-svn deletion)
self.addRevisions('localChange', 1, False)
self.removeFile('localRemove', False)
self.addFile('localAdd', False)
self.x('echo nonsvnAdd > %(sandbox)s/nonsvnAdd')
s = SvnSandbox(self.defs['sandbox'])
self.maxDiff = None
self.assertFalse(s.hasPendingChanges())
if __name__ == '__main__' :
unittest.main()