38
38
def test_knit_constructor(self):
39
39
"""Construct empty k"""
40
knit = KnitVersionedFile(LocalTransport('.'), 'test.knit', 'w', KnitPlainFactory())
42
def make_test_knit(self, annotate=False):
44
factory = KnitPlainFactory()
47
return KnitVersionedFile('test', LocalTransport('.'), access_mode='w', factory=factory)
42
49
def test_knit_add(self):
43
50
"""Store one text in knit and retrieve"""
44
k = KnitVersionedFile(LocalTransport('.'), 'test.knit', 'w', KnitPlainFactory())
51
k = self.make_test_knit()
45
52
k.add_lines('text-1', [], split_lines(TEXT_1))
46
53
self.assertTrue(k.has_version('text-1'))
47
54
self.assertEqualDiff(''.join(k.get_lines('text-1')), TEXT_1)
49
56
def test_knit_reload(self):
50
57
"""Store and reload a knit"""
51
k = KnitVersionedFile(LocalTransport('.'), 'test.knit', 'w', KnitPlainFactory())
58
k = self.make_test_knit()
52
59
k.add_lines('text-1', [], split_lines(TEXT_1))
54
k2 = KnitVersionedFile(LocalTransport('.'), 'test.knit', 'r', KnitPlainFactory())
61
k2 = KnitVersionedFile('test', LocalTransport('.'), access_mode='r', factory=KnitPlainFactory())
55
62
self.assertTrue(k2.has_version('text-1'))
56
63
self.assertEqualDiff(''.join(k2.get_lines('text-1')), TEXT_1)
58
65
def test_knit_several(self):
59
66
"""Store several texts in a knit"""
60
k = KnitVersionedFile(LocalTransport('.'), 'test.knit', 'w', KnitPlainFactory())
67
k = self.make_test_knit()
61
68
k.add_lines('text-1', [], split_lines(TEXT_1))
62
69
k.add_lines('text-2', [], split_lines(TEXT_2))
63
70
self.assertEqualDiff(''.join(k.get_lines('text-1')), TEXT_1)
66
73
def test_repeated_add(self):
67
74
"""Knit traps attempt to replace existing version"""
68
k = KnitVersionedFile(LocalTransport('.'), 'test.knit', 'w', KnitPlainFactory())
75
k = self.make_test_knit()
69
76
k.add_lines('text-1', [], split_lines(TEXT_1))
70
77
self.assertRaises(RevisionAlreadyPresent,
72
79
'text-1', [], split_lines(TEXT_1))
74
81
def test_empty(self):
75
k = KnitVersionedFile(LocalTransport('.'), 'test.knit', 'w', KnitAnnotateFactory())
82
k = self.make_test_knit(True)
76
83
k.add_lines('text-1', [], [])
77
84
self.assertEquals(k.get_lines('text-1'), [])
79
86
def test_incomplete(self):
80
87
"""Test if texts without a ending line-end can be inserted and
82
k = KnitVersionedFile(LocalTransport('.'), 'test.knit', 'w', KnitAnnotateFactory(),
89
k = KnitVersionedFile('test', LocalTransport('.'), delta=False)
84
90
k.add_lines('text-1', [], ['a\n', 'b' ])
85
91
k.add_lines('text-2', ['text-1'], ['a\rb\n', 'b\n'])
86
92
self.assertEquals(k.get_lines('text-1'), ['a\n', 'b' ])
89
95
def test_delta(self):
90
96
"""Expression of knit delta as lines"""
91
k = KnitVersionedFile(LocalTransport('.'), 'test.knit', 'w', KnitPlainFactory())
97
k = self.make_test_knit()
92
98
td = list(line_delta(TEXT_1.splitlines(True),
93
99
TEXT_1A.splitlines(True)))
94
100
self.assertEqualDiff(''.join(td), delta_1_1a)
98
104
def test_add_with_parents(self):
99
105
"""Store in knit with parents"""
100
k = KnitVersionedFile(LocalTransport('.'), 'test.knit', 'w', KnitPlainFactory())
106
k = self.make_test_knit()
101
107
self.add_stock_one_and_one_a(k)
102
108
self.assertEquals(k.get_parents('text-1'), [])
103
109
self.assertEquals(k.get_parents('text-1a'), ['text-1'])
105
111
def test_ancestry(self):
106
112
"""Store in knit with parents"""
107
k = KnitVersionedFile(LocalTransport('.'), 'test.knit', 'w', KnitPlainFactory())
113
k = self.make_test_knit()
108
114
self.add_stock_one_and_one_a(k)
109
115
self.assertEquals(set(k.get_ancestry(['text-1a'])), set(['text-1a', 'text-1']))
111
117
def test_add_delta(self):
112
118
"""Store in knit with parents"""
113
k = KnitVersionedFile(LocalTransport('.'), 'test.knit', 'w', KnitPlainFactory(),
119
k = KnitVersionedFile('test', LocalTransport('.'), factory=KnitPlainFactory(),
115
121
self.add_stock_one_and_one_a(k)
116
122
self.assertEqualDiff(''.join(k.get_lines('text-1a')), TEXT_1A)
118
124
def test_annotate(self):
119
125
"""Annotations"""
120
k = KnitVersionedFile(LocalTransport('.'), 'test.knit', 'w', KnitAnnotateFactory(),
126
k = KnitVersionedFile('knit', LocalTransport('.'), factory=KnitAnnotateFactory(),
122
128
self.insert_and_test_small_annotate(k)
133
139
def test_annotate_fulltext(self):
134
140
"""Annotations"""
135
k = KnitVersionedFile(LocalTransport('.'), 'test.knit', 'w', KnitAnnotateFactory(),
141
k = KnitVersionedFile('knit', LocalTransport('.'), factory=KnitAnnotateFactory(),
137
143
self.insert_and_test_small_annotate(k)
139
145
def test_annotate_merge_1(self):
140
k = KnitVersionedFile(LocalTransport('.'), 'test.knit', 'w', KnitAnnotateFactory())
146
k = self.make_test_knit(True)
141
147
k.add_lines('text-a1', [], ['a\n', 'b\n'])
142
148
k.add_lines('text-a2', [], ['d\n', 'c\n'])
143
149
k.add_lines('text-am', ['text-a1', 'text-a2'], ['d\n', 'b\n'])
146
152
self.assertEquals(origins[1], ('text-a1', 'b\n'))
148
154
def test_annotate_merge_2(self):
149
k = KnitVersionedFile(LocalTransport('.'), 'test.knit', 'w', KnitAnnotateFactory())
155
k = self.make_test_knit(True)
150
156
k.add_lines('text-a1', [], ['a\n', 'b\n', 'c\n'])
151
157
k.add_lines('text-a2', [], ['x\n', 'y\n', 'z\n'])
152
158
k.add_lines('text-am', ['text-a1', 'text-a2'], ['a\n', 'y\n', 'c\n'])
156
162
self.assertEquals(origins[2], ('text-a1', 'c\n'))
158
164
def test_annotate_merge_9(self):
159
k = KnitVersionedFile(LocalTransport('.'), 'test.knit', 'w', KnitAnnotateFactory())
165
k = self.make_test_knit(True)
160
166
k.add_lines('text-a1', [], ['a\n', 'b\n', 'c\n'])
161
167
k.add_lines('text-a2', [], ['x\n', 'y\n', 'z\n'])
162
168
k.add_lines('text-am', ['text-a1', 'text-a2'], ['k\n', 'y\n', 'c\n'])
166
172
self.assertEquals(origins[2], ('text-a1', 'c\n'))
168
174
def test_annotate_merge_3(self):
169
k = KnitVersionedFile(LocalTransport('.'), 'test.knit', 'w', KnitAnnotateFactory())
175
k = self.make_test_knit(True)
170
176
k.add_lines('text-a1', [], ['a\n', 'b\n', 'c\n'])
171
177
k.add_lines('text-a2', [] ,['x\n', 'y\n', 'z\n'])
172
178
k.add_lines('text-am', ['text-a1', 'text-a2'], ['k\n', 'y\n', 'z\n'])
176
182
self.assertEquals(origins[2], ('text-a2', 'z\n'))
178
184
def test_annotate_merge_4(self):
179
k = KnitVersionedFile(LocalTransport('.'), 'test.knit', 'w', KnitAnnotateFactory())
185
k = self.make_test_knit(True)
180
186
k.add_lines('text-a1', [], ['a\n', 'b\n', 'c\n'])
181
187
k.add_lines('text-a2', [], ['x\n', 'y\n', 'z\n'])
182
188
k.add_lines('text-a3', ['text-a1'], ['a\n', 'b\n', 'p\n'])
187
193
self.assertEquals(origins[2], ('text-a2', 'z\n'))
189
195
def test_annotate_merge_5(self):
190
k = KnitVersionedFile(LocalTransport('.'), 'test.knit', 'w', KnitAnnotateFactory())
196
k = self.make_test_knit(True)
191
197
k.add_lines('text-a1', [], ['a\n', 'b\n', 'c\n'])
192
198
k.add_lines('text-a2', [], ['d\n', 'e\n', 'f\n'])
193
199
k.add_lines('text-a3', [], ['x\n', 'y\n', 'z\n'])
200
206
self.assertEquals(origins[2], ('text-a3', 'z\n'))
202
208
def test_annotate_file_cherry_pick(self):
203
k = KnitVersionedFile(LocalTransport('.'), 'test.knit', 'w', KnitAnnotateFactory())
209
k = self.make_test_knit(True)
204
210
k.add_lines('text-1', [], ['a\n', 'b\n', 'c\n'])
205
211
k.add_lines('text-2', ['text-1'], ['d\n', 'e\n', 'f\n'])
206
212
k.add_lines('text-3', ['text-2', 'text-1'], ['a\n', 'b\n', 'c\n'])
212
218
def test_knit_join(self):
213
219
"""Store in knit with parents"""
214
k1 = KnitVersionedFile(LocalTransport('.'), 'test1.knit', 'w', KnitPlainFactory())
220
k1 = KnitVersionedFile('test1', LocalTransport('.'), factory=KnitPlainFactory())
215
221
k1.add_lines('text-a', [], split_lines(TEXT_1))
216
222
k1.add_lines('text-b', ['text-a'], split_lines(TEXT_1))
221
227
k1.add_lines('text-m', ['text-b', 'text-d'], split_lines(TEXT_1))
223
k2 = KnitVersionedFile(LocalTransport('.'), 'test2.knit', 'w', KnitPlainFactory())
229
k2 = KnitVersionedFile('test2', LocalTransport('.'), factory=KnitPlainFactory())
224
230
count = k2.join(k1, version_ids=['text-m'])
225
231
self.assertEquals(count, 5)
226
232
self.assertTrue(k2.has_version('text-a'))
227
233
self.assertTrue(k2.has_version('text-c'))
229
235
def test_reannotate(self):
230
k1 = KnitVersionedFile(LocalTransport('.'), 'test1', 'w',
231
KnitAnnotateFactory())
236
k1 = KnitVersionedFile('knit1', LocalTransport('.'),
237
factory=KnitAnnotateFactory())
233
239
k1.add_lines('text-a', [], ['a\n', 'b\n'])
235
241
k1.add_lines('text-b', ['text-a'], ['a\n', 'c\n'])
237
k2 = KnitVersionedFile(LocalTransport('.'), 'test2', 'w',
238
KnitAnnotateFactory())
243
k2 = KnitVersionedFile('test2', LocalTransport('.'),
244
factory=KnitAnnotateFactory())
239
245
k2.join(k1, version_ids=['text-b'])
256
262
self.assertEquals(origins[1], ('text-b', 'c\n'))
258
264
def test_create_empty_annotated(self):
259
k1 = KnitVersionedFile(LocalTransport('.'), 'test1', 'w',
260
KnitAnnotateFactory())
265
k1 = self.make_test_knit(True)
262
267
k1.add_lines('text-a', [], ['a\n', 'b\n'])
263
268
k2 = k1.create_empty('t', MemoryTransport())