~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test__bencode.py

  • Committer: John Arbash Meinel
  • Date: 2009-12-23 04:19:34 UTC
  • mto: This revision was merged to the branch mainline in revision 4922.
  • Revision ID: john@arbash-meinel.com-20091223041934-zbixrn1cg015bqq4
Rename test_bencode to test__bencode, and use self.module

This makes it more similar to the rest of the extension permutation tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
 
1
# Copyright (C) 2007, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
26
26
 
27
27
class TestBencodeDecode(tests.TestCase):
28
28
 
29
 
    bencode = None
 
29
    module = None
30
30
 
31
31
    def _check(self, expected, source):
32
 
        self.assertEquals(expected, self.bencode.bdecode(source))
 
32
        self.assertEquals(expected, self.module.bdecode(source))
33
33
 
34
34
    def _run_check_error(self, exc, bad):
35
35
        """Check that bdecoding a string raises a particular exception."""
36
 
        self.assertRaises(exc, self.bencode.bdecode, bad)
 
36
        self.assertRaises(exc, self.module.bdecode, bad)
37
37
 
38
38
    def test_int(self):
39
39
        self._check(0, 'i0e')
64
64
        self._check('1234567890', '10:1234567890')
65
65
 
66
66
    def test_large_string(self):
67
 
        self.assertRaises(ValueError, self.bencode.bdecode, "2147483639:foo")
 
67
        self.assertRaises(ValueError, self.module.bdecode, "2147483639:foo")
68
68
 
69
69
    def test_malformed_string(self):
70
70
        self._run_check_error(ValueError, '10:x')
119
119
        self._run_check_error(ValueError, 'd432432432432432432:e')
120
120
 
121
121
    def test_empty_string(self):
122
 
        self.assertRaises(ValueError, self.bencode.bdecode, '')
 
122
        self.assertRaises(ValueError, self.module.bdecode, '')
123
123
 
124
124
    def test_junk(self):
125
125
        self._run_check_error(ValueError, 'i6easd')
128
128
        self._run_check_error(ValueError, 'leanfdldjfh')
129
129
 
130
130
    def test_unknown_object(self):
131
 
        self.assertRaises(ValueError, self.bencode.bdecode, 'relwjhrlewjh')
 
131
        self.assertRaises(ValueError, self.module.bdecode, 'relwjhrlewjh')
132
132
 
133
133
    def test_unsupported_type(self):
134
134
        self._run_check_error(TypeError, float(1.5))
138
138
        self._run_check_error(TypeError, u"ie")
139
139
 
140
140
    def test_decoder_type_error(self):
141
 
        self.assertRaises(TypeError, self.bencode.bdecode, 1)
 
141
        self.assertRaises(TypeError, self.module.bdecode, 1)
142
142
 
143
143
 
144
144
class TestBencodeEncode(tests.TestCase):
145
145
 
146
 
    bencode = None
 
146
    module = None
147
147
 
148
148
    def _check(self, expected, source):
149
 
        self.assertEquals(expected, self.bencode.bencode(source))
 
149
        self.assertEquals(expected, self.module.bencode(source))
150
150
 
151
151
    def test_int(self):
152
152
        self._check('i4e', 4)
178
178
        for i in range(10000):
179
179
            l.append([])
180
180
            l = l[0]
181
 
        self.assertRaises(RuntimeError, self.bencode.bencode, 
 
181
        self.assertRaises(RuntimeError, self.module.bencode, 
182
182
            top)
183
183
 
184
184
    def test_dict(self):
193
193
        for i in range(10000):
194
194
            d[''] = {}
195
195
            d = d['']
196
 
        self.assertRaises(RuntimeError, self.bencode.bencode, 
 
196
        self.assertRaises(RuntimeError, self.module.bencode, 
197
197
            top)
198
198
 
199
199
    def test_bencached(self):
200
 
        self._check('i3e', self.bencode.Bencached(self.bencode.bencode(3)))
 
200
        self._check('i3e', self.module.Bencached(self.module.bencode(3)))
201
201
 
202
202
    def test_invalid_dict(self):
203
 
        self.assertRaises(TypeError, self.bencode.bencode, {1:"foo"})
 
203
        self.assertRaises(TypeError, self.module.bencode, {1:"foo"})
204
204
 
205
205
    def test_bool(self):
206
206
        self._check('i1e', True)