annotate Lib/test/buffer_tests.py @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents 82b58807f481
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43576
diff changeset
1 # Tests that work for both bytes and buffer objects.
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
2 # See PEP 3137.
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
3
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
4 import struct
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
5 import sys
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
6
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
7 class MixinBytesBufferCommonTests(object):
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43576
diff changeset
8 """Tests that work for both bytes and buffer objects.
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
9 See PEP 3137.
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
10 """
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
11
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
12 def marshal(self, x):
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
13 """Convert x into the appropriate type for these tests."""
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
14 raise RuntimeError('test class must provide a marshal method')
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
15
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
16 def test_islower(self):
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
17 self.assertFalse(self.marshal(b'').islower())
66310
9fe76c26ea9f #9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 52700
diff changeset
18 self.assertTrue(self.marshal(b'a').islower())
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
19 self.assertFalse(self.marshal(b'A').islower())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
20 self.assertFalse(self.marshal(b'\n').islower())
66310
9fe76c26ea9f #9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 52700
diff changeset
21 self.assertTrue(self.marshal(b'abc').islower())
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
22 self.assertFalse(self.marshal(b'aBc').islower())
66310
9fe76c26ea9f #9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 52700
diff changeset
23 self.assertTrue(self.marshal(b'abc\n').islower())
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
24 self.assertRaises(TypeError, self.marshal(b'abc').islower, 42)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
25
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
26 def test_isupper(self):
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
27 self.assertFalse(self.marshal(b'').isupper())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
28 self.assertFalse(self.marshal(b'a').isupper())
66310
9fe76c26ea9f #9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 52700
diff changeset
29 self.assertTrue(self.marshal(b'A').isupper())
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
30 self.assertFalse(self.marshal(b'\n').isupper())
66310
9fe76c26ea9f #9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 52700
diff changeset
31 self.assertTrue(self.marshal(b'ABC').isupper())
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
32 self.assertFalse(self.marshal(b'AbC').isupper())
66310
9fe76c26ea9f #9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 52700
diff changeset
33 self.assertTrue(self.marshal(b'ABC\n').isupper())
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
34 self.assertRaises(TypeError, self.marshal(b'abc').isupper, 42)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
35
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
36 def test_istitle(self):
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
37 self.assertFalse(self.marshal(b'').istitle())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
38 self.assertFalse(self.marshal(b'a').istitle())
66310
9fe76c26ea9f #9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 52700
diff changeset
39 self.assertTrue(self.marshal(b'A').istitle())
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
40 self.assertFalse(self.marshal(b'\n').istitle())
66310
9fe76c26ea9f #9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 52700
diff changeset
41 self.assertTrue(self.marshal(b'A Titlecased Line').istitle())
9fe76c26ea9f #9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 52700
diff changeset
42 self.assertTrue(self.marshal(b'A\nTitlecased Line').istitle())
9fe76c26ea9f #9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 52700
diff changeset
43 self.assertTrue(self.marshal(b'A Titlecased, Line').istitle())
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
44 self.assertFalse(self.marshal(b'Not a capitalized String').istitle())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
45 self.assertFalse(self.marshal(b'Not\ta Titlecase String').istitle())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
46 self.assertFalse(self.marshal(b'Not--a Titlecase String').istitle())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
47 self.assertFalse(self.marshal(b'NOT').istitle())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
48 self.assertRaises(TypeError, self.marshal(b'abc').istitle, 42)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
49
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
50 def test_isspace(self):
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
51 self.assertFalse(self.marshal(b'').isspace())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
52 self.assertFalse(self.marshal(b'a').isspace())
66310
9fe76c26ea9f #9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 52700
diff changeset
53 self.assertTrue(self.marshal(b' ').isspace())
9fe76c26ea9f #9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 52700
diff changeset
54 self.assertTrue(self.marshal(b'\t').isspace())
9fe76c26ea9f #9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 52700
diff changeset
55 self.assertTrue(self.marshal(b'\r').isspace())
9fe76c26ea9f #9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 52700
diff changeset
56 self.assertTrue(self.marshal(b'\n').isspace())
9fe76c26ea9f #9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 52700
diff changeset
57 self.assertTrue(self.marshal(b' \t\r\n').isspace())
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
58 self.assertFalse(self.marshal(b' \t\r\na').isspace())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
59 self.assertRaises(TypeError, self.marshal(b'abc').isspace, 42)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
60
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
61 def test_isalpha(self):
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
62 self.assertFalse(self.marshal(b'').isalpha())
66310
9fe76c26ea9f #9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 52700
diff changeset
63 self.assertTrue(self.marshal(b'a').isalpha())
9fe76c26ea9f #9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 52700
diff changeset
64 self.assertTrue(self.marshal(b'A').isalpha())
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
65 self.assertFalse(self.marshal(b'\n').isalpha())
66310
9fe76c26ea9f #9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 52700
diff changeset
66 self.assertTrue(self.marshal(b'abc').isalpha())
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
67 self.assertFalse(self.marshal(b'aBc123').isalpha())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
68 self.assertFalse(self.marshal(b'abc\n').isalpha())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
69 self.assertRaises(TypeError, self.marshal(b'abc').isalpha, 42)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
70
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
71 def test_isalnum(self):
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
72 self.assertFalse(self.marshal(b'').isalnum())
66310
9fe76c26ea9f #9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 52700
diff changeset
73 self.assertTrue(self.marshal(b'a').isalnum())
9fe76c26ea9f #9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 52700
diff changeset
74 self.assertTrue(self.marshal(b'A').isalnum())
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
75 self.assertFalse(self.marshal(b'\n').isalnum())
66310
9fe76c26ea9f #9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 52700
diff changeset
76 self.assertTrue(self.marshal(b'123abc456').isalnum())
9fe76c26ea9f #9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 52700
diff changeset
77 self.assertTrue(self.marshal(b'a1b3c').isalnum())
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
78 self.assertFalse(self.marshal(b'aBc000 ').isalnum())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
79 self.assertFalse(self.marshal(b'abc\n').isalnum())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
80 self.assertRaises(TypeError, self.marshal(b'abc').isalnum, 42)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
81
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
82 def test_isdigit(self):
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
83 self.assertFalse(self.marshal(b'').isdigit())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
84 self.assertFalse(self.marshal(b'a').isdigit())
66310
9fe76c26ea9f #9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 52700
diff changeset
85 self.assertTrue(self.marshal(b'0').isdigit())
9fe76c26ea9f #9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 52700
diff changeset
86 self.assertTrue(self.marshal(b'0123456789').isdigit())
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
87 self.assertFalse(self.marshal(b'0123456789a').isdigit())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
88
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
89 self.assertRaises(TypeError, self.marshal(b'abc').isdigit, 42)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
90
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
91 def test_lower(self):
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
92 self.assertEqual(b'hello', self.marshal(b'HeLLo').lower())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
93 self.assertEqual(b'hello', self.marshal(b'hello').lower())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
94 self.assertRaises(TypeError, self.marshal(b'hello').lower, 42)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
95
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
96 def test_upper(self):
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
97 self.assertEqual(b'HELLO', self.marshal(b'HeLLo').upper())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
98 self.assertEqual(b'HELLO', self.marshal(b'HELLO').upper())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
99 self.assertRaises(TypeError, self.marshal(b'hello').upper, 42)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
100
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
101 def test_capitalize(self):
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
102 self.assertEqual(b' hello ', self.marshal(b' hello ').capitalize())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
103 self.assertEqual(b'Hello ', self.marshal(b'Hello ').capitalize())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
104 self.assertEqual(b'Hello ', self.marshal(b'hello ').capitalize())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
105 self.assertEqual(b'Aaaa', self.marshal(b'aaaa').capitalize())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
106 self.assertEqual(b'Aaaa', self.marshal(b'AaAa').capitalize())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
107
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
108 self.assertRaises(TypeError, self.marshal(b'hello').capitalize, 42)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
109
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
110 def test_ljust(self):
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
111 self.assertEqual(b'abc ', self.marshal(b'abc').ljust(10))
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
112 self.assertEqual(b'abc ', self.marshal(b'abc').ljust(6))
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
113 self.assertEqual(b'abc', self.marshal(b'abc').ljust(3))
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
114 self.assertEqual(b'abc', self.marshal(b'abc').ljust(2))
52700
a73d7326311d make 'c' only accept bytes and 'C' only unicode #5499
Benjamin Peterson <benjamin@python.org>
parents: 44160
diff changeset
115 self.assertEqual(b'abc*******', self.marshal(b'abc').ljust(10, b'*'))
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
116 self.assertRaises(TypeError, self.marshal(b'abc').ljust)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
117
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
118 def test_rjust(self):
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
119 self.assertEqual(b' abc', self.marshal(b'abc').rjust(10))
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
120 self.assertEqual(b' abc', self.marshal(b'abc').rjust(6))
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
121 self.assertEqual(b'abc', self.marshal(b'abc').rjust(3))
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
122 self.assertEqual(b'abc', self.marshal(b'abc').rjust(2))
52700
a73d7326311d make 'c' only accept bytes and 'C' only unicode #5499
Benjamin Peterson <benjamin@python.org>
parents: 44160
diff changeset
123 self.assertEqual(b'*******abc', self.marshal(b'abc').rjust(10, b'*'))
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
124 self.assertRaises(TypeError, self.marshal(b'abc').rjust)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
125
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
126 def test_center(self):
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
127 self.assertEqual(b' abc ', self.marshal(b'abc').center(10))
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
128 self.assertEqual(b' abc ', self.marshal(b'abc').center(6))
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
129 self.assertEqual(b'abc', self.marshal(b'abc').center(3))
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
130 self.assertEqual(b'abc', self.marshal(b'abc').center(2))
52700
a73d7326311d make 'c' only accept bytes and 'C' only unicode #5499
Benjamin Peterson <benjamin@python.org>
parents: 44160
diff changeset
131 self.assertEqual(b'***abc****', self.marshal(b'abc').center(10, b'*'))
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
132 self.assertRaises(TypeError, self.marshal(b'abc').center)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
133
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
134 def test_swapcase(self):
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
135 self.assertEqual(b'hEllO CoMPuTErS',
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
136 self.marshal(b'HeLLo cOmpUteRs').swapcase())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
137
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
138 self.assertRaises(TypeError, self.marshal(b'hello').swapcase, 42)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
139
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
140 def test_zfill(self):
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
141 self.assertEqual(b'123', self.marshal(b'123').zfill(2))
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
142 self.assertEqual(b'123', self.marshal(b'123').zfill(3))
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
143 self.assertEqual(b'0123', self.marshal(b'123').zfill(4))
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
144 self.assertEqual(b'+123', self.marshal(b'+123').zfill(3))
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
145 self.assertEqual(b'+123', self.marshal(b'+123').zfill(4))
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
146 self.assertEqual(b'+0123', self.marshal(b'+123').zfill(5))
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
147 self.assertEqual(b'-123', self.marshal(b'-123').zfill(3))
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
148 self.assertEqual(b'-123', self.marshal(b'-123').zfill(4))
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
149 self.assertEqual(b'-0123', self.marshal(b'-123').zfill(5))
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
150 self.assertEqual(b'000', self.marshal(b'').zfill(3))
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
151 self.assertEqual(b'34', self.marshal(b'34').zfill(1))
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
152 self.assertEqual(b'0034', self.marshal(b'34').zfill(4))
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
153
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
154 self.assertRaises(TypeError, self.marshal(b'123').zfill)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
155
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
156 def test_expandtabs(self):
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
157 self.assertEqual(b'abc\rab def\ng hi',
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
158 self.marshal(b'abc\rab\tdef\ng\thi').expandtabs())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
159 self.assertEqual(b'abc\rab def\ng hi',
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
160 self.marshal(b'abc\rab\tdef\ng\thi').expandtabs(8))
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
161 self.assertEqual(b'abc\rab def\ng hi',
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
162 self.marshal(b'abc\rab\tdef\ng\thi').expandtabs(4))
87153
82b58807f481 #17806: Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
Ezio Melotti <ezio.melotti@gmail.com>
parents: 72462
diff changeset
163 self.assertEqual(b'abc\r\nab def\ng hi',
82b58807f481 #17806: Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
Ezio Melotti <ezio.melotti@gmail.com>
parents: 72462
diff changeset
164 self.marshal(b'abc\r\nab\tdef\ng\thi').expandtabs())
82b58807f481 #17806: Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
Ezio Melotti <ezio.melotti@gmail.com>
parents: 72462
diff changeset
165 self.assertEqual(b'abc\r\nab def\ng hi',
82b58807f481 #17806: Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
Ezio Melotti <ezio.melotti@gmail.com>
parents: 72462
diff changeset
166 self.marshal(b'abc\r\nab\tdef\ng\thi').expandtabs(8))
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
167 self.assertEqual(b'abc\r\nab def\ng hi',
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
168 self.marshal(b'abc\r\nab\tdef\ng\thi').expandtabs(4))
87153
82b58807f481 #17806: Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
Ezio Melotti <ezio.melotti@gmail.com>
parents: 72462
diff changeset
169 self.assertEqual(b'abc\r\nab\r\ndef\ng\r\nhi',
82b58807f481 #17806: Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
Ezio Melotti <ezio.melotti@gmail.com>
parents: 72462
diff changeset
170 self.marshal(b'abc\r\nab\r\ndef\ng\r\nhi').expandtabs(4))
82b58807f481 #17806: Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
Ezio Melotti <ezio.melotti@gmail.com>
parents: 72462
diff changeset
171 # check keyword args
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
172 self.assertEqual(b'abc\rab def\ng hi',
87153
82b58807f481 #17806: Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
Ezio Melotti <ezio.melotti@gmail.com>
parents: 72462
diff changeset
173 self.marshal(b'abc\rab\tdef\ng\thi').expandtabs(tabsize=8))
82b58807f481 #17806: Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
Ezio Melotti <ezio.melotti@gmail.com>
parents: 72462
diff changeset
174 self.assertEqual(b'abc\rab def\ng hi',
82b58807f481 #17806: Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
Ezio Melotti <ezio.melotti@gmail.com>
parents: 72462
diff changeset
175 self.marshal(b'abc\rab\tdef\ng\thi').expandtabs(tabsize=4))
82b58807f481 #17806: Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
Ezio Melotti <ezio.melotti@gmail.com>
parents: 72462
diff changeset
176
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
177 self.assertEqual(b' a\n b', self.marshal(b' \ta\n\tb').expandtabs(1))
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
178
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
179 self.assertRaises(TypeError, self.marshal(b'hello').expandtabs, 42, 42)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
180 # This test is only valid when sizeof(int) == sizeof(void*) == 4.
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
181 if sys.maxsize < (1 << 32) and struct.calcsize('P') == 4:
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
182 self.assertRaises(OverflowError,
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
183 self.marshal(b'\ta\n\tb').expandtabs, sys.maxsize)
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
184
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
185 def test_title(self):
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
186 self.assertEqual(b' Hello ', self.marshal(b' hello ').title())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
187 self.assertEqual(b'Hello ', self.marshal(b'hello ').title())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
188 self.assertEqual(b'Hello ', self.marshal(b'Hello ').title())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
189 self.assertEqual(b'Format This As Title String',
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
190 self.marshal(b'fOrMaT thIs aS titLe String').title())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
191 self.assertEqual(b'Format,This-As*Title;String',
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
192 self.marshal(b'fOrMaT,thIs-aS*titLe;String').title())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
193 self.assertEqual(b'Getint', self.marshal(b'getInt').title())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
194 self.assertRaises(TypeError, self.marshal(b'hello').title, 42)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
195
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
196 def test_splitlines(self):
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
197 self.assertEqual([b'abc', b'def', b'', b'ghi'],
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
198 self.marshal(b'abc\ndef\n\rghi').splitlines())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
199 self.assertEqual([b'abc', b'def', b'', b'ghi'],
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
200 self.marshal(b'abc\ndef\n\r\nghi').splitlines())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
201 self.assertEqual([b'abc', b'def', b'ghi'],
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
202 self.marshal(b'abc\ndef\r\nghi').splitlines())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
203 self.assertEqual([b'abc', b'def', b'ghi'],
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
204 self.marshal(b'abc\ndef\r\nghi\n').splitlines())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
205 self.assertEqual([b'abc', b'def', b'ghi', b''],
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
206 self.marshal(b'abc\ndef\r\nghi\n\r').splitlines())
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
207 self.assertEqual([b'', b'abc', b'def', b'ghi', b''],
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
208 self.marshal(b'\nabc\ndef\r\nghi\n\r').splitlines())
72462
0b2660384d4e Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines.
Mark Dickinson <mdickinson@enthought.com>
parents: 66310
diff changeset
209 self.assertEqual([b'', b'abc', b'def', b'ghi', b''],
0b2660384d4e Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines.
Mark Dickinson <mdickinson@enthought.com>
parents: 66310
diff changeset
210 self.marshal(b'\nabc\ndef\r\nghi\n\r').splitlines(False))
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
211 self.assertEqual([b'\n', b'abc\n', b'def\r\n', b'ghi\n', b'\r'],
72462
0b2660384d4e Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines.
Mark Dickinson <mdickinson@enthought.com>
parents: 66310
diff changeset
212 self.marshal(b'\nabc\ndef\r\nghi\n\r').splitlines(True))
0b2660384d4e Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines.
Mark Dickinson <mdickinson@enthought.com>
parents: 66310
diff changeset
213 self.assertEqual([b'', b'abc', b'def', b'ghi', b''],
0b2660384d4e Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines.
Mark Dickinson <mdickinson@enthought.com>
parents: 66310
diff changeset
214 self.marshal(b'\nabc\ndef\r\nghi\n\r').splitlines(keepends=False))
0b2660384d4e Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines.
Mark Dickinson <mdickinson@enthought.com>
parents: 66310
diff changeset
215 self.assertEqual([b'\n', b'abc\n', b'def\r\n', b'ghi\n', b'\r'],
0b2660384d4e Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines.
Mark Dickinson <mdickinson@enthought.com>
parents: 66310
diff changeset
216 self.marshal(b'\nabc\ndef\r\nghi\n\r').splitlines(keepends=True))
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
217
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
218 self.assertRaises(TypeError, self.marshal(b'abc').splitlines, 42, 42)