104
104
args_300 = ['a']*300
105
105
self.assertRaises(ValueError, self.module.StaticTuple, *args_300)
107
self.assertRaises(TypeError, self.module.StaticTuple, 10)
107
self.assertRaises(TypeError, self.module.StaticTuple, object())
109
def test_concat(self):
110
st1 = self.module.StaticTuple('foo')
111
st2 = self.module.StaticTuple('bar')
112
st3 = self.module.StaticTuple('foo', 'bar')
114
self.assertEqual(st3, st4)
115
self.assertIsInstance(st4, self.module.StaticTuple)
117
def test_concat_with_tuple(self):
118
st1 = self.module.StaticTuple('foo')
120
st3 = self.module.StaticTuple('foo', 'bar')
121
st4 = self.module.StaticTuple('bar', 'foo')
124
self.assertEqual(st3, st5)
125
self.assertIsInstance(st5, self.module.StaticTuple)
126
self.assertEqual(st4, st6)
127
if self.module is _static_tuple_py:
128
# _static_tuple_py has StaticTuple(tuple), so tuple thinks it
129
# already knows how to concatenate, as such we can't "inject" our
130
# own concatenation...
131
self.assertIsInstance(st6, tuple)
133
self.assertIsInstance(st6, self.module.StaticTuple)
135
def test_concat_with_bad_tuple(self):
136
st1 = self.module.StaticTuple('foo')
138
# Using st1.__add__ doesn't give the same results as doing the '+' form
139
self.assertRaises(TypeError, lambda: st1 + t2)
141
def test_concat_with_non_tuple(self):
142
st1 = self.module.StaticTuple('foo')
143
self.assertRaises(TypeError, lambda: st1 + 10)
109
145
def test_as_tuple(self):
110
146
k = self.module.StaticTuple('foo')
177
213
self.assertFalse(k1 < k2)
178
214
self.assertFalse(k1 > k2)
216
def test_holds_None(self):
217
k1 = self.module.StaticTuple(None)
218
# You cannot subclass None anyway
220
def test_holds_int(self):
221
k1 = self.module.StaticTuple(1)
224
# But not a subclass, because subint could introduce refcycles
225
self.assertRaises(TypeError, self.module.StaticTuple, subint(2))
227
def test_holds_long(self):
228
k1 = self.module.StaticTuple(2L**65)
232
self.assertRaises(TypeError, self.module.StaticTuple, sublong(1))
234
def test_holds_float(self):
235
k1 = self.module.StaticTuple(1.2)
236
class subfloat(float):
238
self.assertRaises(TypeError, self.module.StaticTuple, subfloat(1.5))
240
def test_holds_str(self):
241
k1 = self.module.StaticTuple('astring')
244
self.assertRaises(TypeError, self.module.StaticTuple, substr('a'))
246
def test_holds_unicode(self):
247
k1 = self.module.StaticTuple(u'\xb5')
248
class subunicode(unicode):
250
self.assertRaises(TypeError, self.module.StaticTuple,
253
def test_hold_bool(self):
254
k1 = self.module.StaticTuple(True)
255
k2 = self.module.StaticTuple(False)
256
# Cannot subclass bool
180
258
def test_compare_same_obj(self):
181
259
k1 = self.module.StaticTuple('foo', 'bar')
182
260
self.assertCompareEqual(k1, k1)
183
261
k2 = self.module.StaticTuple(k1, k1)
184
262
self.assertCompareEqual(k2, k2)
263
k3 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, 2**65, True,
265
self.assertCompareEqual(k3, k3)
186
267
def test_compare_equivalent_obj(self):
187
268
k1 = self.module.StaticTuple('foo', 'bar')
190
271
k3 = self.module.StaticTuple(k1, k2)
191
272
k4 = self.module.StaticTuple(k2, k1)
192
273
self.assertCompareEqual(k1, k2)
274
k5 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, 2**65, True,
276
k6 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, 2**65, True,
278
self.assertCompareEqual(k5, k6)
279
k7 = self.module.StaticTuple(None)
280
k8 = self.module.StaticTuple(None)
281
self.assertCompareEqual(k7, k8)
194
283
def test_compare_similar_obj(self):
195
284
k1 = self.module.StaticTuple('foo' + ' bar', 'bar' + ' baz')
240
329
k3 = self.module.StaticTuple(k1, k2)
241
330
k4 = self.module.StaticTuple(k2, k1)
242
331
self.assertCompareDifferent(k3, k4)
332
k5 = self.module.StaticTuple(1)
333
k6 = self.module.StaticTuple(2)
334
self.assertCompareDifferent(k5, k6)
335
k7 = self.module.StaticTuple(1.2)
336
k8 = self.module.StaticTuple(2.4)
337
self.assertCompareDifferent(k7, k8)
338
k9 = self.module.StaticTuple(u's\xb5')
339
k10 = self.module.StaticTuple(u's\xe5')
340
self.assertCompareDifferent(k9, k10)
244
342
def test_compare_some_different(self):
245
343
k1 = self.module.StaticTuple('foo', 'bar')
248
346
k3 = self.module.StaticTuple(k1, k1)
249
347
k4 = self.module.StaticTuple(k1, k2)
250
348
self.assertCompareDifferent(k3, k4)
349
k5 = self.module.StaticTuple('foo', None)
350
self.assertCompareDifferent(k5, k1)
351
self.assertCompareDifferent(k5, k2)
252
353
def test_compare_diff_width(self):
253
354
k1 = self.module.StaticTuple('foo')
257
358
k4 = self.module.StaticTuple(k1, k2)
258
359
self.assertCompareDifferent(k3, k4)
361
def test_compare_different_types(self):
362
k1 = self.module.StaticTuple('foo', 'bar')
363
k2 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, 2**65, True,
365
self.assertCompareNoRelation(k1, k2)
366
k3 = self.module.StaticTuple('foo')
367
self.assertCompareDifferent(k3, k1)
368
k4 = self.module.StaticTuple(None)
369
self.assertCompareDifferent(k4, k1)
370
k5 = self.module.StaticTuple(1)
371
self.assertCompareNoRelation(k1, k5)
260
373
def test_compare_to_tuples(self):
261
374
k1 = self.module.StaticTuple('foo')
262
375
self.assertCompareEqual(k1, ('foo',))
306
419
as_tuple2 = (('foo', 'bar', 'baz', 'bing'),)
307
420
self.assertEqual(hash(k2), hash(as_tuple2))
422
k3 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, 2**65, True,
424
as_tuple3 = ('foo', 1, None, u'\xb5', 1.2, 2**65, True, k)
425
self.assertEqual(hash(as_tuple3), hash(k3))
309
427
def test_slice(self):
310
428
k = self.module.StaticTuple('foo', 'bar', 'baz', 'bing')
311
429
self.assertEqual(('foo', 'bar'), k[:2])