~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to tests/test__groupcompress_c.py

  • Committer: John Arbash Meinel
  • Date: 2009-02-27 18:43:07 UTC
  • mto: (0.23.23 groupcompress_rabin)
  • mto: This revision was merged to the branch mainline in revision 4280.
  • Revision ID: john@arbash-meinel.com-20090227184307-h8zgtnf217omdw1h
Add another test text.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 
37
37
CompiledGroupCompress = _CompiledGroupCompress()
38
38
 
39
 
_source_text1 = """\
 
39
_text1 = """\
40
40
This is a bit
41
41
of source text
42
42
which is meant to be matched
43
43
against other text
44
44
"""
45
45
 
46
 
_source_text2 = """\
 
46
_text2 = """\
47
47
This is a bit
48
48
of source text
49
49
which is meant to differ from
50
50
against other text
51
51
"""
52
52
 
 
53
_text3 = """\
 
54
This is a bit
 
55
of source text
 
56
which is meant to be matched
 
57
against other text
 
58
except it also
 
59
has a lot more data
 
60
at the end of the file
 
61
"""
 
62
 
53
63
 
54
64
class Test_GroupCompress(tests.TestCase):
55
65
    """Direct tests for the compiled extension."""
74
84
            self.make_delta, u'not a string', 'a string')
75
85
 
76
86
    def test_make_noop_delta(self):
77
 
        ident_delta = self.make_delta(_source_text1, _source_text1)
 
87
        ident_delta = self.make_delta(_text1, _text1)
78
88
        self.assertEqual('MM\x90M', ident_delta)
79
 
        ident_delta = self.make_delta(_source_text2, _source_text2)
 
89
        ident_delta = self.make_delta(_text2, _text2)
80
90
        self.assertEqual('NN\x90N', ident_delta)
 
91
        ident_delta = self.make_delta(_text3, _text3)
 
92
        self.assertEqual('\x87\x01\x87\x01\x90\x87', ident_delta)
81
93
 
82
94
    def test_make_delta(self):
83
 
        delta = self.make_delta(_source_text1, _source_text2)
 
95
        delta = self.make_delta(_text1, _text2)
84
96
        self.assertEqual('MN\x90/\x1fdiffer from\nagainst other text\n', delta)
85
 
        delta = self.make_delta(_source_text2, _source_text1)
 
97
        delta = self.make_delta(_text2, _text1)
86
98
        self.assertEqual('NM\x90/\x1ebe matched\nagainst other text\n', delta)
 
99
        delta = self.make_delta(_text3, _text1)
 
100
        self.assertEqual('\x87\x01M\x90M', delta)
 
101
        delta = self.make_delta(_text3, _text2)
 
102
        self.assertEqual('\x87\x01N\x90/\x1fdiffer from\nagainst other text\n',
 
103
                         delta)
87
104
 
88
105
    def test_apply_delta_is_typesafe(self):
89
 
        self.apply_delta(_source_text1, 'MM\x90M')
 
106
        self.apply_delta(_text1, 'MM\x90M')
90
107
        self.assertRaises(TypeError,
91
108
            self.apply_delta, object(), 'MM\x90M')
92
109
        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())
 
110
            self.apply_delta, unicode(_text1), 'MM\x90M')
 
111
        self.assertRaises(TypeError,
 
112
            self.apply_delta, _text1, u'MM\x90M')
 
113
        self.assertRaises(TypeError,
 
114
            self.apply_delta, _text1, object())
98
115
 
99
116
    def test_apply_delta(self):
100
 
        target = self.apply_delta(_source_text1,
 
117
        target = self.apply_delta(_text1,
101
118
                    'MN\x90/\x1fdiffer from\nagainst other text\n')
102
 
        self.assertEqual(_source_text2, target)
103
 
        target = self.apply_delta(_source_text2,
 
119
        self.assertEqual(_text2, target)
 
120
        target = self.apply_delta(_text2,
104
121
                    'NM\x90/\x1ebe matched\nagainst other text\n')
105
 
        self.assertEqual(_source_text1, target)
 
122
        self.assertEqual(_text1, target)