/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test__static_tuple.py

  • Committer: Breezy landing bot
  • Author(s): Martin
  • Date: 2017-06-25 23:44:48 UTC
  • mfrom: (6715.1.4 py3_static_tuple_start)
  • Revision ID: breezy.the.bot@gmail.com-20170625234448-pn3eoyb7as7yc6z0
Start of making _static_tuple_c compatible with Python 3

Merged from https://code.launchpad.net/~gz/brz/py3_static_tuple_start/+merge/326117

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests for the StaticTuple type."""
18
18
 
19
 
import cPickle
 
19
try:
 
20
    import cPickle as pickle
 
21
except ImportError:
 
22
    import pickle
20
23
import sys
21
24
 
22
25
from breezy import (
26
29
    static_tuple,
27
30
    tests,
28
31
    )
 
32
from breezy.sixish import (
 
33
    PY3,
 
34
    text_type,
 
35
    )
29
36
from breezy.tests import (
30
37
    features,
31
38
    )
213
220
        self.assertRaises(TypeError, self.module.StaticTuple, subint(2))
214
221
 
215
222
    def test_holds_long(self):
 
223
        if PY3:
 
224
            self.skipTest("No long type on Python 3")
216
225
        k1 = self.module.StaticTuple(2**65)
217
226
        class sublong(long):
218
227
            pass
225
234
            pass
226
235
        self.assertRaises(TypeError, self.module.StaticTuple, subfloat(1.5))
227
236
 
228
 
    def test_holds_str(self):
229
 
        k1 = self.module.StaticTuple('astring')
230
 
        class substr(str):
 
237
    def test_holds_bytes(self):
 
238
        k1 = self.module.StaticTuple(b'astring')
 
239
        class substr(bytes):
231
240
            pass
232
 
        self.assertRaises(TypeError, self.module.StaticTuple, substr('a'))
 
241
        self.assertRaises(TypeError, self.module.StaticTuple, substr(b'a'))
233
242
 
234
243
    def test_holds_unicode(self):
235
244
        k1 = self.module.StaticTuple(u'\xb5')
236
 
        class subunicode(unicode):
 
245
        class subunicode(text_type):
237
246
            pass
238
247
        self.assertRaises(TypeError, self.module.StaticTuple,
239
248
                          subunicode(u'\xb5'))
416
425
        k = self.module.StaticTuple('foo', 'bar', 'baz', 'bing')
417
426
        self.assertEqual(('foo', 'bar'), k[:2])
418
427
        self.assertEqual(('baz',), k[2:-1])
419
 
        try:
420
 
            val = k[::2]
421
 
        except TypeError:
422
 
            # C implementation raises a TypeError, we don't need the
423
 
            # implementation yet, so allow this to pass
424
 
            pass
425
 
        else:
426
 
            # Python implementation uses a regular Tuple, so make sure it gives
427
 
            # the right result
428
 
            self.assertEqual(('foo', 'baz'), val)
 
428
        self.assertEqual(('foo', 'baz',), k[::2])
 
429
        self.assertRaises(TypeError, k.__getitem__, 'not_slice')
429
430
 
430
431
    def test_referents(self):
431
432
        # We implement tp_traverse so that things like 'meliae' can measure the
582
583
 
583
584
    def test_pickle(self):
584
585
        st = self.module.StaticTuple('foo', 'bar')
585
 
        pickled = cPickle.dumps(st)
586
 
        unpickled = cPickle.loads(pickled)
 
586
        pickled = pickle.dumps(st)
 
587
        unpickled = pickle.loads(pickled)
587
588
        self.assertEqual(unpickled, st)
588
589
 
589
590
    def test_pickle_empty(self):
590
591
        st = self.module.StaticTuple()
591
 
        pickled = cPickle.dumps(st)
592
 
        unpickled = cPickle.loads(pickled)
 
592
        pickled = pickle.dumps(st)
 
593
        unpickled = pickle.loads(pickled)
593
594
        self.assertIs(st, unpickled)
594
595
 
595
596
    def test_pickle_nested(self):
596
597
        st = self.module.StaticTuple('foo', self.module.StaticTuple('bar'))
597
 
        pickled = cPickle.dumps(st)
598
 
        unpickled = cPickle.loads(pickled)
 
598
        pickled = pickle.dumps(st)
 
599
        unpickled = pickle.loads(pickled)
599
600
        self.assertEqual(unpickled, st)
600
601
 
601
602
    def test_static_tuple_thunk(self):