/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 bzrlib/tests/test__simple_set.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import sys
20
20
 
21
 
from breezy import (
 
21
from bzrlib import (
22
22
    tests,
23
23
    )
24
 
from breezy.tests import (
 
24
from bzrlib.tests import (
25
25
    features,
26
26
    )
27
27
 
28
28
try:
29
 
    from breezy import _simple_set_pyx
 
29
    from bzrlib import _simple_set_pyx
30
30
except ImportError:
31
31
    _simple_set_pyx = None
32
32
 
35
35
    """A simple object which has a fixed hash value.
36
36
 
37
37
    We could have used an 'int', but it turns out that Int objects don't
38
 
    implement tp_richcompare in Python 2.
 
38
    implement tp_richcompare...
39
39
    """
40
40
 
41
41
    def __init__(self, the_hash):
69
69
    def __eq__(self, other):
70
70
        raise RuntimeError('I refuse to play nice')
71
71
 
72
 
    __hash__ = _Hashable.__hash__
73
 
 
74
72
 
75
73
class _NoImplementCompare(_Hashable):
76
74
 
77
75
    def __eq__(self, other):
78
76
        return NotImplemented
79
77
 
80
 
    __hash__ = _Hashable.__hash__
81
 
 
82
78
 
83
79
# Even though this is an extension, we don't permute the tests for a python
84
80
# version. As the plain python version is just a dict or set
85
81
compiled_simpleset_feature = features.ModuleAvailableFeature(
86
 
                                'breezy._simple_set_pyx')
 
82
                                'bzrlib._simple_set_pyx')
87
83
 
88
84
 
89
85
class TestSimpleSet(tests.TestCase):
91
87
    _test_needs_features = [compiled_simpleset_feature]
92
88
    module = _simple_set_pyx
93
89
 
 
90
    def assertIn(self, obj, container):
 
91
        self.assertTrue(obj in container,
 
92
            '%s not found in %s' % (obj, container))
 
93
 
 
94
    def assertNotIn(self, obj, container):
 
95
        self.assertTrue(obj not in container,
 
96
            'We found %s in %s' % (obj, container))
 
97
 
94
98
    def assertFillState(self, used, fill, mask, obj):
95
99
        self.assertEqual((used, fill, mask), (obj.used, obj.fill, obj.mask))
96
100
 
277
281
 
278
282
    def test__resize(self):
279
283
        obj = self.module.SimpleSet()
280
 
        # Need objects with exact hash as checking offset of <null> later
281
 
        k1 = _Hashable(501)
282
 
        k2 = _Hashable(591)
283
 
        k3 = _Hashable(2051)
 
284
        k1 = ('foo',)
 
285
        k2 = ('bar',)
 
286
        k3 = ('baz',)
284
287
        obj.add(k1)
285
288
        obj.add(k2)
286
289
        obj.add(k3)
370
373
            all.add(key)
371
374
        self.assertEqual(sorted([k1, k2, k3]), sorted(all))
372
375
        iterator = iter(obj)
373
 
        self.assertIn(next(iterator), all)
 
376
        iterator.next()
374
377
        obj.add(('foo',))
375
378
        # Set changed size
376
 
        self.assertRaises(RuntimeError, next, iterator)
 
379
        self.assertRaises(RuntimeError, iterator.next)
377
380
        # And even removing an item still causes it to fail
378
381
        obj.discard(k2)
379
 
        self.assertRaises(RuntimeError, next, iterator)
 
382
        self.assertRaises(RuntimeError, iterator.next)
380
383
 
381
384
    def test__sizeof__(self):
382
385
        # SimpleSet needs a custom sizeof implementation, because it allocates