Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 275bd96

Browse files
committed
Issue #19587: Remove masked and redundant tests in test_bytes
* test_contains() did not override anything * test_expandtabs/upper/lower() in FixedStringTest were masking usable tests in string_tests. These tests now get run for bytearray() and bytes(). * test_expandtabs/upper/lower() in buffer_tests were only run on bytearray() and are redundant with string_tests
1 parent 3464ea2 commit 275bd96

3 files changed

Lines changed: 6 additions & 63 deletions

File tree

Lib/test/buffer_tests.py

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
# Tests that work for both bytes and buffer objects.
1+
# Tests that work for bytearray objects. Could be merged into string_tests.
22
# See PEP 3137.
33

4-
import struct
5-
import sys
6-
74
class MixinBytesBufferCommonTests(object):
8-
"""Tests that work for both bytes and buffer objects.
5+
"""Tests that work for bytearray objects.
96
See PEP 3137.
107
"""
118

@@ -88,16 +85,6 @@ def test_isdigit(self):
8885

8986
self.assertRaises(TypeError, self.marshal(b'abc').isdigit, 42)
9087

91-
def test_lower(self):
92-
self.assertEqual(b'hello', self.marshal(b'HeLLo').lower())
93-
self.assertEqual(b'hello', self.marshal(b'hello').lower())
94-
self.assertRaises(TypeError, self.marshal(b'hello').lower, 42)
95-
96-
def test_upper(self):
97-
self.assertEqual(b'HELLO', self.marshal(b'HeLLo').upper())
98-
self.assertEqual(b'HELLO', self.marshal(b'HELLO').upper())
99-
self.assertRaises(TypeError, self.marshal(b'hello').upper, 42)
100-
10188
def test_capitalize(self):
10289
self.assertEqual(b' hello ', self.marshal(b' hello ').capitalize())
10390
self.assertEqual(b'Hello ', self.marshal(b'Hello ').capitalize())
@@ -153,35 +140,6 @@ def test_zfill(self):
153140

154141
self.assertRaises(TypeError, self.marshal(b'123').zfill)
155142

156-
def test_expandtabs(self):
157-
self.assertEqual(b'abc\rab def\ng hi',
158-
self.marshal(b'abc\rab\tdef\ng\thi').expandtabs())
159-
self.assertEqual(b'abc\rab def\ng hi',
160-
self.marshal(b'abc\rab\tdef\ng\thi').expandtabs(8))
161-
self.assertEqual(b'abc\rab def\ng hi',
162-
self.marshal(b'abc\rab\tdef\ng\thi').expandtabs(4))
163-
self.assertEqual(b'abc\r\nab def\ng hi',
164-
self.marshal(b'abc\r\nab\tdef\ng\thi').expandtabs())
165-
self.assertEqual(b'abc\r\nab def\ng hi',
166-
self.marshal(b'abc\r\nab\tdef\ng\thi').expandtabs(8))
167-
self.assertEqual(b'abc\r\nab def\ng hi',
168-
self.marshal(b'abc\r\nab\tdef\ng\thi').expandtabs(4))
169-
self.assertEqual(b'abc\r\nab\r\ndef\ng\r\nhi',
170-
self.marshal(b'abc\r\nab\r\ndef\ng\r\nhi').expandtabs(4))
171-
# check keyword args
172-
self.assertEqual(b'abc\rab def\ng hi',
173-
self.marshal(b'abc\rab\tdef\ng\thi').expandtabs(tabsize=8))
174-
self.assertEqual(b'abc\rab def\ng hi',
175-
self.marshal(b'abc\rab\tdef\ng\thi').expandtabs(tabsize=4))
176-
177-
self.assertEqual(b' a\n b', self.marshal(b' \ta\n\tb').expandtabs(1))
178-
179-
self.assertRaises(TypeError, self.marshal(b'hello').expandtabs, 42, 42)
180-
# This test is only valid when sizeof(int) == sizeof(void*) == 4.
181-
if sys.maxsize < (1 << 32) and struct.calcsize('P') == 4:
182-
self.assertRaises(OverflowError,
183-
self.marshal(b'\ta\n\tb').expandtabs, sys.maxsize)
184-
185143
def test_title(self):
186144
self.assertEqual(b' Hello ', self.marshal(b' hello ').title())
187145
self.assertEqual(b'Hello ', self.marshal(b'hello ').title())

Lib/test/string_tests.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Common tests shared by test_unicode, test_userstring and test_string.
2+
Common tests shared by test_unicode, test_userstring and test_bytes.
33
"""
44

55
import unittest, string, sys, struct
@@ -686,8 +686,7 @@ def test_replace_overflow(self):
686686

687687
class CommonTest(BaseTest):
688688
# This testcase contains tests that can be used in all
689-
# stringlike classes. Currently this is str, unicode
690-
# UserString and the string module.
689+
# stringlike classes. Currently this is str and UserString.
691690

692691
def test_hash(self):
693692
# SF bug 1054139: += optimization was not invalidating cached hash value
@@ -857,8 +856,7 @@ def test_zfill(self):
857856

858857
class MixinStrUnicodeUserStringTest:
859858
# additional tests that only work for
860-
# stringlike objects, i.e. str, unicode, UserString
861-
# (but not the string module)
859+
# stringlike objects, i.e. str, UserString
862860

863861
def test_islower(self):
864862
self.checkequal(False, '', 'islower')
@@ -1343,7 +1341,7 @@ def test_find_etc_raise_correct_error_messages(self):
13431341

13441342

13451343
class MixinStrUnicodeTest:
1346-
# Additional tests that only work with str and unicode.
1344+
# Additional tests that only work with str.
13471345

13481346
def test_bug1001011(self):
13491347
# Make sure join returns a NEW object for single item sequences

Lib/test/test_bytes.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,24 +1467,11 @@ def test_returns_new_copy(self):
14671467

14681468

14691469
class FixedStringTest(test.string_tests.BaseTest):
1470-
14711470
def fixtype(self, obj):
14721471
if isinstance(obj, str):
14731472
return obj.encode("utf-8")
14741473
return super().fixtype(obj)
14751474

1476-
# Currently the bytes containment testing uses a single integer
1477-
# value. This may not be the final design, but until then the
1478-
# bytes section with in a bytes containment not valid
1479-
def test_contains(self):
1480-
pass
1481-
def test_expandtabs(self):
1482-
pass
1483-
def test_upper(self):
1484-
pass
1485-
def test_lower(self):
1486-
pass
1487-
14881475
class ByteArrayAsStringTest(FixedStringTest, unittest.TestCase):
14891476
type2test = bytearray
14901477
contains_bytes = True

0 commit comments

Comments
 (0)