bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
5374.2.2
by John Arbash Meinel
Create a multi-parent diff generator class. |
1 |
# Copyright (C) 2010 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
16 |
||
17 |
"""Tests for VersionedFile classes"""
|
|
18 |
||
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
19 |
from .. import ( |
|
5374.2.2
by John Arbash Meinel
Create a multi-parent diff generator class. |
20 |
errors, |
21 |
multiparent, |
|
22 |
tests, |
|
|
6670.4.1
by Jelmer Vernooij
Update imports. |
23 |
)
|
24 |
from ..bzr import ( |
|
25 |
groupcompress, |
|
|
5374.2.2
by John Arbash Meinel
Create a multi-parent diff generator class. |
26 |
versionedfile, |
27 |
)
|
|
28 |
||
29 |
||
30 |
class Test_MPDiffGenerator(tests.TestCaseWithMemoryTransport): |
|
31 |
# Should this be a per vf test?
|
|
32 |
||
33 |
def make_vf(self): |
|
34 |
t = self.get_transport('') |
|
35 |
factory = groupcompress.make_pack_factory(True, True, 1) |
|
36 |
return factory(t) |
|
37 |
||
38 |
def make_three_vf(self): |
|
39 |
vf = self.make_vf() |
|
|
6963.2.10
by Jelmer Vernooij
Fix a bunch of tests. |
40 |
vf.add_lines((b'one',), (), [b'first\n']) |
41 |
vf.add_lines((b'two',), [(b'one',)], [b'first\n', b'second\n']) |
|
42 |
vf.add_lines((b'three',), [(b'one',), (b'two',)], |
|
43 |
[b'first\n', b'second\n', b'third\n']) |
|
|
5374.2.2
by John Arbash Meinel
Create a multi-parent diff generator class. |
44 |
return vf |
45 |
||
46 |
def test_finds_parents(self): |
|
47 |
vf = self.make_three_vf() |
|
|
6963.2.10
by Jelmer Vernooij
Fix a bunch of tests. |
48 |
gen = versionedfile._MPDiffGenerator(vf, [(b'three',)]) |
|
5374.2.2
by John Arbash Meinel
Create a multi-parent diff generator class. |
49 |
needed_keys, refcount = gen._find_needed_keys() |
|
6963.2.10
by Jelmer Vernooij
Fix a bunch of tests. |
50 |
self.assertEqual(sorted([(b'one',), (b'two',), (b'three',)]), |
|
5374.2.2
by John Arbash Meinel
Create a multi-parent diff generator class. |
51 |
sorted(needed_keys)) |
|
6963.2.10
by Jelmer Vernooij
Fix a bunch of tests. |
52 |
self.assertEqual({(b'one',): 1, (b'two',): 1}, refcount) |
|
5374.2.2
by John Arbash Meinel
Create a multi-parent diff generator class. |
53 |
|
54 |
def test_ignores_ghost_parents(self): |
|
55 |
# If a parent is a ghost, it is just ignored
|
|
56 |
vf = self.make_vf() |
|
|
6963.2.10
by Jelmer Vernooij
Fix a bunch of tests. |
57 |
vf.add_lines((b'two',), [(b'one',)], [b'first\n', b'second\n']) |
58 |
gen = versionedfile._MPDiffGenerator(vf, [(b'two',)]) |
|
|
5374.2.2
by John Arbash Meinel
Create a multi-parent diff generator class. |
59 |
needed_keys, refcount = gen._find_needed_keys() |
|
6963.2.10
by Jelmer Vernooij
Fix a bunch of tests. |
60 |
self.assertEqual(sorted([(b'two',)]), sorted(needed_keys)) |
|
5374.2.2
by John Arbash Meinel
Create a multi-parent diff generator class. |
61 |
# It is returned, but we don't really care as we won't extract it
|
|
6963.2.10
by Jelmer Vernooij
Fix a bunch of tests. |
62 |
self.assertEqual({(b'one',): 1}, refcount) |
63 |
self.assertEqual([(b'one',)], sorted(gen.ghost_parents)) |
|
|
5374.2.5
by John Arbash Meinel
Rework things a bit so the logic can be shared. |
64 |
self.assertEqual([], sorted(gen.present_parents)) |
|
5374.2.2
by John Arbash Meinel
Create a multi-parent diff generator class. |
65 |
|
66 |
def test_raises_on_ghost_keys(self): |
|
67 |
# If the requested key is a ghost, then we have a problem
|
|
68 |
vf = self.make_vf() |
|
|
6963.2.10
by Jelmer Vernooij
Fix a bunch of tests. |
69 |
gen = versionedfile._MPDiffGenerator(vf, [(b'one',)]) |
|
5374.2.2
by John Arbash Meinel
Create a multi-parent diff generator class. |
70 |
self.assertRaises(errors.RevisionNotPresent, |
71 |
gen._find_needed_keys) |
|
72 |
||
73 |
def test_refcount_multiple_children(self): |
|
74 |
vf = self.make_three_vf() |
|
|
6963.2.10
by Jelmer Vernooij
Fix a bunch of tests. |
75 |
gen = versionedfile._MPDiffGenerator(vf, [(b'two',), (b'three',)]) |
|
5374.2.2
by John Arbash Meinel
Create a multi-parent diff generator class. |
76 |
needed_keys, refcount = gen._find_needed_keys() |
|
6963.2.10
by Jelmer Vernooij
Fix a bunch of tests. |
77 |
self.assertEqual(sorted([(b'one',), (b'two',), (b'three',)]), |
|
5374.2.2
by John Arbash Meinel
Create a multi-parent diff generator class. |
78 |
sorted(needed_keys)) |
|
6963.2.10
by Jelmer Vernooij
Fix a bunch of tests. |
79 |
self.assertEqual({(b'one',): 2, (b'two',): 1}, refcount) |
80 |
self.assertEqual([(b'one',)], sorted(gen.present_parents)) |
|
|
5374.2.2
by John Arbash Meinel
Create a multi-parent diff generator class. |
81 |
|
82 |
def test_process_contents(self): |
|
83 |
vf = self.make_three_vf() |
|
|
6963.2.10
by Jelmer Vernooij
Fix a bunch of tests. |
84 |
gen = versionedfile._MPDiffGenerator(vf, [(b'two',), (b'three',)]) |
|
5374.2.2
by John Arbash Meinel
Create a multi-parent diff generator class. |
85 |
gen._find_needed_keys() |
|
6963.2.10
by Jelmer Vernooij
Fix a bunch of tests. |
86 |
self.assertEqual({(b'two',): ((b'one',),), |
87 |
(b'three',): ((b'one',), (b'two',))}, |
|
|
5374.2.2
by John Arbash Meinel
Create a multi-parent diff generator class. |
88 |
gen.parent_map) |
|
6963.2.10
by Jelmer Vernooij
Fix a bunch of tests. |
89 |
self.assertEqual({(b'one',): 2, (b'two',): 1}, gen.refcounts) |
90 |
self.assertEqual(sorted([(b'one',), (b'two',), (b'three',)]), |
|
|
5374.2.2
by John Arbash Meinel
Create a multi-parent diff generator class. |
91 |
sorted(gen.needed_keys)) |
92 |
stream = vf.get_record_stream(gen.needed_keys, 'topological', True) |
|
|
6634.2.1
by Martin
Apply 2to3 next fixer and make compatible |
93 |
record = next(stream) |
|
6963.2.10
by Jelmer Vernooij
Fix a bunch of tests. |
94 |
self.assertEqual((b'one',), record.key) |
|
5374.2.2
by John Arbash Meinel
Create a multi-parent diff generator class. |
95 |
# one is not needed in the output, but it is needed by children. As
|
96 |
# such, it should end up in the various caches
|
|
|
5374.2.5
by John Arbash Meinel
Rework things a bit so the logic can be shared. |
97 |
gen._process_one_record(record.key, record.get_bytes_as('chunked')) |
|
5374.2.2
by John Arbash Meinel
Create a multi-parent diff generator class. |
98 |
# The chunks should be cached, the refcount untouched
|
|
6963.2.10
by Jelmer Vernooij
Fix a bunch of tests. |
99 |
self.assertEqual({(b'one',)}, set(gen.chunks)) |
100 |
self.assertEqual({(b'one',): 2, (b'two',): 1}, gen.refcounts) |
|
|
6656.1.1
by Martin
Apply 2to3 dict fixer and clean up resulting mess using view helpers |
101 |
self.assertEqual(set(), set(gen.diffs)) |
|
5374.2.2
by John Arbash Meinel
Create a multi-parent diff generator class. |
102 |
# Next we get 'two', which is something we output, but also needed for
|
103 |
# three
|
|
|
6634.2.1
by Martin
Apply 2to3 next fixer and make compatible |
104 |
record = next(stream) |
|
6963.2.10
by Jelmer Vernooij
Fix a bunch of tests. |
105 |
self.assertEqual((b'two',), record.key) |
|
5374.2.5
by John Arbash Meinel
Rework things a bit so the logic can be shared. |
106 |
gen._process_one_record(record.key, record.get_bytes_as('chunked')) |
|
5374.2.2
by John Arbash Meinel
Create a multi-parent diff generator class. |
107 |
# Both are now cached, and the diff for two has been extracted, and
|
108 |
# one's refcount has been updated. two has been removed from the
|
|
109 |
# parent_map
|
|
|
6963.2.10
by Jelmer Vernooij
Fix a bunch of tests. |
110 |
self.assertEqual({(b'one',), (b'two',)}, set(gen.chunks)) |
111 |
self.assertEqual({(b'one',): 1, (b'two',): 1}, gen.refcounts) |
|
112 |
self.assertEqual({(b'two',)}, set(gen.diffs)) |
|
113 |
self.assertEqual({(b'three',): ((b'one',), (b'two',))}, |
|
|
5374.2.2
by John Arbash Meinel
Create a multi-parent diff generator class. |
114 |
gen.parent_map) |
115 |
# Finally 'three', which allows us to remove all parents from the
|
|
116 |
# caches
|
|
|
6634.2.1
by Martin
Apply 2to3 next fixer and make compatible |
117 |
record = next(stream) |
|
6963.2.10
by Jelmer Vernooij
Fix a bunch of tests. |
118 |
self.assertEqual((b'three',), record.key) |
|
5374.2.5
by John Arbash Meinel
Rework things a bit so the logic can be shared. |
119 |
gen._process_one_record(record.key, record.get_bytes_as('chunked')) |
|
5374.2.2
by John Arbash Meinel
Create a multi-parent diff generator class. |
120 |
# Both are now cached, and the diff for two has been extracted, and
|
121 |
# one's refcount has been updated
|
|
|
6656.1.1
by Martin
Apply 2to3 dict fixer and clean up resulting mess using view helpers |
122 |
self.assertEqual(set(), set(gen.chunks)) |
|
5374.2.2
by John Arbash Meinel
Create a multi-parent diff generator class. |
123 |
self.assertEqual({}, gen.refcounts) |
|
6963.2.10
by Jelmer Vernooij
Fix a bunch of tests. |
124 |
self.assertEqual({(b'two',), (b'three',)}, set(gen.diffs)) |
|
5374.2.2
by John Arbash Meinel
Create a multi-parent diff generator class. |
125 |
|
126 |
def test_compute_diffs(self): |
|
127 |
vf = self.make_three_vf() |
|
128 |
# The content is in the order requested, even if it isn't topological
|
|
|
6963.2.10
by Jelmer Vernooij
Fix a bunch of tests. |
129 |
gen = versionedfile._MPDiffGenerator(vf, [(b'two',), (b'three',), |
130 |
(b'one',)]) |
|
|
5374.2.2
by John Arbash Meinel
Create a multi-parent diff generator class. |
131 |
diffs = gen.compute_diffs() |
132 |
expected_diffs = [ |
|
133 |
multiparent.MultiParent([multiparent.ParentText(0, 0, 0, 1), |
|
|
6963.2.10
by Jelmer Vernooij
Fix a bunch of tests. |
134 |
multiparent.NewText([b'second\n'])]), |
|
5374.2.2
by John Arbash Meinel
Create a multi-parent diff generator class. |
135 |
multiparent.MultiParent([multiparent.ParentText(1, 0, 0, 2), |
|
6963.2.10
by Jelmer Vernooij
Fix a bunch of tests. |
136 |
multiparent.NewText([b'third\n'])]), |
137 |
multiparent.MultiParent([multiparent.NewText([b'first\n'])]), |
|
|
5374.2.2
by John Arbash Meinel
Create a multi-parent diff generator class. |
138 |
]
|
139 |
self.assertEqual(expected_diffs, diffs) |