bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
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 |
||
20 |
"""test case for knit/weave algorithm"""
|
|
21 |
||
22 |
||
23 |
from testsweet import TestBase |
|
|
0.1.17
by Martin Pool
Use objects rather than tuples for tracking VerInfo for |
24 |
from knit import Knit, 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): |
|
35 |
k = Knit() |
|
36 |
||
37 |
||
38 |
class StoreText(TestBase): |
|
39 |
"""Store and retrieve a simple text.""" |
|
40 |
def runTest(self): |
|
41 |
k = Knit() |
|
|
0.1.4
by Martin Pool
Start indexing knits by both integer and version string. |
42 |
idx = k.add(TEXT_0) |
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): |
|
50 |
k = Knit() |
|
51 |
k.add(TEXT_0) |
|
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): |
|
58 |
k = Knit() |
|
59 |
||
60 |
idx = k.add(TEXT_0) |
|
61 |
self.assertEqual(idx, 0) |
|
62 |
||
63 |
idx = k.add(TEXT_1) |
|
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 |
||
72 |
class MatchedLine(TestBase): |
|
73 |
"""Store a revision that adds one line to the original. |
|
74 |
||
75 |
Look at the annotations to make sure that the first line is matched
|
|
76 |
and not stored repeatedly."""
|
|
77 |
def runTest(self): |
|
|
0.1.17
by Martin Pool
Use objects rather than tuples for tracking VerInfo for |
78 |
return
|
|
0.1.13
by Martin Pool
Knit structure now allows for versions to include the lines present in other |
79 |
k = Knit() |
80 |
||
81 |
k.add(['line 1']) |
|
82 |
k.add(['line 1', 'line 2']) |
|
83 |
||
84 |
self.assertEqual(k.annotate(0), |
|
85 |
[(0, 'line 1')]) |
|
86 |
||
87 |
self.assertEqual(k.annotate(1), |
|
88 |
[(0, 'line 1'), |
|
89 |
(1, 'line 2')]) |
|
90 |
||
91 |
||
92 |
class IncludeVersions(TestBase): |
|
93 |
"""Check texts that are stored across multiple revisions. |
|
94 |
||
95 |
Here we manually create a knit with particular encoding and make
|
|
96 |
sure it unpacks properly.
|
|
97 |
||
98 |
Text 0 includes nothing; text 1 includes text 0 and adds some
|
|
99 |
lines.
|
|
100 |
"""
|
|
101 |
||
102 |
def runTest(self): |
|
103 |
k = Knit() |
|
104 |
||
|
0.1.17
by Martin Pool
Use objects rather than tuples for tracking VerInfo for |
105 |
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 |
106 |
k._l = [(0, "first line"), |
107 |
(1, "second line")] |
|
108 |
||
109 |
self.assertEqual(k.get(1), |
|
110 |
["first line", |
|
111 |
"second line"]) |
|
112 |
||
113 |
self.assertEqual(k.get(0), |
|
114 |
["first line"]) |
|
115 |
||
116 |
k.dump(self.TEST_LOG) |
|
117 |
||
|
0.1.5
by Martin Pool
Add test for storing two text versions. |
118 |
|
|
0.1.14
by Martin Pool
Another test for version inclusion |
119 |
class DivergedIncludes(TestBase): |
120 |
"""Knit with two diverged texts based on version 0. |
|
121 |
"""
|
|
122 |
def runTest(self): |
|
123 |
k = Knit() |
|
124 |
||
|
0.1.17
by Martin Pool
Use objects rather than tuples for tracking VerInfo for |
125 |
k._v = [VerInfo(), |
126 |
VerInfo(included=[0]), |
|
127 |
VerInfo(included=[0]), |
|
128 |
]
|
|
|
0.1.14
by Martin Pool
Another test for version inclusion |
129 |
k._l = [(0, "first line"), |
130 |
(1, "second line"), |
|
131 |
(2, "alternative second line"),] |
|
132 |
||
133 |
self.assertEqual(k.get(0), |
|
134 |
["first line"]) |
|
135 |
||
136 |
self.assertEqual(k.get(1), |
|
137 |
["first line", |
|
138 |
"second line"]) |
|
139 |
||
140 |
self.assertEqual(k.get(2), |
|
141 |
["first line", |
|
142 |
"alternative second line"]) |
|
143 |
||
|
0.1.2
by Martin Pool
Import testsweet module adapted from bzr. |
144 |
def testknit(): |
145 |
import testsweet |
|
146 |
from unittest import TestSuite, TestLoader |
|
147 |
import testknit |
|
148 |
||
149 |
tl = TestLoader() |
|
150 |
suite = TestSuite() |
|
151 |
suite.addTest(tl.loadTestsFromModule(testknit)) |
|
152 |
||
|
0.1.15
by Martin Pool
Fix inverted shell return code for testknit |
153 |
return int(not testsweet.run_suite(suite)) # for shell 0=true |
|
0.1.2
by Martin Pool
Import testsweet module adapted from bzr. |
154 |
|
155 |
||
156 |
if __name__ == '__main__': |
|
157 |
import sys |
|
158 |
sys.exit(testknit()) |
|
159 |