bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
1 |
# Copyright (C) 2005 Canonical Ltd
|
2 |
||
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
||
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
||
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
17 |
"""\
|
|
18 |
Tests for version_info
|
|
19 |
"""
|
|
20 |
||
21 |
import os |
|
|
0.8.5
by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info |
22 |
import sys |
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
23 |
|
|
0.8.5
by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info |
24 |
from StringIO import StringIO |
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
25 |
from bzrlib.tests import TestCase, TestCaseInTempDir |
26 |
from bzrlib.branch import Branch |
|
|
0.8.7
by John Arbash Meinel
Adding tests for parsing the rio text back into rio. |
27 |
from bzrlib.rio import read_stanzas |
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
28 |
|
29 |
# TODO: jam 20051228 When part of bzrlib, this should become
|
|
30 |
# from bzrlib.generate_version_info import foo
|
|
31 |
||
|
0.8.13
by John Arbash Meinel
Including file-revisions fields, updated test suite. |
32 |
from generate_version_info import ( |
|
0.8.5
by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info |
33 |
generate_rio_version, generate_python_version) |
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
34 |
|
35 |
||
|
0.8.13
by John Arbash Meinel
Including file-revisions fields, updated test suite. |
36 |
# TODO: Change this to testing get_file_revisions
|
37 |
class TestIsClean(object): |
|
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
38 |
|
39 |
# TODO: jam 20051228 Test that a branch without a working tree
|
|
40 |
# is clean. This would be something like an SFTP test
|
|
41 |
||
42 |
def test_is_clean(self): |
|
43 |
b = Branch.initialize('.') |
|
44 |
wt = b.working_tree() |
|
45 |
||
46 |
def not_clean(b): |
|
|
0.8.3
by John Arbash Meinel
Playing around with some formats |
47 |
clean, message = is_clean(b) |
48 |
if clean: |
|
49 |
self.fail('Tree should not be clean') |
|
50 |
||
51 |
def check_clean(b): |
|
52 |
clean, message = is_clean(b) |
|
53 |
if not clean: |
|
54 |
self.fail(message) |
|
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
55 |
|
56 |
# Nothing happened yet
|
|
|
0.8.3
by John Arbash Meinel
Playing around with some formats |
57 |
check_clean(b) |
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
58 |
|
59 |
# Unknown file
|
|
60 |
open('a', 'wb').write('a file\n') |
|
61 |
not_clean(b) |
|
62 |
||
63 |
# Newly added file
|
|
64 |
wt.add('a') |
|
65 |
not_clean(b) |
|
66 |
||
67 |
# We committed, things are clean
|
|
68 |
wt.commit('added a') |
|
|
0.8.3
by John Arbash Meinel
Playing around with some formats |
69 |
check_clean(b) |
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
70 |
|
71 |
# Unknown
|
|
72 |
open('b', 'wb').write('b file\n') |
|
73 |
not_clean(b) |
|
74 |
||
75 |
wt.add('b') |
|
76 |
not_clean(b) |
|
77 |
||
78 |
wt.commit('added b') |
|
|
0.8.3
by John Arbash Meinel
Playing around with some formats |
79 |
check_clean(b) |
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
80 |
|
81 |
open('a', 'wb').write('different\n') |
|
82 |
not_clean(b) |
|
83 |
||
84 |
wt.commit('mod a') |
|
|
0.8.3
by John Arbash Meinel
Playing around with some formats |
85 |
check_clean(b) |
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
86 |
|
87 |
os.remove('a') |
|
88 |
not_clean(b) |
|
89 |
||
90 |
wt.commit('del a') |
|
|
0.8.3
by John Arbash Meinel
Playing around with some formats |
91 |
check_clean(b) |
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
92 |
|
93 |
wt.rename_one('b', 'a') |
|
94 |
not_clean(b) |
|
95 |
||
96 |
wt.commit('rename b => a') |
|
|
0.8.3
by John Arbash Meinel
Playing around with some formats |
97 |
check_clean(b) |
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
98 |
|
99 |
||
100 |
class TestVersionInfo(TestCaseInTempDir): |
|
|
0.8.5
by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info |
101 |
|
102 |
def create_branch(self): |
|
103 |
os.mkdir('branch') |
|
104 |
b = Branch.initialize(u'branch') |
|
105 |
wt = b.working_tree() |
|
106 |
||
107 |
open('branch/a', 'wb').write('a file\n') |
|
108 |
wt.add('a') |
|
109 |
wt.commit('a', rev_id='r1') |
|
110 |
||
111 |
open('branch/b', 'wb').write('b file\n') |
|
112 |
wt.add('b') |
|
113 |
wt.commit('b', rev_id='r2') |
|
114 |
||
115 |
open('branch/a', 'wb').write('new contents\n') |
|
116 |
wt.commit('a2', rev_id='r3') |
|
117 |
||
118 |
return b, wt |
|
119 |
||
|
0.8.7
by John Arbash Meinel
Adding tests for parsing the rio text back into rio. |
120 |
def test_rio_version_text(self): |
|
0.8.5
by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info |
121 |
b, wt = self.create_branch() |
122 |
||
123 |
def regen(**kwargs): |
|
124 |
sio = StringIO() |
|
125 |
generate_rio_version(b, to_file=sio, **kwargs) |
|
126 |
val = sio.getvalue() |
|
127 |
return val |
|
128 |
||
129 |
val = regen() |
|
|
0.8.13
by John Arbash Meinel
Including file-revisions fields, updated test suite. |
130 |
self.assertContainsRe(val, 'build-date:') |
|
0.8.5
by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info |
131 |
self.assertContainsRe(val, 'date:') |
132 |
self.assertContainsRe(val, 'revno: 3') |
|
|
0.8.16
by John Arbash Meinel
Using revision-id for rio, and revision_id for python |
133 |
self.assertContainsRe(val, 'revision-id: r3') |
|
0.8.5
by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info |
134 |
|
135 |
val = regen(check_for_clean=True) |
|
136 |
self.assertContainsRe(val, 'clean: True') |
|
137 |
||
138 |
open('branch/c', 'wb').write('now unclean\n') |
|
139 |
val = regen(check_for_clean=True) |
|
140 |
self.assertContainsRe(val, 'clean: False') |
|
141 |
os.remove('branch/c') |
|
142 |
||
143 |
val = regen(include_revision_history=True) |
|
|
0.8.6
by John Arbash Meinel
Updated the blackbox tests. |
144 |
self.assertContainsRe(val, 'id: r1') |
|
0.8.5
by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info |
145 |
self.assertContainsRe(val, 'message: a') |
|
0.8.6
by John Arbash Meinel
Updated the blackbox tests. |
146 |
self.assertContainsRe(val, 'id: r2') |
|
0.8.5
by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info |
147 |
self.assertContainsRe(val, 'message: b') |
|
0.8.6
by John Arbash Meinel
Updated the blackbox tests. |
148 |
self.assertContainsRe(val, 'id: r3') |
|
0.8.5
by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info |
149 |
self.assertContainsRe(val, 'message: a2') |
150 |
||
|
0.8.7
by John Arbash Meinel
Adding tests for parsing the rio text back into rio. |
151 |
def test_rio_version(self): |
152 |
b, wt = self.create_branch() |
|
153 |
||
154 |
def regen(**kwargs): |
|
155 |
sio = StringIO() |
|
156 |
generate_rio_version(b, to_file=sio, **kwargs) |
|
157 |
sio.seek(0) |
|
158 |
stanzas = list(read_stanzas(sio)) |
|
159 |
self.assertEqual(1, len(stanzas)) |
|
160 |
return stanzas[0] |
|
161 |
||
|
0.8.13
by John Arbash Meinel
Including file-revisions fields, updated test suite. |
162 |
def get_one_stanza(stanza, key): |
163 |
new_stanzas = list(read_stanzas(StringIO(stanza[key]))) |
|
164 |
self.assertEqual(1, len(new_stanzas)) |
|
165 |
return new_stanzas[0] |
|
166 |
||
|
0.8.7
by John Arbash Meinel
Adding tests for parsing the rio text back into rio. |
167 |
stanza = regen() |
168 |
self.failUnless('date' in stanza) |
|
|
0.8.13
by John Arbash Meinel
Including file-revisions fields, updated test suite. |
169 |
self.failUnless('build-date' in stanza) |
|
0.8.7
by John Arbash Meinel
Adding tests for parsing the rio text back into rio. |
170 |
self.assertEqual(['3'], stanza.get_all('revno')) |
|
0.8.16
by John Arbash Meinel
Using revision-id for rio, and revision_id for python |
171 |
self.assertEqual(['r3'], stanza.get_all('revision-id')) |
|
0.8.7
by John Arbash Meinel
Adding tests for parsing the rio text back into rio. |
172 |
|
173 |
stanza = regen(check_for_clean=True) |
|
174 |
self.assertEqual(['True'], stanza.get_all('clean')) |
|
175 |
||
176 |
open('branch/c', 'wb').write('now unclean\n') |
|
|
0.8.13
by John Arbash Meinel
Including file-revisions fields, updated test suite. |
177 |
stanza = regen(check_for_clean=True, include_file_revisions=True) |
|
0.8.7
by John Arbash Meinel
Adding tests for parsing the rio text back into rio. |
178 |
self.assertEqual(['False'], stanza.get_all('clean')) |
|
0.8.13
by John Arbash Meinel
Including file-revisions fields, updated test suite. |
179 |
|
180 |
file_rev_stanza = get_one_stanza(stanza, 'file-revisions') |
|
181 |
self.assertEqual(['a', 'b', 'c'], file_rev_stanza.get_all('path')) |
|
182 |
self.assertEqual(['r3', 'r2', 'unversioned'], |
|
183 |
file_rev_stanza.get_all('revision')) |
|
|
0.8.7
by John Arbash Meinel
Adding tests for parsing the rio text back into rio. |
184 |
os.remove('branch/c') |
185 |
||
186 |
stanza = regen(include_revision_history=True) |
|
|
0.8.13
by John Arbash Meinel
Including file-revisions fields, updated test suite. |
187 |
revision_stanza = get_one_stanza(stanza, 'revisions') |
|
0.8.7
by John Arbash Meinel
Adding tests for parsing the rio text back into rio. |
188 |
self.assertEqual(['r1', 'r2', 'r3'], revision_stanza.get_all('id')) |
189 |
self.assertEqual(['a', 'b', 'a2'], revision_stanza.get_all('message')) |
|
|
0.8.15
by John Arbash Meinel
Including the date stamp for all revisions. |
190 |
self.assertEqual(3, len(revision_stanza.get_all('date'))) |
|
0.8.7
by John Arbash Meinel
Adding tests for parsing the rio text back into rio. |
191 |
|
|
0.8.13
by John Arbash Meinel
Including file-revisions fields, updated test suite. |
192 |
open('branch/a', 'ab').write('adding some more stuff\n') |
193 |
open('branch/c', 'wb').write('new file c\n') |
|
194 |
wt.add('c') |
|
195 |
wt.rename_one('b', 'd') |
|
196 |
stanza = regen(check_for_clean=True, include_file_revisions=True) |
|
197 |
file_rev_stanza = get_one_stanza(stanza, 'file-revisions') |
|
198 |
self.assertEqual(['a', 'b', 'c', 'd'], file_rev_stanza.get_all('path')) |
|
199 |
self.assertEqual(['modified', 'renamed to d', 'new', 'renamed from b'], |
|
200 |
file_rev_stanza.get_all('revision')) |
|
201 |
||
202 |
wt.commit('modified', rev_id='r4') |
|
203 |
wt.remove(['c', 'd']) |
|
204 |
os.remove('branch/d') |
|
205 |
stanza = regen(check_for_clean=True, include_file_revisions=True) |
|
206 |
file_rev_stanza = get_one_stanza(stanza, 'file-revisions') |
|
207 |
self.assertEqual(['a', 'c', 'd'], file_rev_stanza.get_all('path')) |
|
208 |
self.assertEqual(['r4', 'unversioned', 'removed'], |
|
209 |
file_rev_stanza.get_all('revision')) |
|
210 |
||
|
0.8.5
by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info |
211 |
def test_python_version(self): |
212 |
b, wt = self.create_branch() |
|
213 |
||
214 |
def regen(**kwargs): |
|
215 |
outf = open('test_version_information.py', 'wb') |
|
216 |
generate_python_version(b, to_file=outf, **kwargs) |
|
217 |
outf.close() |
|
218 |
try: |
|
219 |
sys.path.append(os.getcwdu()) |
|
220 |
import test_version_information as tvi |
|
221 |
reload(tvi) |
|
222 |
finally: |
|
223 |
sys.path.pop() |
|
224 |
# Make sure the module isn't cached
|
|
225 |
sys.modules.pop('tvi', None) |
|
226 |
sys.modules.pop('test_version_information', None) |
|
227 |
# Delete the compiled versions, because we are generating
|
|
228 |
# a new file fast enough that python doesn't detect it
|
|
229 |
# needs to recompile, and using sleep() just makes the
|
|
230 |
# test slow
|
|
231 |
if os.path.exists('test_version_information.pyc'): |
|
232 |
os.remove('test_version_information.pyc') |
|
233 |
if os.path.exists('test_version_information.pyo'): |
|
234 |
os.remove('test_version_information.pyo') |
|
235 |
return tvi |
|
236 |
||
237 |
tvi = regen() |
|
|
0.8.13
by John Arbash Meinel
Including file-revisions fields, updated test suite. |
238 |
self.assertEqual(3, tvi.version_info['revno']) |
239 |
self.assertEqual('r3', tvi.version_info['revision_id']) |
|
|
0.8.5
by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info |
240 |
self.failUnless(tvi.version_info.has_key('date')) |
|
0.8.13
by John Arbash Meinel
Including file-revisions fields, updated test suite. |
241 |
self.assertEqual(None, tvi.version_info['clean']) |
|
0.8.5
by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info |
242 |
|
243 |
tvi = regen(check_for_clean=True) |
|
|
0.8.13
by John Arbash Meinel
Including file-revisions fields, updated test suite. |
244 |
self.assertEqual(True, tvi.version_info['clean']) |
|
0.8.5
by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info |
245 |
|
246 |
open('branch/c', 'wb').write('now unclean\n') |
|
|
0.8.13
by John Arbash Meinel
Including file-revisions fields, updated test suite. |
247 |
tvi = regen(check_for_clean=True, include_file_revisions=True) |
248 |
self.assertEqual(False, tvi.version_info['clean']) |
|
249 |
self.assertEqual(['a', 'b', 'c'], sorted(tvi.file_revisions.keys())) |
|
250 |
self.assertEqual('r3', tvi.file_revisions['a']) |
|
251 |
self.assertEqual('r2', tvi.file_revisions['b']) |
|
252 |
self.assertEqual('unversioned', tvi.file_revisions['c']) |
|
|
0.8.5
by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info |
253 |
os.remove('branch/c') |
254 |
||
255 |
tvi = regen(include_revision_history=True) |
|
|
0.8.15
by John Arbash Meinel
Including the date stamp for all revisions. |
256 |
|
257 |
rev_info = [(rev, message) for rev, message, timestamp, timezone |
|
258 |
in tvi.revisions] |
|
259 |
self.assertEqual([('r1', 'a'), ('r2', 'b'), ('r3', 'a2')], rev_info) |
|
|
0.8.13
by John Arbash Meinel
Including file-revisions fields, updated test suite. |
260 |
|
261 |
open('branch/a', 'ab').write('adding some more stuff\n') |
|
262 |
open('branch/c', 'wb').write('new file c\n') |
|
263 |
wt.add('c') |
|
264 |
wt.rename_one('b', 'd') |
|
265 |
tvi = regen(check_for_clean=True, include_file_revisions=True) |
|
266 |
self.assertEqual(['a', 'b', 'c', 'd'], sorted(tvi.file_revisions.keys())) |
|
267 |
self.assertEqual('modified', tvi.file_revisions['a']) |
|
268 |
self.assertEqual('renamed to d', tvi.file_revisions['b']) |
|
269 |
self.assertEqual('new', tvi.file_revisions['c']) |
|
270 |
self.assertEqual('renamed from b', tvi.file_revisions['d']) |
|
271 |
||
272 |
wt.commit('modified', rev_id='r4') |
|
273 |
wt.remove(['c', 'd']) |
|
274 |
os.remove('branch/d') |
|
275 |
tvi = regen(check_for_clean=True, include_file_revisions=True) |
|
276 |
self.assertEqual(['a', 'c', 'd'], sorted(tvi.file_revisions.keys())) |
|
277 |
self.assertEqual('r4', tvi.file_revisions['a']) |
|
278 |
self.assertEqual('unversioned', tvi.file_revisions['c']) |
|
279 |
self.assertEqual('removed', tvi.file_revisions['d']) |
|
|
0.8.5
by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info |
280 |
|
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
281 |