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.5
by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info |
32 |
from generate_version_info import (is_clean, |
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 |
||
36 |
class TestIsClean(TestCaseInTempDir): |
|
37 |
||
38 |
# TODO: jam 20051228 Test that a branch without a working tree
|
|
39 |
# is clean. This would be something like an SFTP test
|
|
40 |
||
41 |
def test_is_clean(self): |
|
42 |
b = Branch.initialize('.') |
|
43 |
wt = b.working_tree() |
|
44 |
||
45 |
def not_clean(b): |
|
|
0.8.3
by John Arbash Meinel
Playing around with some formats |
46 |
clean, message = is_clean(b) |
47 |
if clean: |
|
48 |
self.fail('Tree should not be clean') |
|
49 |
||
50 |
def check_clean(b): |
|
51 |
clean, message = is_clean(b) |
|
52 |
if not clean: |
|
53 |
self.fail(message) |
|
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
54 |
|
55 |
# Nothing happened yet
|
|
|
0.8.3
by John Arbash Meinel
Playing around with some formats |
56 |
check_clean(b) |
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
57 |
|
58 |
# Unknown file
|
|
59 |
open('a', 'wb').write('a file\n') |
|
60 |
not_clean(b) |
|
61 |
||
62 |
# Newly added file
|
|
63 |
wt.add('a') |
|
64 |
not_clean(b) |
|
65 |
||
66 |
# We committed, things are clean
|
|
67 |
wt.commit('added a') |
|
|
0.8.3
by John Arbash Meinel
Playing around with some formats |
68 |
check_clean(b) |
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
69 |
|
70 |
# Unknown
|
|
71 |
open('b', 'wb').write('b file\n') |
|
72 |
not_clean(b) |
|
73 |
||
74 |
wt.add('b') |
|
75 |
not_clean(b) |
|
76 |
||
77 |
wt.commit('added b') |
|
|
0.8.3
by John Arbash Meinel
Playing around with some formats |
78 |
check_clean(b) |
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
79 |
|
80 |
open('a', 'wb').write('different\n') |
|
81 |
not_clean(b) |
|
82 |
||
83 |
wt.commit('mod a') |
|
|
0.8.3
by John Arbash Meinel
Playing around with some formats |
84 |
check_clean(b) |
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
85 |
|
86 |
os.remove('a') |
|
87 |
not_clean(b) |
|
88 |
||
89 |
wt.commit('del a') |
|
|
0.8.3
by John Arbash Meinel
Playing around with some formats |
90 |
check_clean(b) |
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
91 |
|
92 |
wt.rename_one('b', 'a') |
|
93 |
not_clean(b) |
|
94 |
||
95 |
wt.commit('rename b => a') |
|
|
0.8.3
by John Arbash Meinel
Playing around with some formats |
96 |
check_clean(b) |
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
97 |
|
98 |
||
99 |
class TestVersionInfo(TestCaseInTempDir): |
|
|
0.8.5
by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info |
100 |
|
101 |
def create_branch(self): |
|
102 |
os.mkdir('branch') |
|
103 |
b = Branch.initialize(u'branch') |
|
104 |
wt = b.working_tree() |
|
105 |
||
106 |
open('branch/a', 'wb').write('a file\n') |
|
107 |
wt.add('a') |
|
108 |
wt.commit('a', rev_id='r1') |
|
109 |
||
110 |
open('branch/b', 'wb').write('b file\n') |
|
111 |
wt.add('b') |
|
112 |
wt.commit('b', rev_id='r2') |
|
113 |
||
114 |
open('branch/a', 'wb').write('new contents\n') |
|
115 |
wt.commit('a2', rev_id='r3') |
|
116 |
||
117 |
return b, wt |
|
118 |
||
|
0.8.7
by John Arbash Meinel
Adding tests for parsing the rio text back into rio. |
119 |
def test_rio_version_text(self): |
|
0.8.5
by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info |
120 |
b, wt = self.create_branch() |
121 |
||
122 |
def regen(**kwargs): |
|
123 |
sio = StringIO() |
|
124 |
generate_rio_version(b, to_file=sio, **kwargs) |
|
125 |
val = sio.getvalue() |
|
126 |
return val |
|
127 |
||
128 |
val = regen() |
|
129 |
self.assertContainsRe(val, 'date:') |
|
130 |
self.assertContainsRe(val, 'revno: 3') |
|
131 |
self.assertContainsRe(val, 'revision_id: r3') |
|
132 |
||
133 |
val = regen(check_for_clean=True) |
|
134 |
self.assertContainsRe(val, 'clean: True') |
|
135 |
||
136 |
open('branch/c', 'wb').write('now unclean\n') |
|
137 |
val = regen(check_for_clean=True) |
|
138 |
self.assertContainsRe(val, 'clean: False') |
|
139 |
os.remove('branch/c') |
|
140 |
||
141 |
val = regen(include_revision_history=True) |
|
|
0.8.6
by John Arbash Meinel
Updated the blackbox tests. |
142 |
self.assertContainsRe(val, 'id: r1') |
|
0.8.5
by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info |
143 |
self.assertContainsRe(val, 'message: a') |
|
0.8.6
by John Arbash Meinel
Updated the blackbox tests. |
144 |
self.assertContainsRe(val, 'id: r2') |
|
0.8.5
by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info |
145 |
self.assertContainsRe(val, 'message: b') |
|
0.8.6
by John Arbash Meinel
Updated the blackbox tests. |
146 |
self.assertContainsRe(val, 'id: r3') |
|
0.8.5
by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info |
147 |
self.assertContainsRe(val, 'message: a2') |
148 |
||
|
0.8.7
by John Arbash Meinel
Adding tests for parsing the rio text back into rio. |
149 |
def test_rio_version(self): |
150 |
b, wt = self.create_branch() |
|
151 |
||
152 |
def regen(**kwargs): |
|
153 |
sio = StringIO() |
|
154 |
generate_rio_version(b, to_file=sio, **kwargs) |
|
155 |
sio.seek(0) |
|
156 |
stanzas = list(read_stanzas(sio)) |
|
157 |
self.assertEqual(1, len(stanzas)) |
|
158 |
return stanzas[0] |
|
159 |
||
160 |
stanza = regen() |
|
161 |
self.failUnless('date' in stanza) |
|
162 |
self.assertEqual(['3'], stanza.get_all('revno')) |
|
163 |
self.assertEqual(['r3'], stanza.get_all('revision_id')) |
|
164 |
||
165 |
stanza = regen(check_for_clean=True) |
|
166 |
self.assertEqual(['True'], stanza.get_all('clean')) |
|
167 |
||
168 |
open('branch/c', 'wb').write('now unclean\n') |
|
169 |
stanza = regen(check_for_clean=True) |
|
170 |
self.assertEqual(['False'], stanza.get_all('clean')) |
|
171 |
os.remove('branch/c') |
|
172 |
||
173 |
stanza = regen(include_revision_history=True) |
|
174 |
txt = stanza['revisions'] |
|
175 |
revision_stanza = list(read_stanzas(StringIO(txt))) |
|
176 |
self.assertEqual(1, len(revision_stanza)) |
|
177 |
revision_stanza = revision_stanza[0] |
|
178 |
self.assertEqual(['r1', 'r2', 'r3'], revision_stanza.get_all('id')) |
|
179 |
self.assertEqual(['a', 'b', 'a2'], revision_stanza.get_all('message')) |
|
180 |
||
|
0.8.5
by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info |
181 |
def test_python_version(self): |
182 |
b, wt = self.create_branch() |
|
183 |
||
184 |
def regen(**kwargs): |
|
185 |
outf = open('test_version_information.py', 'wb') |
|
186 |
generate_python_version(b, to_file=outf, **kwargs) |
|
187 |
outf.close() |
|
188 |
try: |
|
189 |
sys.path.append(os.getcwdu()) |
|
190 |
import test_version_information as tvi |
|
191 |
reload(tvi) |
|
192 |
finally: |
|
193 |
sys.path.pop() |
|
194 |
# Make sure the module isn't cached
|
|
195 |
sys.modules.pop('tvi', None) |
|
196 |
sys.modules.pop('test_version_information', None) |
|
197 |
# Delete the compiled versions, because we are generating
|
|
198 |
# a new file fast enough that python doesn't detect it
|
|
199 |
# needs to recompile, and using sleep() just makes the
|
|
200 |
# test slow
|
|
201 |
if os.path.exists('test_version_information.pyc'): |
|
202 |
os.remove('test_version_information.pyc') |
|
203 |
if os.path.exists('test_version_information.pyo'): |
|
204 |
os.remove('test_version_information.pyo') |
|
205 |
return tvi |
|
206 |
||
207 |
tvi = regen() |
|
208 |
self.assertEquals(3, tvi.version_info['revno']) |
|
209 |
self.assertEquals('r3', tvi.version_info['revision_id']) |
|
210 |
self.failUnless(tvi.version_info.has_key('date')) |
|
211 |
self.assertEquals(None, tvi.version_info['clean']) |
|
212 |
||
213 |
tvi = regen(check_for_clean=True) |
|
214 |
self.assertEquals(True, tvi.version_info['clean']) |
|
215 |
||
216 |
open('branch/c', 'wb').write('now unclean\n') |
|
217 |
tvi = regen(check_for_clean=True) |
|
218 |
self.assertEquals(False, tvi.version_info['clean']) |
|
219 |
os.remove('branch/c') |
|
220 |
||
221 |
tvi = regen(include_revision_history=True) |
|
222 |
self.assertEqual([('r1', 'a'), ('r2', 'b'), ('r3', 'a2')], |
|
223 |
tvi.version_info['revisions']) |
|
224 |
||
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
225 |