~a1s/brz/3.2-windows-installer

« back to all changes in this revision

Viewing changes to breezy/tests/test__simple_set.py

  • Committer: Jelmer Vernooij
  • Date: 2017-07-23 22:06:41 UTC
  • mfrom: (6738 trunk)
  • mto: This revision was merged to the branch mainline in revision 6739.
  • Revision ID: jelmer@jelmer.uk-20170723220641-69eczax9bmv8d6kk
Merge trunk, address review comments.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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...
 
38
    implement tp_richcompare in Python 2.
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
 
72
74
 
73
75
class _NoImplementCompare(_Hashable):
74
76
 
75
77
    def __eq__(self, other):
76
78
        return NotImplemented
77
79
 
 
80
    __hash__ = _Hashable.__hash__
 
81
 
78
82
 
79
83
# Even though this is an extension, we don't permute the tests for a python
80
84
# version. As the plain python version is just a dict or set
87
91
    _test_needs_features = [compiled_simpleset_feature]
88
92
    module = _simple_set_pyx
89
93
 
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
 
 
98
94
    def assertFillState(self, used, fill, mask, obj):
99
95
        self.assertEqual((used, fill, mask), (obj.used, obj.fill, obj.mask))
100
96
 
281
277
 
282
278
    def test__resize(self):
283
279
        obj = self.module.SimpleSet()
284
 
        k1 = ('foo',)
285
 
        k2 = ('bar',)
286
 
        k3 = ('baz',)
 
280
        # Need objects with exact hash as checking offset of <null> later
 
281
        k1 = _Hashable(501)
 
282
        k2 = _Hashable(591)
 
283
        k3 = _Hashable(2051)
287
284
        obj.add(k1)
288
285
        obj.add(k2)
289
286
        obj.add(k3)
373
370
            all.add(key)
374
371
        self.assertEqual(sorted([k1, k2, k3]), sorted(all))
375
372
        iterator = iter(obj)
376
 
        next(iterator)
 
373
        self.assertIn(next(iterator), all)
377
374
        obj.add(('foo',))
378
375
        # Set changed size
379
376
        self.assertRaises(RuntimeError, next, iterator)