~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/util/tests/test_bencode.py

  • Committer: Ian Clatworthy
  • Date: 2009-02-09 23:33:58 UTC
  • mfrom: (3955.3.10 open-in-launchpad)
  • mto: This revision was merged to the branch mainline in revision 3992.
  • Revision ID: ian.clatworthy@canonical.com-20090209233358-87e0072zgnkomb6v
Command for opening Launchpad pages (Jonathan Lange)

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
# Software.
24
24
 
25
25
 
26
 
from bzrlib.util.bencode import bencode, bdecode, Bencached
 
26
from bzrlib.util.bencode import bencode, bdecode, bdecode_as_tuple, Bencached
27
27
from bzrlib.tests import TestCase
28
28
 
29
29
class TestBencode(TestCase):
189
189
        bdecode('d0:i3ee')
190
190
 
191
191
 
 
192
    def test_bdecode_as_tuple(self):
 
193
        assert bdecode_as_tuple('le') == ()
 
194
        try:
 
195
            bdecode_as_tuple('leanfdldjfh')
 
196
            assert 0
 
197
        except ValueError:
 
198
            pass
 
199
        assert bdecode_as_tuple('l0:0:0:e') == ('', '', '')
 
200
        assert bdecode_as_tuple('li1ei2ei3ee') == (1, 2, 3)
 
201
        assert bdecode_as_tuple('l3:asd2:xye') == ('asd', 'xy')
 
202
        assert bdecode_as_tuple('ll5:Alice3:Bobeli2ei3eee') == (('Alice', 'Bob'),
 
203
                (2, 3))
 
204
        try:
 
205
            bdecode_as_tuple('l-3:e')
 
206
            assert 0
 
207
        except ValueError:
 
208
            pass
 
209
 
 
210
 
192
211
    def test_bencode(self):
193
212
        assert bencode(4) == 'i4e'
194
213
        assert bencode(0) == 'i0e'
204
223
        assert bencode({'age': 25, 'eyes': 'blue'}) == 'd3:agei25e4:eyes4:bluee'
205
224
        assert bencode({'spam.mp3': {'author': 'Alice', 'length': 100000}}) == 'd8:spam.mp3d6:author5:Alice6:lengthi100000eee'
206
225
        assert bencode(Bencached(bencode(3))) == 'i3e'
 
226
        assert bencode(True) == 'i1e'
 
227
        assert bencode(False) == 'i0e'
207
228
        try:
208
229
            bencode({1: 'foo'})
 
230
            assert 0
209
231
        except TypeError:
210
 
            return
211
 
        assert 0
 
232
            pass
 
233
 
212
234