/brz/remove-bazaar

To get this branch, use:
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.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):
50
        k = Knit()
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):
58
        k = Knit()
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
78
        k = Knit()
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):
103
        k = Knit()
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):
117
        k = Knit()
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.13 by Martin Pool
Knit structure now allows for versions to include the lines present in other
147
0.1.26 by Martin Pool
Refactor parameters to add command
148
0.1.13 by Martin Pool
Knit structure now allows for versions to include the lines present in other
149
class IncludeVersions(TestBase):
150
    """Check texts that are stored across multiple revisions.
151
152
    Here we manually create a knit with particular encoding and make
153
    sure it unpacks properly.
154
155
    Text 0 includes nothing; text 1 includes text 0 and adds some
156
    lines.
157
    """
158
159
    def runTest(self):
160
        k = Knit()
161
0.1.17 by Martin Pool
Use objects rather than tuples for tracking VerInfo for
162
        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
163
        k._l = [(0, "first line"),
164
                (1, "second line")]
165
166
        self.assertEqual(k.get(1),
167
                         ["first line",
168
                          "second line"])
169
170
        self.assertEqual(k.get(0),
171
                         ["first line"])
172
173
        k.dump(self.TEST_LOG)
174
0.1.5 by Martin Pool
Add test for storing two text versions.
175
0.1.14 by Martin Pool
Another test for version inclusion
176
class DivergedIncludes(TestBase):
177
    """Knit with two diverged texts based on version 0.
178
    """
179
    def runTest(self):
180
        k = Knit()
181
0.1.17 by Martin Pool
Use objects rather than tuples for tracking VerInfo for
182
        k._v = [VerInfo(),
183
                VerInfo(included=[0]),
184
                VerInfo(included=[0]),
185
                ]
0.1.14 by Martin Pool
Another test for version inclusion
186
        k._l = [(0, "first line"),
187
                (1, "second line"),
188
                (2, "alternative second line"),]
189
190
        self.assertEqual(k.get(0),
191
                         ["first line"])
192
193
        self.assertEqual(k.get(1),
194
                         ["first line",
195
                          "second line"])
196
197
        self.assertEqual(k.get(2),
198
                         ["first line",
199
                          "alternative second line"])
200
0.1.2 by Martin Pool
Import testsweet module adapted from bzr.
201
def testknit():
202
    import testsweet
203
    from unittest import TestSuite, TestLoader
204
    import testknit
205
206
    tl = TestLoader()
207
    suite = TestSuite()
208
    suite.addTest(tl.loadTestsFromModule(testknit))
209
    
0.1.15 by Martin Pool
Fix inverted shell return code for testknit
210
    return int(not testsweet.run_suite(suite)) # for shell 0=true
0.1.2 by Martin Pool
Import testsweet module adapted from bzr.
211
212
213
if __name__ == '__main__':
214
    import sys
215
    sys.exit(testknit())
216