bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.17.1
by Robert Collins
Starting point. Interface tests hooked up and failing. |
1 |
# groupcompress, a bzr plugin providing new compression logic.
|
2 |
# Copyright (C) 2008 Canonical Limited.
|
|
3 |
#
|
|
4 |
# This program is free software; you can redistribute it and/or modify
|
|
5 |
# it under the terms of the GNU General Public License version 2 as published
|
|
6 |
# by the Free Software Foundation.
|
|
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 St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
16 |
#
|
|
17 |
||
18 |
"""Tests for group compression."""
|
|
19 |
||
20 |
import zlib |
|
21 |
||
22 |
from bzrlib import tests |
|
|
0.17.2
by Robert Collins
Core proof of concept working. |
23 |
from bzrlib.osutils import sha_strings |
|
0.17.1
by Robert Collins
Starting point. Interface tests hooked up and failing. |
24 |
from bzrlib.plugins.groupcompress import errors, groupcompress |
25 |
from bzrlib.tests import ( |
|
26 |
TestCaseWithTransport, |
|
27 |
TestScenarioApplier, |
|
28 |
adapt_tests, |
|
29 |
)
|
|
30 |
from bzrlib.transport import get_transport |
|
31 |
||
32 |
||
33 |
def load_tests(standard_tests, module, loader): |
|
34 |
from bzrlib.tests.test_versionedfile import TestVersionedFiles |
|
35 |
vf_interface_tests = loader.loadTestsFromTestCase(TestVersionedFiles) |
|
36 |
cleanup_pack_group = groupcompress.cleanup_pack_group |
|
37 |
make_pack_factory = groupcompress.make_pack_factory |
|
38 |
group_scenario = ('groupcompress-nograph', { |
|
39 |
'cleanup':cleanup_pack_group, |
|
40 |
'factory':make_pack_factory(False, False, 1), |
|
41 |
'graph': False, |
|
42 |
'key_length':1, |
|
|
0.20.21
by John Arbash Meinel
Merge the chk sorting code. |
43 |
'support_partial_insertion':False, |
|
0.17.1
by Robert Collins
Starting point. Interface tests hooked up and failing. |
44 |
}
|
45 |
)
|
|
46 |
applier = TestScenarioApplier() |
|
47 |
applier.scenarios = [group_scenario] |
|
48 |
adapt_tests(vf_interface_tests, applier, standard_tests) |
|
49 |
return standard_tests |
|
50 |
||
51 |
||
|
0.17.2
by Robert Collins
Core proof of concept working. |
52 |
class TestGroupCompressor(TestCaseWithTransport): |
53 |
"""Tests for GroupCompressor""" |
|
54 |
||
55 |
def test_empty_delta(self): |
|
56 |
compressor = groupcompress.GroupCompressor(True) |
|
57 |
self.assertEqual([], compressor.lines) |
|
58 |
||
59 |
def test_one_nosha_delta(self): |
|
60 |
# diff against NUKK
|
|
61 |
compressor = groupcompress.GroupCompressor(True) |
|
62 |
sha1, end_point = compressor.compress(('label',), |
|
63 |
['strange\n', 'common\n'], None) |
|
64 |
self.assertEqual(sha_strings(['strange\n', 'common\n']), sha1) |
|
65 |
expected_lines = [ |
|
66 |
'label: label\n', |
|
67 |
'sha1: %s\n' % sha1, |
|
|
0.17.3
by Robert Collins
new encoder, allows non monotonically increasing sequence matches for moar compression. |
68 |
'i,3\n', |
|
0.17.2
by Robert Collins
Core proof of concept working. |
69 |
'strange\n', |
70 |
'common\n', |
|
71 |
'\n', # the last \n in a text is removed, which allows safe |
|
72 |
# serialisation of lines without trailing \n.
|
|
73 |
]
|
|
74 |
self.assertEqual(expected_lines, compressor.lines) |
|
75 |
self.assertEqual(sum(map(len, expected_lines)), end_point) |
|
76 |
||
77 |
def test_two_nosha_delta(self): |
|
78 |
compressor = groupcompress.GroupCompressor(True) |
|
79 |
sha1_1, _ = compressor.compress(('label',), |
|
|
0.20.17
by John Arbash Meinel
Fix the test suite now that we don't match short lines |
80 |
['strange\n', 'common long line\n'], None) |
|
0.17.3
by Robert Collins
new encoder, allows non monotonically increasing sequence matches for moar compression. |
81 |
expected_lines = list(compressor.lines) |
|
0.17.2
by Robert Collins
Core proof of concept working. |
82 |
sha1_2, end_point = compressor.compress(('newlabel',), |
|
0.20.17
by John Arbash Meinel
Fix the test suite now that we don't match short lines |
83 |
['common long line\n', 'different\n'], None) |
84 |
self.assertEqual(sha_strings(['common long line\n', 'different\n']), |
|
85 |
sha1_2) |
|
|
0.17.3
by Robert Collins
new encoder, allows non monotonically increasing sequence matches for moar compression. |
86 |
expected_lines.extend([ |
|
0.17.2
by Robert Collins
Core proof of concept working. |
87 |
'label: newlabel\n', |
88 |
'sha1: %s\n' % sha1_2, |
|
|
0.17.3
by Robert Collins
new encoder, allows non monotonically increasing sequence matches for moar compression. |
89 |
# copy the line common
|
|
0.20.17
by John Arbash Meinel
Fix the test suite now that we don't match short lines |
90 |
'c,72,17\n', |
91 |
# add the line different, and the trailing newline
|
|
92 |
'i,2\n', |
|
|
0.17.2
by Robert Collins
Core proof of concept working. |
93 |
'different\n', |
|
0.17.13
by Robert Collins
Do not output copy instructions which take more to encode than a fresh insert. (But do not refer to those insertions when finding ranges to copy: they are not interesting). |
94 |
'\n' |
|
0.17.3
by Robert Collins
new encoder, allows non monotonically increasing sequence matches for moar compression. |
95 |
])
|
|
0.20.17
by John Arbash Meinel
Fix the test suite now that we don't match short lines |
96 |
self.assertEqualDiff(''.join(expected_lines), ''.join(compressor.lines)) |
|
0.17.2
by Robert Collins
Core proof of concept working. |
97 |
self.assertEqual(sum(map(len, expected_lines)), end_point) |
98 |
||
99 |
def test_three_nosha_delta(self): |
|
100 |
# The first interesting test: make a change that should use lines from
|
|
101 |
# both parents.
|
|
102 |
compressor = groupcompress.GroupCompressor(True) |
|
103 |
sha1_1, end_point = compressor.compress(('label',), |
|
|
0.20.17
by John Arbash Meinel
Fix the test suite now that we don't match short lines |
104 |
['strange\n', 'common long line\n'], None) |
|
0.17.2
by Robert Collins
Core proof of concept working. |
105 |
sha1_2, _ = compressor.compress(('newlabel',), |
|
0.20.17
by John Arbash Meinel
Fix the test suite now that we don't match short lines |
106 |
['common long line\n', 'different\n', 'moredifferent\n'], None) |
|
0.17.3
by Robert Collins
new encoder, allows non monotonically increasing sequence matches for moar compression. |
107 |
expected_lines = list(compressor.lines) |
|
0.17.2
by Robert Collins
Core proof of concept working. |
108 |
sha1_3, end_point = compressor.compress(('label3',), |
|
0.20.17
by John Arbash Meinel
Fix the test suite now that we don't match short lines |
109 |
['new\n', 'common long line\n', 'different\n', 'moredifferent\n'], |
110 |
None) |
|
|
0.17.2
by Robert Collins
Core proof of concept working. |
111 |
self.assertEqual( |
|
0.20.17
by John Arbash Meinel
Fix the test suite now that we don't match short lines |
112 |
sha_strings(['new\n', 'common long line\n', 'different\n', |
113 |
'moredifferent\n']), |
|
|
0.17.2
by Robert Collins
Core proof of concept working. |
114 |
sha1_3) |
|
0.17.3
by Robert Collins
new encoder, allows non monotonically increasing sequence matches for moar compression. |
115 |
expected_lines.extend([ |
|
0.17.2
by Robert Collins
Core proof of concept working. |
116 |
'label: label3\n', |
117 |
'sha1: %s\n' % sha1_3, |
|
|
0.17.3
by Robert Collins
new encoder, allows non monotonically increasing sequence matches for moar compression. |
118 |
# insert new
|
119 |
'i,1\n', |
|
|
0.17.2
by Robert Collins
Core proof of concept working. |
120 |
'new\n', |
|
0.17.3
by Robert Collins
new encoder, allows non monotonically increasing sequence matches for moar compression. |
121 |
# copy the line common
|
|
0.20.17
by John Arbash Meinel
Fix the test suite now that we don't match short lines |
122 |
'c,72,17\n', |
123 |
# copy the lines different, moredifferent and trailing newline
|
|
124 |
'c,165,25\n', |
|
|
0.17.3
by Robert Collins
new encoder, allows non monotonically increasing sequence matches for moar compression. |
125 |
])
|
|
0.18.6
by John Arbash Meinel
Use the new EquivalenceTable to track the lines. |
126 |
self.assertEqualDiff(''.join(expected_lines), |
127 |
''.join(compressor.lines)) |
|
|
0.17.2
by Robert Collins
Core proof of concept working. |
128 |
self.assertEqual(sum(map(len, expected_lines)), end_point) |
129 |
||
130 |
def test_stats(self): |
|
131 |
compressor = groupcompress.GroupCompressor(True) |
|
132 |
compressor.compress(('label',), |
|
133 |
['strange\n', 'common\n'], None) |
|
134 |
compressor.compress(('newlabel',), |
|
135 |
['common\n', 'different\n', 'moredifferent\n'], None) |
|
136 |
compressor.compress(('label3',), |
|
137 |
['new\n', 'common\n', 'different\n', 'moredifferent\n'], None) |
|
138 |
self.assertAlmostEqual(0.3, compressor.ratio(), 1) |
|
|
0.17.11
by Robert Collins
Add extraction of just-compressed texts to support converting from knits. |
139 |
|
140 |
def test_extract_from_compressor(self): |
|
141 |
# Knit fetching will try to reconstruct texts locally which results in
|
|
142 |
# reading something that is in the compressor stream already.
|
|
143 |
compressor = groupcompress.GroupCompressor(True) |
|
144 |
sha_1, _ = compressor.compress(('label',), |
|
145 |
['strange\n', 'common\n'], None) |
|
146 |
sha_2, _ = compressor.compress(('newlabel',), |
|
147 |
['common\n', 'different\n', 'moredifferent\n'], None) |
|
148 |
# get the first out
|
|
149 |
self.assertEqual((['strange\n', 'common\n'], sha_1), |
|
150 |
compressor.extract(('label',))) |
|
151 |
# and the second
|
|
152 |
self.assertEqual((['common\n', 'different\n', 'moredifferent\n'], |
|
153 |
sha_2), compressor.extract(('newlabel',))) |