1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
# Copyright (C) 2005 by Canonical Ltd
#
# Authors:
# Johan Rydberg <jrydberg@gnu.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# Remaing to do is to figure out if get_graph should return a simple
# map, or a graph object of some kind.
from bzrlib.tests import TestCaseInTempDir
from bzrlib.weave import Weave
from bzrlib.transactions import PassThroughTransaction
from bzrlib.trace import mutter
#from bzrlib.knit import KnitVersionedFile, \
# KnitAnnotateFactory
from bzrlib.transport.local import LocalTransport
from bzrlib.errors import RevisionNotPresent, \
RevisionAlreadyPresent
class VersionedFileTestMixIn(object):
"""A mixin test class for testing VersionedFiles.
This is not an adaptor-style test at this point because
theres no dynamic substitution of versioned file implementations,
they are strictly controlled by their owning repositories.
"""
def test_add(self):
t = PassThroughTransaction()
f = self.get_file()
f.add_lines('r0', [], ['a\n', 'b\n'])
f.add_lines('r1', ['r0'], ['b\n', 'c\n'])
versions = f.versions()
self.assertTrue('r0' in versions)
self.assertTrue('r1' in versions)
self.assertEquals(f.get_lines('r0'), ['a\n', 'b\n'])
self.assertEquals(f.get_text('r0'), 'a\nb\n')
self.assertEquals(f.get_lines('r1'), ['b\n', 'c\n'])
self.assertRaises(RevisionNotPresent,
f.add_lines, 'r2', ['foo'], [])
self.assertRaises(RevisionAlreadyPresent,
f.add_lines, 'r1', [], [])
def test_ancestry(self):
t = PassThroughTransaction()
f = self.get_file()
f.add_lines('r0', [], ['a\n', 'b\n'])
f.add_lines('r1', ['r0'], ['b\n', 'c\n'])
f.add_lines('r2', ['r0'], ['b\n', 'c\n'])
f.add_lines('r3', ['r2'], ['b\n', 'c\n'])
f.add_lines('rM', ['r1', 'r2'], ['b\n', 'c\n'])
versions = set(f.get_ancestry(['rM']))
self.assertEquals(versions, set(['rM', 'r2', 'r1', 'r0']))
self.assertRaises(RevisionNotPresent,
f.get_ancestry, ['rM', 'rX'])
def test_clone_text(self):
t = PassThroughTransaction()
f = self.get_file()
f.add_lines('r0', [], ['a\n', 'b\n'])
f.clone_text('r1', 'r0', ['r0'], t)
self.assertEquals(f.get_lines('r1'), f.get_lines('r0'))
self.assertEquals(f.get_lines('r1'), ['a\n', 'b\n'])
self.assertEquals(f.get_parents('r1'), ['r0'])
self.assertRaises(RevisionNotPresent,
f.clone_text, 'r2', 'rX', [], t)
self.assertRaises(RevisionAlreadyPresent,
f.clone_text, 'r1', 'r0', [], t)
def test_get_parents(self):
t = PassThroughTransaction()
f = self.get_file()
f.add_lines('r0', [], ['a\n', 'b\n'])
f.add_lines('r1', [], ['a\n', 'b\n'])
f.add_lines('r2', [], ['a\n', 'b\n'])
f.add_lines('r3', [], ['a\n', 'b\n'])
f.add_lines('m', ['r0', 'r1', 'r2', 'r3'], ['a\n', 'b\n'])
self.assertEquals(f.get_parents('m'), ['r0', 'r1', 'r2', 'r3'])
self.assertRaises(RevisionNotPresent,
f.get_parents, 'y')
def test_annotate(self):
t = PassThroughTransaction()
f = self.get_file()
f.add_lines('r0', [], ['a\n', 'b\n'])
f.add_lines('r1', ['r0'], ['c\n', 'b\n'])
origins = f.annotate('r1')
self.assertEquals(origins[0][0], 'r1')
self.assertEquals(origins[1][0], 'r0')
self.assertRaises(RevisionNotPresent,
f.annotate, 'foo')
def test_join(self):
t = PassThroughTransaction()
f1 = self.get_file('1')
f1.add_lines('r0', [], ['a\n', 'b\n'])
f1.add_lines('r1', ['r0'], ['c\n', 'b\n'])
f2 = self.get_file('2')
f2.join(f1, None, t)
self.assertTrue(f2.has_version('r0'))
self.assertTrue(f2.has_version('r1'))
self.assertRaises(RevisionNotPresent,
f2.join, f1, version_ids=['r3'])
#f3 = self.get_file('1')
#f3.add_lines('r0', ['a\n', 'b\n'], [], t)
#f3.add_lines('r1', ['c\n', 'b\n'], ['r0'], t)
#f4 = self.get_file('2')
#f4.join(f3, ['r0'], t)
#self.assertTrue(f4.has_version('r0'))
#self.assertFalse(f4.has_version('r1'))
def test_walk(self):
t = PassThroughTransaction()
f = self.get_file('1')
f.add_lines('r0', [], ['a\n', 'b\n'])
f.add_lines('r1', ['r0'], ['c\n', 'b\n'])
f.add_lines('rX', ['r1'], ['d\n', 'b\n'])
f.add_lines('rY', ['r1'], ['c\n', 'e\n'])
lines = {}
for lineno, insert, dset, text in f.walk(['rX', 'rY']):
lines[text] = (insert, dset)
self.assertTrue(lines['a\n'], ('r0', set(['r1'])))
self.assertTrue(lines['b\n'], ('r0', set(['rY'])))
self.assertTrue(lines['c\n'], ('r1', set(['rX'])))
self.assertTrue(lines['d\n'], ('rX', set([])))
self.assertTrue(lines['e\n'], ('rY', set([])))
class TestWeave(TestCaseInTempDir, VersionedFileTestMixIn):
def get_file(self, name='foo'):
return Weave(name)
#class TestKnit(TestCaseInTempDir, VersionedFileTestMixIn):
# def get_file(self, name='foo'):
# t = PassThroughTransaction()
# return KnitVersionedFile(LocalTransport('.'),
# name, 'w', KnitAnnotateFactory(), t, delta=True)
#
# def test_clone_text(self):
# pass
#
# def test_walk(self):
# pass
|