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