1
# Copyright (C) 2009, 2010 Canonical Ltd
1
# Copyright (C) 2009 Canonical Ltd
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
69
69
raise RuntimeError('I refuse to play nice')
72
class _NoImplementCompare(_Hashable):
74
def __eq__(self, other):
78
72
# Even though this is an extension, we don't permute the tests for a python
79
73
# version. As the plain python version is just a dict or set
80
compiled_simpleset_feature = tests.ModuleAvailableFeature(
81
'bzrlib._simple_set_pyx')
75
class _CompiledSimpleSet(tests.Feature):
78
if _simple_set_pyx is None:
82
def feature_name(self):
83
return 'bzrlib._simple_set_pyx'
85
CompiledSimpleSet = _CompiledSimpleSet()
84
88
class TestSimpleSet(tests.TestCase):
86
_test_needs_features = [compiled_simpleset_feature]
90
_test_needs_features = [CompiledSimpleSet]
87
91
module = _simple_set_pyx
89
93
def assertIn(self, obj, container):
325
329
# Tries to compare with k1, fails
326
330
self.assertRaises(RuntimeError, obj.add, k2)
328
def test_richcompare_not_implemented(self):
329
obj = self.module.SimpleSet()
330
# Even though their hashes are the same, tp_richcompare returns
331
# NotImplemented, which means we treat them as not equal
332
k1 = _NoImplementCompare(200)
333
k2 = _NoImplementCompare(200)
334
self.assertLookup(200, '<null>', obj, k1)
335
self.assertLookup(200, '<null>', obj, k2)
336
self.assertIs(k1, obj.add(k1))
337
self.assertLookup(200, k1, obj, k1)
338
self.assertLookup(201, '<null>', obj, k2)
339
self.assertIs(k2, obj.add(k2))
340
self.assertIs(k1, obj[k1])
342
332
def test_add_and_remove_lots_of_items(self):
343
333
obj = self.module.SimpleSet()
344
334
chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890'