104
105
args_300 = ['a']*300
105
106
self.assertRaises(ValueError, self.module.StaticTuple, *args_300)
107
self.assertRaises(TypeError, self.module.StaticTuple, 10)
108
self.assertRaises(TypeError, self.module.StaticTuple, object())
110
def test_concat(self):
111
st1 = self.module.StaticTuple('foo')
112
st2 = self.module.StaticTuple('bar')
113
st3 = self.module.StaticTuple('foo', 'bar')
115
self.assertEqual(st3, st4)
116
self.assertIsInstance(st4, self.module.StaticTuple)
118
def test_concat_with_tuple(self):
119
st1 = self.module.StaticTuple('foo')
121
st3 = self.module.StaticTuple('foo', 'bar')
122
st4 = self.module.StaticTuple('bar', 'foo')
125
self.assertEqual(st3, st5)
126
self.assertIsInstance(st5, self.module.StaticTuple)
127
self.assertEqual(st4, st6)
128
if self.module is _static_tuple_py:
129
# _static_tuple_py has StaticTuple(tuple), so tuple thinks it
130
# already knows how to concatenate, as such we can't "inject" our
131
# own concatenation...
132
self.assertIsInstance(st6, tuple)
134
self.assertIsInstance(st6, self.module.StaticTuple)
136
def test_concat_with_bad_tuple(self):
137
st1 = self.module.StaticTuple('foo')
139
# Using st1.__add__ doesn't give the same results as doing the '+' form
140
self.assertRaises(TypeError, lambda: st1 + t2)
142
def test_concat_with_non_tuple(self):
143
st1 = self.module.StaticTuple('foo')
144
self.assertRaises(TypeError, lambda: st1 + 10)
109
146
def test_as_tuple(self):
110
147
k = self.module.StaticTuple('foo')
177
214
self.assertFalse(k1 < k2)
178
215
self.assertFalse(k1 > k2)
217
def test_holds_None(self):
218
k1 = self.module.StaticTuple(None)
219
# You cannot subclass None anyway
221
def test_holds_int(self):
222
k1 = self.module.StaticTuple(1)
225
# But not a subclass, because subint could introduce refcycles
226
self.assertRaises(TypeError, self.module.StaticTuple, subint(2))
228
def test_holds_long(self):
229
k1 = self.module.StaticTuple(2L**65)
233
self.assertRaises(TypeError, self.module.StaticTuple, sublong(1))
235
def test_holds_float(self):
236
k1 = self.module.StaticTuple(1.2)
237
class subfloat(float):
239
self.assertRaises(TypeError, self.module.StaticTuple, subfloat(1.5))
241
def test_holds_str(self):
242
k1 = self.module.StaticTuple('astring')
245
self.assertRaises(TypeError, self.module.StaticTuple, substr('a'))
247
def test_holds_unicode(self):
248
k1 = self.module.StaticTuple(u'\xb5')
249
class subunicode(unicode):
251
self.assertRaises(TypeError, self.module.StaticTuple,
254
def test_hold_bool(self):
255
k1 = self.module.StaticTuple(True)
256
k2 = self.module.StaticTuple(False)
257
# Cannot subclass bool
180
259
def test_compare_same_obj(self):
181
260
k1 = self.module.StaticTuple('foo', 'bar')
182
261
self.assertCompareEqual(k1, k1)
183
262
k2 = self.module.StaticTuple(k1, k1)
184
263
self.assertCompareEqual(k2, k2)
264
k3 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, 2**65, True,
266
self.assertCompareEqual(k3, k3)
186
268
def test_compare_equivalent_obj(self):
187
269
k1 = self.module.StaticTuple('foo', 'bar')
190
272
k3 = self.module.StaticTuple(k1, k2)
191
273
k4 = self.module.StaticTuple(k2, k1)
192
274
self.assertCompareEqual(k1, k2)
275
k5 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, 2**65, True,
277
k6 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, 2**65, True,
279
self.assertCompareEqual(k5, k6)
280
k7 = self.module.StaticTuple(None)
281
k8 = self.module.StaticTuple(None)
282
self.assertCompareEqual(k7, k8)
194
284
def test_compare_similar_obj(self):
195
285
k1 = self.module.StaticTuple('foo' + ' bar', 'bar' + ' baz')
240
330
k3 = self.module.StaticTuple(k1, k2)
241
331
k4 = self.module.StaticTuple(k2, k1)
242
332
self.assertCompareDifferent(k3, k4)
333
k5 = self.module.StaticTuple(1)
334
k6 = self.module.StaticTuple(2)
335
self.assertCompareDifferent(k5, k6)
336
k7 = self.module.StaticTuple(1.2)
337
k8 = self.module.StaticTuple(2.4)
338
self.assertCompareDifferent(k7, k8)
339
k9 = self.module.StaticTuple(u's\xb5')
340
k10 = self.module.StaticTuple(u's\xe5')
341
self.assertCompareDifferent(k9, k10)
244
343
def test_compare_some_different(self):
245
344
k1 = self.module.StaticTuple('foo', 'bar')
248
347
k3 = self.module.StaticTuple(k1, k1)
249
348
k4 = self.module.StaticTuple(k1, k2)
250
349
self.assertCompareDifferent(k3, k4)
350
k5 = self.module.StaticTuple('foo', None)
351
self.assertCompareDifferent(k5, k1)
352
self.assertCompareDifferent(k5, k2)
252
354
def test_compare_diff_width(self):
253
355
k1 = self.module.StaticTuple('foo')
257
359
k4 = self.module.StaticTuple(k1, k2)
258
360
self.assertCompareDifferent(k3, k4)
362
def test_compare_different_types(self):
363
k1 = self.module.StaticTuple('foo', 'bar')
364
k2 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, 2**65, True,
366
self.assertCompareNoRelation(k1, k2)
367
k3 = self.module.StaticTuple('foo')
368
self.assertCompareDifferent(k3, k1)
369
k4 = self.module.StaticTuple(None)
370
self.assertCompareDifferent(k4, k1)
371
k5 = self.module.StaticTuple(1)
372
self.assertCompareNoRelation(k1, k5)
260
374
def test_compare_to_tuples(self):
261
375
k1 = self.module.StaticTuple('foo')
262
376
self.assertCompareEqual(k1, ('foo',))
306
420
as_tuple2 = (('foo', 'bar', 'baz', 'bing'),)
307
421
self.assertEqual(hash(k2), hash(as_tuple2))
423
k3 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, 2**65, True,
425
as_tuple3 = ('foo', 1, None, u'\xb5', 1.2, 2**65, True, k)
426
self.assertEqual(hash(as_tuple3), hash(k3))
309
428
def test_slice(self):
310
429
k = self.module.StaticTuple('foo', 'bar', 'baz', 'bing')
311
430
self.assertEqual(('foo', 'bar'), k[:2])
459
578
self.assertRaises(TypeError,
460
579
self.module.StaticTuple.from_sequence, foo='a')
581
def test_pickle(self):
582
st = self.module.StaticTuple('foo', 'bar')
583
pickled = cPickle.dumps(st)
584
unpickled = cPickle.loads(pickled)
585
self.assertEqual(unpickled, st)
587
def test_pickle_empty(self):
588
st = self.module.StaticTuple()
589
pickled = cPickle.dumps(st)
590
unpickled = cPickle.loads(pickled)
591
self.assertIs(st, unpickled)
593
def test_pickle_nested(self):
594
st = self.module.StaticTuple('foo', self.module.StaticTuple('bar'))
595
pickled = cPickle.dumps(st)
596
unpickled = cPickle.loads(pickled)
597
self.assertEqual(unpickled, st)
462
599
def test_static_tuple_thunk(self):
463
600
# Make sure the right implementation is available from
464
601
# bzrlib.static_tuple.StaticTuple.