/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.18.1 by John Arbash Meinel
Start working on an EquivalenceTable construct.
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
from bzrlib import tests
18
19
from bzrlib.plugins.groupcompress import equivalence_table
0.18.15 by John Arbash Meinel
Start writing tests directly for the compiled class
20
from bzrlib.plugins.groupcompress.tests.test__groupcompress_c import (
21
    CompiledGroupCompress
22
    )
0.18.13 by John Arbash Meinel
Copy the EquivalenceTable code into pyrex and get it under test.
23
0.18.1 by John Arbash Meinel
Start working on an EquivalenceTable construct.
24
25
class TestEquivalenceTable(tests.TestCase):
26
0.18.13 by John Arbash Meinel
Copy the EquivalenceTable code into pyrex and get it under test.
27
    eq_class = equivalence_table.EquivalenceTable
28
0.18.1 by John Arbash Meinel
Start working on an EquivalenceTable construct.
29
    def test_create(self):
0.18.13 by John Arbash Meinel
Copy the EquivalenceTable code into pyrex and get it under test.
30
        eq = self.eq_class(['a', 'b'])
0.18.1 by John Arbash Meinel
Start working on an EquivalenceTable construct.
31
32
    def test_matching_lines(self):
33
        lines = ['a', 'b', 'c', 'b']
0.18.13 by John Arbash Meinel
Copy the EquivalenceTable code into pyrex and get it under test.
34
        eq = self.eq_class(lines)
0.18.9 by John Arbash Meinel
If we are going to do it this way, we don't need to explicitly distinguish left and right
35
        self.assertEqual(lines, eq.lines)
0.18.8 by John Arbash Meinel
We don't actually care much about the right-line relationships. We only need to track the left-hand side.
36
        self.assertEqual({'a': [0], 'b': [1, 3], 'c': [2]},
0.18.12 by John Arbash Meinel
Switch away from probing hidden member variables
37
                         eq._get_matching_lines())
0.18.8 by John Arbash Meinel
We don't actually care much about the right-line relationships. We only need to track the left-hand side.
38
0.18.11 by John Arbash Meinel
Convert back into grabbing a right-lines ahead of time.
39
    def test_set_right_lines(self):
0.18.13 by John Arbash Meinel
Copy the EquivalenceTable code into pyrex and get it under test.
40
        eq = self.eq_class(['a', 'b', 'c', 'b'])
0.18.11 by John Arbash Meinel
Convert back into grabbing a right-lines ahead of time.
41
        eq.set_right_lines(['f', 'b', 'b'])
42
        self.assertEqual(None, eq.get_idx_matches(0))
43
        self.assertEqual([1, 3], eq.get_idx_matches(1))
44
        self.assertEqual([1, 3], eq.get_idx_matches(2))
45
0.18.8 by John Arbash Meinel
We don't actually care much about the right-line relationships. We only need to track the left-hand side.
46
    def assertGetLeftMatches(self, expected_left, eq, right):
0.18.2 by John Arbash Meinel
we can now extract what lines in left match the right
47
        """Assert that we find the right matching lines."""
0.18.9 by John Arbash Meinel
If we are going to do it this way, we don't need to explicitly distinguish left and right
48
        self.assertEqual(expected_left, eq.get_matches(right))
0.18.2 by John Arbash Meinel
we can now extract what lines in left match the right
49
50
    def test_get_matching(self):
0.18.13 by John Arbash Meinel
Copy the EquivalenceTable code into pyrex and get it under test.
51
        eq = self.eq_class(['a', 'b', 'c', 'b'])
0.18.8 by John Arbash Meinel
We don't actually care much about the right-line relationships. We only need to track the left-hand side.
52
        self.assertGetLeftMatches([1, 3], eq, 'b')
53
        self.assertGetLeftMatches([2], eq, 'c')
54
        self.assertGetLeftMatches(None, eq, 'd')
55
        self.assertGetLeftMatches([2], eq, 'c')
0.18.3 by John Arbash Meinel
We can now add more lines to left lines, and continue to track the right info.
56
0.18.9 by John Arbash Meinel
If we are going to do it this way, we don't need to explicitly distinguish left and right
57
    def test_extend_lines(self):
0.18.13 by John Arbash Meinel
Copy the EquivalenceTable code into pyrex and get it under test.
58
        eq = self.eq_class(['a', 'b', 'c', 'b'])
0.18.9 by John Arbash Meinel
If we are going to do it this way, we don't need to explicitly distinguish left and right
59
        eq.extend_lines(['d', 'e', 'c'], [True, True, True])
0.18.3 by John Arbash Meinel
We can now add more lines to left lines, and continue to track the right info.
60
        self.assertEqual(['a', 'b', 'c', 'b', 'd', 'e', 'c'],
0.18.9 by John Arbash Meinel
If we are going to do it this way, we don't need to explicitly distinguish left and right
61
                         eq.lines)
0.18.8 by John Arbash Meinel
We don't actually care much about the right-line relationships. We only need to track the left-hand side.
62
        self.assertEqual({'a': [0], 'b': [1, 3],
63
                          'c': [2, 6], 'd': [4],
64
                          'e': [5]},
0.18.12 by John Arbash Meinel
Switch away from probing hidden member variables
65
                         eq._get_matching_lines())
0.18.4 by John Arbash Meinel
Allow ignoring some of the new lines.
66
0.18.9 by John Arbash Meinel
If we are going to do it this way, we don't need to explicitly distinguish left and right
67
    def test_extend_lines_ignored(self):
0.18.13 by John Arbash Meinel
Copy the EquivalenceTable code into pyrex and get it under test.
68
        eq = self.eq_class(['a', 'b', 'c', 'b'])
0.18.9 by John Arbash Meinel
If we are going to do it this way, we don't need to explicitly distinguish left and right
69
        eq.extend_lines(['d', 'e', 'c'], [False, False, True])
0.18.4 by John Arbash Meinel
Allow ignoring some of the new lines.
70
        self.assertEqual(['a', 'b', 'c', 'b', 'd', 'e', 'c'],
0.18.9 by John Arbash Meinel
If we are going to do it this way, we don't need to explicitly distinguish left and right
71
                         eq.lines)
0.18.8 by John Arbash Meinel
We don't actually care much about the right-line relationships. We only need to track the left-hand side.
72
        self.assertEqual({'a': [0], 'b': [1, 3],
0.18.12 by John Arbash Meinel
Switch away from probing hidden member variables
73
                          'c': [2, 6], 'd': None, 'e': None},
74
                         eq._get_matching_lines())
0.18.5 by John Arbash Meinel
Add a test that just uses lots of the same lines,
75
76
    def test_abusive(self):
0.18.13 by John Arbash Meinel
Copy the EquivalenceTable code into pyrex and get it under test.
77
        eq = self.eq_class(['a']*1000)
0.18.12 by John Arbash Meinel
Switch away from probing hidden member variables
78
        self.assertEqual({'a': range(1000)}, eq._get_matching_lines())
0.18.8 by John Arbash Meinel
We don't actually care much about the right-line relationships. We only need to track the left-hand side.
79
        self.assertGetLeftMatches(range(1000), eq, 'a')
0.18.13 by John Arbash Meinel
Copy the EquivalenceTable code into pyrex and get it under test.
80
81
82
class TestCompiledEquivalenceTable(TestEquivalenceTable):
83
84
    _tests_need_features = [CompiledGroupCompress]
85
86
    def setUp(self):
87
        super(TestCompiledEquivalenceTable, self).setUp()
88
        from bzrlib.plugins.groupcompress import _groupcompress_c
89
        self.eq_class = _groupcompress_c.EquivalenceTable