/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.26 by Martin Pool
Refactor parameters to add command
100
class InsertLines(TestBase):
0.1.13 by Martin Pool
Knit structure now allows for versions to include the lines present in other
101
    """Store a revision that adds one line to the original.
102
103
    Look at the annotations to make sure that the first line is matched
104
    and not stored repeatedly."""
105
    def runTest(self):
106
        k = Knit()
107
0.1.26 by Martin Pool
Refactor parameters to add command
108
        k.add([], ['line 1'])
109
        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
110
111
        self.assertEqual(k.annotate(0),
112
                         [(0, 'line 1')])
113
0.1.25 by Martin Pool
Handle insertion of new weave layers that insert text on top of the basis
114
        self.assertEqual(k.get(1),
115
                         ['line 1',
116
                          'line 2'])
117
0.1.13 by Martin Pool
Knit structure now allows for versions to include the lines present in other
118
        self.assertEqual(k.annotate(1),
119
                         [(0, 'line 1'),
120
                          (1, 'line 2')])
121
122
0.1.26 by Martin Pool
Refactor parameters to add command
123
0.1.13 by Martin Pool
Knit structure now allows for versions to include the lines present in other
124
class IncludeVersions(TestBase):
125
    """Check texts that are stored across multiple revisions.
126
127
    Here we manually create a knit with particular encoding and make
128
    sure it unpacks properly.
129
130
    Text 0 includes nothing; text 1 includes text 0 and adds some
131
    lines.
132
    """
133
134
    def runTest(self):
135
        k = Knit()
136
0.1.17 by Martin Pool
Use objects rather than tuples for tracking VerInfo for
137
        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
138
        k._l = [(0, "first line"),
139
                (1, "second line")]
140
141
        self.assertEqual(k.get(1),
142
                         ["first line",
143
                          "second line"])
144
145
        self.assertEqual(k.get(0),
146
                         ["first line"])
147
148
        k.dump(self.TEST_LOG)
149
0.1.5 by Martin Pool
Add test for storing two text versions.
150
0.1.14 by Martin Pool
Another test for version inclusion
151
class DivergedIncludes(TestBase):
152
    """Knit with two diverged texts based on version 0.
153
    """
154
    def runTest(self):
155
        k = Knit()
156
0.1.17 by Martin Pool
Use objects rather than tuples for tracking VerInfo for
157
        k._v = [VerInfo(),
158
                VerInfo(included=[0]),
159
                VerInfo(included=[0]),
160
                ]
0.1.14 by Martin Pool
Another test for version inclusion
161
        k._l = [(0, "first line"),
162
                (1, "second line"),
163
                (2, "alternative second line"),]
164
165
        self.assertEqual(k.get(0),
166
                         ["first line"])
167
168
        self.assertEqual(k.get(1),
169
                         ["first line",
170
                          "second line"])
171
172
        self.assertEqual(k.get(2),
173
                         ["first line",
174
                          "alternative second line"])
175
0.1.2 by Martin Pool
Import testsweet module adapted from bzr.
176
def testknit():
177
    import testsweet
178
    from unittest import TestSuite, TestLoader
179
    import testknit
180
181
    tl = TestLoader()
182
    suite = TestSuite()
183
    suite.addTest(tl.loadTestsFromModule(testknit))
184
    
0.1.15 by Martin Pool
Fix inverted shell return code for testknit
185
    return int(not testsweet.run_suite(suite)) # for shell 0=true
0.1.2 by Martin Pool
Import testsweet module adapted from bzr.
186
187
188
if __name__ == '__main__':
189
    import sys
190
    sys.exit(testknit())
191