/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.18.15 by John Arbash Meinel
Start writing tests directly for the compiled class
1
# Copyright (C) 2008 Canonical Limited.
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 version 2 as published
5
# by the Free Software Foundation.
6
# 
7
# This program is distributed in the hope that it will be useful,
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
# GNU General Public License for more details.
11
# 
12
# You should have received a copy of the GNU General Public License
13
# along with this program; if not, write to the Free Software
14
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
15
# 
16
17
"""Tests for the pyrex extension of groupcompress"""
18
19
from bzrlib import tests
20
0.23.6 by John Arbash Meinel
Start stripping out the actual GroupCompressor
21
from bzrlib.plugins.groupcompress_rabin import groupcompress
0.18.26 by John Arbash Meinel
Start with a copy implementation of the _get_longest_match function.
22
0.18.15 by John Arbash Meinel
Start writing tests directly for the compiled class
23
24
class _CompiledGroupCompress(tests.Feature):
25
26
    def _probe(self):
27
        try:
0.23.6 by John Arbash Meinel
Start stripping out the actual GroupCompressor
28
            import bzrlib.plugins.groupcompress_rabin._groupcompress_c
0.18.15 by John Arbash Meinel
Start writing tests directly for the compiled class
29
        except ImportError:
30
            return False
31
        else:
32
            return True
33
34
    def feature_name(self):
0.23.6 by John Arbash Meinel
Start stripping out the actual GroupCompressor
35
        return 'bzrlib.plugins.groupcompress_rabin._groupcompress_c'
0.18.15 by John Arbash Meinel
Start writing tests directly for the compiled class
36
37
CompiledGroupCompress = _CompiledGroupCompress()
38
0.23.6 by John Arbash Meinel
Start stripping out the actual GroupCompressor
39
_source_text1 = """\
40
This is a bit
41
of source text
42
which is meant to be matched
43
against other text
44
"""
45
46
_source_text2 = """\
47
This is a bit
48
of source text
49
which is meant to differ from
50
against other text
51
"""
52
53
54
class Test_GroupCompress(tests.TestCase):
55
    """Direct tests for the compiled extension."""
0.18.31 by John Arbash Meinel
We had a small bug when we had to rebuild the hash, as we would forget about the non-indexed entries.
56
0.18.15 by John Arbash Meinel
Start writing tests directly for the compiled class
57
    def setUp(self):
0.23.6 by John Arbash Meinel
Start stripping out the actual GroupCompressor
58
        super(Test_GroupCompress, self).setUp()
59
        self.requireFeature(CompiledGroupCompress)
60
        from bzrlib.plugins.groupcompress_rabin import _groupcompress_c
0.18.15 by John Arbash Meinel
Start writing tests directly for the compiled class
61
        self._gc_module = _groupcompress_c
0.23.6 by John Arbash Meinel
Start stripping out the actual GroupCompressor
62
        self.make_delta = _groupcompress_c.make_delta
63
        self.apply_delta = _groupcompress_c.apply_delta
64
65
    def test_make_delta_is_typesafe(self):
66
        self.make_delta('a string', 'another string')
67
        self.assertRaises(TypeError,
68
            self.make_delta, 'a string', object())
69
        self.assertRaises(TypeError,
70
            self.make_delta, 'a string', u'not a string')
71
        self.assertRaises(TypeError,
72
            self.make_delta, object(), 'a string')
73
        self.assertRaises(TypeError,
74
            self.make_delta, u'not a string', 'a string')
75
76
    def test_make_noop_delta(self):
77
        ident_delta = self.make_delta(_source_text1, _source_text1)
78
        self.assertEqual('MM\x90M', ident_delta)
79
        ident_delta = self.make_delta(_source_text2, _source_text2)
80
        self.assertEqual('NN\x90N', ident_delta)
81
82
    def test_make_delta(self):
83
        delta = self.make_delta(_source_text1, _source_text2)
84
        self.assertEqual('MN\x90/\x1fdiffer from\nagainst other text\n', delta)
85
        delta = self.make_delta(_source_text2, _source_text1)
86
        self.assertEqual('NM\x90/\x1ebe matched\nagainst other text\n', delta)
87
88
    def test_apply_delta_is_typesafe(self):
89
        self.apply_delta(_source_text1, 'MM\x90M')
90
        self.assertRaises(TypeError,
91
            self.apply_delta, object(), 'MM\x90M')
92
        self.assertRaises(TypeError,
93
            self.apply_delta, unicode(_source_text1), 'MM\x90M')
94
        self.assertRaises(TypeError,
95
            self.apply_delta, _source_text1, u'MM\x90M')
96
        self.assertRaises(TypeError,
97
            self.apply_delta, _source_text1, object())
98
99
    def test_apply_delta(self):
100
        target = self.apply_delta(_source_text1,
101
                    'MN\x90/\x1fdiffer from\nagainst other text\n')
102
        self.assertEqual(_source_text2, target)
103
        target = self.apply_delta(_source_text2,
104
                    'NM\x90/\x1ebe matched\nagainst other text\n')
105
        self.assertEqual(_source_text1, target)