0.1.2
by Martin Pool
Import testsweet module adapted from bzr. |
1 |
# Copyright (C) 2005 by 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 |
||
19 |
||
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
20 |
"""test suite for weave algorithm"""
|
0.1.2
by Martin Pool
Import testsweet module adapted from bzr. |
21 |
|
22 |
||
23 |
from testsweet import TestBase |
|
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
24 |
from weave import Weave, VerInfo |
0.1.2
by Martin Pool
Import testsweet module adapted from bzr. |
25 |
|
26 |
||
27 |
# texts for use in testing
|
|
0.1.3
by Martin Pool
Change storage of texts for testing |
28 |
TEXT_0 = ["Hello world"] |
29 |
TEXT_1 = ["Hello world", |
|
30 |
"A second line"] |
|
0.1.2
by Martin Pool
Import testsweet module adapted from bzr. |
31 |
|
32 |
||
33 |
class Easy(TestBase): |
|
34 |
def runTest(self): |
|
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
35 |
k = Weave() |
0.1.2
by Martin Pool
Import testsweet module adapted from bzr. |
36 |
|
37 |
||
38 |
class StoreText(TestBase): |
|
39 |
"""Store and retrieve a simple text."""
|
|
40 |
def runTest(self): |
|
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
41 |
k = Weave() |
0.1.26
by Martin Pool
Refactor parameters to add command |
42 |
idx = k.add([], TEXT_0) |
0.1.4
by Martin Pool
Start indexing knits by both integer and version string. |
43 |
self.assertEqual(k.get(idx), TEXT_0) |
44 |
self.assertEqual(idx, 0) |
|
0.1.2
by Martin Pool
Import testsweet module adapted from bzr. |
45 |
|
46 |
||
0.1.7
by Martin Pool
Add trivial annotate text |
47 |
|
48 |
class AnnotateOne(TestBase): |
|
49 |
def runTest(self): |
|
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
50 |
k = Weave() |
0.1.26
by Martin Pool
Refactor parameters to add command |
51 |
k.add([], TEXT_0) |
0.1.7
by Martin Pool
Add trivial annotate text |
52 |
self.assertEqual(k.annotate(0), |
53 |
[(0, TEXT_0[0])]) |
|
54 |
||
55 |
||
0.1.5
by Martin Pool
Add test for storing two text versions. |
56 |
class StoreTwo(TestBase): |
57 |
def runTest(self): |
|
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
58 |
k = Weave() |
0.1.5
by Martin Pool
Add test for storing two text versions. |
59 |
|
0.1.26
by Martin Pool
Refactor parameters to add command |
60 |
idx = k.add([], TEXT_0) |
0.1.5
by Martin Pool
Add test for storing two text versions. |
61 |
self.assertEqual(idx, 0) |
62 |
||
0.1.26
by Martin Pool
Refactor parameters to add command |
63 |
idx = k.add([], TEXT_1) |
0.1.5
by Martin Pool
Add test for storing two text versions. |
64 |
self.assertEqual(idx, 1) |
65 |
||
66 |
self.assertEqual(k.get(0), TEXT_0) |
|
67 |
self.assertEqual(k.get(1), TEXT_1) |
|
68 |
||
0.1.13
by Martin Pool
Knit structure now allows for versions to include the lines present in other |
69 |
k.dump(self.TEST_LOG) |
70 |
||
71 |
||
0.1.21
by Martin Pool
Start computing a delta to insert a new revision |
72 |
|
73 |
class Delta1(TestBase): |
|
74 |
"""Detection of changes prior to inserting new revision."""
|
|
75 |
def runTest(self): |
|
76 |
from pprint import pformat |
|
77 |
||
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
78 |
k = Weave() |
0.1.26
by Martin Pool
Refactor parameters to add command |
79 |
k.add([], ['line 1']) |
0.1.21
by Martin Pool
Start computing a delta to insert a new revision |
80 |
|
0.1.22
by Martin Pool
Calculate delta for new versions relative to a set of parent versions. |
81 |
changes = list(k._delta(set([0]), |
82 |
['line 1', |
|
83 |
'new line'])) |
|
0.1.21
by Martin Pool
Start computing a delta to insert a new revision |
84 |
|
85 |
self.log('raw changes: ' + pformat(changes)) |
|
86 |
||
0.1.24
by Martin Pool
Add another change for delta of new version. |
87 |
# should be one inserted line after line 0q
|
0.1.22
by Martin Pool
Calculate delta for new versions relative to a set of parent versions. |
88 |
self.assertEquals(changes, |
89 |
[(1, 1, ['new line'])]) |
|
90 |
||
0.1.24
by Martin Pool
Add another change for delta of new version. |
91 |
changes = k._delta(set([0]), |
92 |
['top line', |
|
93 |
'line 1']) |
|
94 |
||
95 |
self.assertEquals(list(changes), |
|
96 |
[(0, 0, ['top line'])]) |
|
97 |
||
98 |
||
0.1.21
by Martin Pool
Start computing a delta to insert a new revision |
99 |
|
0.1.27
by Martin Pool
Check that version numbers passed in are reasonable |
100 |
class InvalidAdd(TestBase): |
101 |
"""Try to use invalid version number during add."""
|
|
102 |
def runTest(self): |
|
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
103 |
k = Weave() |
0.1.27
by Martin Pool
Check that version numbers passed in are reasonable |
104 |
|
105 |
self.assertRaises(IndexError, |
|
106 |
k.add, |
|
107 |
[69], |
|
108 |
['new text!']) |
|
109 |
||
110 |
||
0.1.26
by Martin Pool
Refactor parameters to add command |
111 |
class InsertLines(TestBase): |
0.1.13
by Martin Pool
Knit structure now allows for versions to include the lines present in other |
112 |
"""Store a revision that adds one line to the original.
|
113 |
||
114 |
Look at the annotations to make sure that the first line is matched
|
|
115 |
and not stored repeatedly."""
|
|
116 |
def runTest(self): |
|
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
117 |
k = Weave() |
0.1.13
by Martin Pool
Knit structure now allows for versions to include the lines present in other |
118 |
|
0.1.26
by Martin Pool
Refactor parameters to add command |
119 |
k.add([], ['line 1']) |
120 |
k.add([0], ['line 1', 'line 2']) |
|
0.1.13
by Martin Pool
Knit structure now allows for versions to include the lines present in other |
121 |
|
122 |
self.assertEqual(k.annotate(0), |
|
123 |
[(0, 'line 1')]) |
|
124 |
||
0.1.25
by Martin Pool
Handle insertion of new weave layers that insert text on top of the basis |
125 |
self.assertEqual(k.get(1), |
126 |
['line 1', |
|
127 |
'line 2']) |
|
128 |
||
0.1.13
by Martin Pool
Knit structure now allows for versions to include the lines present in other |
129 |
self.assertEqual(k.annotate(1), |
130 |
[(0, 'line 1'), |
|
131 |
(1, 'line 2')]) |
|
132 |
||
0.1.28
by Martin Pool
More tests for insertion of lines in new versions. |
133 |
k.add([0], ['line 1', 'diverged line']) |
134 |
||
135 |
self.assertEqual(k.annotate(2), |
|
136 |
[(0, 'line 1'), |
|
137 |
(2, 'diverged line')]) |
|
138 |
||
139 |
k.add([0, 1], |
|
140 |
['line 1', 'middle line', 'line 2']) |
|
141 |
||
142 |
self.assertEqual(k.annotate(3), |
|
143 |
[(0, 'line 1'), |
|
144 |
(3, 'middle line'), |
|
145 |
(1, 'line 2')]) |
|
146 |
||
0.1.31
by Martin Pool
Fix insertion of multiple regions, calculating the right line offset as we go. |
147 |
# now multiple insertions at different places
|
148 |
k.add([0, 1, 3], |
|
149 |
['line 1', 'aaa', 'middle line', 'bbb', 'line 2', 'ccc']) |
|
150 |
||
151 |
self.assertEqual(k.annotate(4), |
|
152 |
[(0, 'line 1'), |
|
153 |
(4, 'aaa'), |
|
154 |
(3, 'middle line'), |
|
155 |
(4, 'bbb'), |
|
156 |
(1, 'line 2'), |
|
157 |
(4, 'ccc')]) |
|
0.1.13
by Martin Pool
Knit structure now allows for versions to include the lines present in other |
158 |
|
0.1.30
by Martin Pool
Start adding tests for line deletion |
159 |
class DeleteLines(TestBase): |
160 |
"""Test recording revisions that delete lines.
|
|
161 |
||
162 |
This relies on the weave having a way to represent lines knocked
|
|
163 |
out by a later revision."""
|
|
164 |
def runTest(self): |
|
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
165 |
k = Weave() |
0.1.30
by Martin Pool
Start adding tests for line deletion |
166 |
|
167 |
k.add([], ["line the first", |
|
168 |
"line 2", |
|
169 |
"line 3", |
|
170 |
"fine"]) |
|
171 |
||
172 |
self.assertEqual(len(k.get(0)), 4) |
|
173 |
||
174 |
return ################################## SKIPPED |
|
175 |
||
176 |
k.add([0], ["line the first", |
|
177 |
"fine"]) |
|
178 |
||
179 |
self.assertEqual(k.get(1), |
|
180 |
["line the first", |
|
181 |
"fine"]) |
|
182 |
||
183 |
||
0.1.26
by Martin Pool
Refactor parameters to add command |
184 |
|
0.1.13
by Martin Pool
Knit structure now allows for versions to include the lines present in other |
185 |
class IncludeVersions(TestBase): |
186 |
"""Check texts that are stored across multiple revisions.
|
|
187 |
||
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
188 |
Here we manually create a weave with particular encoding and make
|
0.1.13
by Martin Pool
Knit structure now allows for versions to include the lines present in other |
189 |
sure it unpacks properly.
|
190 |
||
191 |
Text 0 includes nothing; text 1 includes text 0 and adds some
|
|
192 |
lines.
|
|
193 |
"""
|
|
194 |
||
195 |
def runTest(self): |
|
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
196 |
k = Weave() |
0.1.13
by Martin Pool
Knit structure now allows for versions to include the lines present in other |
197 |
|
0.1.17
by Martin Pool
Use objects rather than tuples for tracking VerInfo for |
198 |
k._v = [VerInfo(), VerInfo(included=[0])] |
0.1.13
by Martin Pool
Knit structure now allows for versions to include the lines present in other |
199 |
k._l = [(0, "first line"), |
200 |
(1, "second line")] |
|
201 |
||
202 |
self.assertEqual(k.get(1), |
|
203 |
["first line", |
|
204 |
"second line"]) |
|
205 |
||
206 |
self.assertEqual(k.get(0), |
|
207 |
["first line"]) |
|
208 |
||
209 |
k.dump(self.TEST_LOG) |
|
210 |
||
0.1.5
by Martin Pool
Add test for storing two text versions. |
211 |
|
0.1.14
by Martin Pool
Another test for version inclusion |
212 |
class DivergedIncludes(TestBase): |
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
213 |
"""Weave with two diverged texts based on version 0.
|
0.1.14
by Martin Pool
Another test for version inclusion |
214 |
"""
|
215 |
def runTest(self): |
|
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
216 |
k = Weave() |
0.1.14
by Martin Pool
Another test for version inclusion |
217 |
|
0.1.17
by Martin Pool
Use objects rather than tuples for tracking VerInfo for |
218 |
k._v = [VerInfo(), |
219 |
VerInfo(included=[0]), |
|
220 |
VerInfo(included=[0]), |
|
221 |
]
|
|
0.1.14
by Martin Pool
Another test for version inclusion |
222 |
k._l = [(0, "first line"), |
223 |
(1, "second line"), |
|
224 |
(2, "alternative second line"),] |
|
225 |
||
226 |
self.assertEqual(k.get(0), |
|
227 |
["first line"]) |
|
228 |
||
229 |
self.assertEqual(k.get(1), |
|
230 |
["first line", |
|
231 |
"second line"]) |
|
232 |
||
233 |
self.assertEqual(k.get(2), |
|
234 |
["first line", |
|
235 |
"alternative second line"]) |
|
236 |
||
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
237 |
def testweave(): |
0.1.2
by Martin Pool
Import testsweet module adapted from bzr. |
238 |
import testsweet |
239 |
from unittest import TestSuite, TestLoader |
|
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
240 |
import testweave |
0.1.2
by Martin Pool
Import testsweet module adapted from bzr. |
241 |
|
242 |
tl = TestLoader() |
|
243 |
suite = TestSuite() |
|
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
244 |
suite.addTest(tl.loadTestsFromModule(testweave)) |
0.1.2
by Martin Pool
Import testsweet module adapted from bzr. |
245 |
|
0.1.15
by Martin Pool
Fix inverted shell return code for testknit |
246 |
return int(not testsweet.run_suite(suite)) # for shell 0=true |
0.1.2
by Martin Pool
Import testsweet module adapted from bzr. |
247 |
|
248 |
||
249 |
if __name__ == '__main__': |
|
250 |
import sys |
|
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
251 |
sys.exit(testweave()) |
0.1.2
by Martin Pool
Import testsweet module adapted from bzr. |
252 |