/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test__bencode.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-22 00:56:52 UTC
  • mfrom: (6621.2.26 py3_pokes)
  • Revision ID: jelmer@jelmer.uk-20170522005652-yjahcr9hwmjkno7n
Merge Python3 porting work ('py3 pokes')

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2007, 2009, 2010, 2016 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
16
16
 
17
17
"""Tests for bencode structured encoding"""
18
18
 
19
 
from bzrlib import tests
 
19
import sys
 
20
 
 
21
from .. import tests
20
22
 
21
23
def load_tests(standard_tests, module, loader):
22
24
    suite, _ = tests.permute_tests_for_extension(standard_tests, loader,
23
 
        'bzrlib.util._bencode_py', 'bzrlib._bencode_pyx')
 
25
        'breezy.util._bencode_py', 'breezy._bencode_pyx')
24
26
    return suite
25
27
 
26
28
 
29
31
    module = None
30
32
 
31
33
    def _check(self, expected, source):
32
 
        self.assertEquals(expected, self.module.bdecode(source))
 
34
        self.assertEqual(expected, self.module.bdecode(source))
33
35
 
34
36
    def _run_check_error(self, exc, bad):
35
37
        """Check that bdecoding a string raises a particular exception."""
43
45
        self._check(int('1' * 1000), 'i' + ('1' * 1000) + 'e')
44
46
 
45
47
    def test_long(self):
46
 
        self._check(12345678901234567890L, 'i12345678901234567890e')
47
 
        self._check(-12345678901234567890L, 'i-12345678901234567890e')
 
48
        self._check(12345678901234567890, 'i12345678901234567890e')
 
49
        self._check(-12345678901234567890, 'i-12345678901234567890e')
48
50
 
49
51
    def test_malformed_int(self):
50
52
        self._run_check_error(ValueError, 'ie')
105
107
                            'd8:spam.mp3d6:author5:Alice6:lengthi100000eee')
106
108
 
107
109
    def test_dict_deepnested(self):
108
 
        self._run_check_error(RuntimeError, ("d0:" * 10000) + 'i1e' + ("e" * 10000))
 
110
        # The recursion here provokes CPython into emitting a warning on
 
111
        # stderr, "maximum recursion depth exceeded in __subclasscheck__", due
 
112
        # to running out of stack space while evaluating "except (...):" in
 
113
        # _bencode_py.  This is harmless, so we temporarily override stderr to
 
114
        # avoid distracting noise in the test output.
 
115
        self.overrideAttr(sys, 'stderr', self._log_file)
 
116
        self._run_check_error(
 
117
            RuntimeError, ("d0:" * 10000) + 'i1e' + ("e" * 10000))
109
118
 
110
119
    def test_malformed_dict(self):
111
120
        self._run_check_error(ValueError, 'd')
146
155
    module = None
147
156
 
148
157
    def _check(self, expected, source):
149
 
        self.assertEquals(expected, self.module.bencode(source))
 
158
        self.assertEqual(expected, self.module.bencode(source))
150
159
 
151
160
    def test_int(self):
152
161
        self._check('i4e', 4)
154
163
        self._check('i-10e', -10)
155
164
 
156
165
    def test_long(self):
157
 
        self._check('i12345678901234567890e', 12345678901234567890L)
158
 
        self._check('i-12345678901234567890e', -12345678901234567890L)
 
166
        self._check('i12345678901234567890e', 12345678901234567890)
 
167
        self._check('i-12345678901234567890e', -12345678901234567890)
159
168
 
160
169
    def test_string(self):
161
170
        self._check('0:', '')