141
141
self.assertEqual('foo', k[0])
142
142
self.assertEqual('z', k[6])
143
143
self.assertEqual('z', k[-1])
144
self.assertRaises(IndexError, k.__getitem__, 7)
145
self.assertRaises(IndexError, k.__getitem__, 256+7)
146
self.assertRaises(IndexError, k.__getitem__, 12024)
147
# Python's [] resolver handles the negative arguments, so we can't
148
# really test StaticTuple_item() with negative values.
149
self.assertRaises(TypeError, k.__getitem__, 'not-an-int')
150
self.assertRaises(TypeError, k.__getitem__, '5')
145
152
def test_refcount(self):
202
209
self.assertTrue(k_small <= k_big)
203
210
self.assertTrue(k_small < k_big)
212
def assertCompareNoRelation(self, k1, k2):
213
"""Run the comparison operators, make sure they do something.
215
However, we don't actually care what comes first or second. This is
216
stuff like cross-class comparisons. We don't want to segfault/raise an
217
exception, but we don't care about the sort order.
219
self.assertFalse(k1 == k2)
220
self.assertTrue(k1 != k2)
221
# Do the comparison, but we don't care about the result
205
227
def test_compare_vs_none(self):
206
228
k1 = self.module.StaticTuple('baz', 'bing')
207
229
self.assertCompareDifferent(None, k1)
208
self.assertCompareDifferent(10, k1)
209
# Comparison with a string is poorly-defined, I seem to get failures
210
# regardless of which one comes first...
211
# self.assertCompareDifferent('baz', k1)
231
def test_compare_cross_class(self):
232
k1 = self.module.StaticTuple('baz', 'bing')
233
self.assertCompareNoRelation(10, k1)
234
self.assertCompareNoRelation('baz', k1)
213
236
def test_compare_all_different_same_width(self):
214
237
k1 = self.module.StaticTuple('baz', 'bing')
277
300
k = self.module.StaticTuple('foo', 'bar', 'baz', 'bing')
278
301
self.assertEqual(('foo', 'bar'), k[:2])
279
302
self.assertEqual(('baz',), k[2:-1])
306
# C implementation raises a TypeError, we don't need the
307
# implementation yet, so allow this to pass
310
# Python implementation uses a regular Tuple, so make sure it gives
312
self.assertEqual(('foo', 'baz'), val)
281
314
def test_referents(self):
282
315
# We implement tp_traverse so that things like 'meliae' can measure the
283
316
# amount of referenced memory. Unfortunately gc.get_referents() first
284
# checks the IS_GC flag before it traverses anything. So there isn't a
285
# way to expose it that I can see.
317
# checks the IS_GC flag before it traverses anything. We could write a
318
# helper func, but that won't work for the generic implementation...
286
319
self.requireFeature(Meliae)
287
320
from meliae import scanner
288
321
strs = ['foo', 'bar', 'baz', 'bing']