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

Skip to content

Commit 0dceb56

Browse files
committed
#16910: test_bytes, test_unicode, and test_userstring now work with unittest test discovery. Patch by Zachary Ware.
1 parent 2688e81 commit 0dceb56

5 files changed

Lines changed: 19 additions & 25 deletions

File tree

Lib/test/string_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class BadSeq2(Sequence):
1919
def __init__(self): self.seq = ['a', 'b', 'c']
2020
def __len__(self): return 8
2121

22-
class BaseTest(unittest.TestCase):
22+
class BaseTest:
2323
# These tests are for buffers of values (bytes) and not
2424
# specific to character interpretation, used for bytes objects
2525
# and various string implementations

Lib/test/test_bytes.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def __index__(self):
3838
return self.value
3939

4040

41-
class BaseBytesTest(unittest.TestCase):
41+
class BaseBytesTest:
4242

4343
def test_basics(self):
4444
b = self.type2test()
@@ -682,7 +682,7 @@ def test_find_etc_raise_correct_error_messages(self):
682682
x, None, None, None)
683683

684684

685-
class BytesTest(BaseBytesTest):
685+
class BytesTest(BaseBytesTest, unittest.TestCase):
686686
type2test = bytes
687687

688688
def test_buffer_is_readonly(self):
@@ -730,7 +730,7 @@ def test_from_format(self):
730730
b's:cstr')
731731

732732

733-
class ByteArrayTest(BaseBytesTest):
733+
class ByteArrayTest(BaseBytesTest, unittest.TestCase):
734734
type2test = bytearray
735735

736736
def test_nohash(self):
@@ -1293,16 +1293,16 @@ def test_upper(self):
12931293
def test_lower(self):
12941294
pass
12951295

1296-
class ByteArrayAsStringTest(FixedStringTest):
1296+
class ByteArrayAsStringTest(FixedStringTest, unittest.TestCase):
12971297
type2test = bytearray
12981298
contains_bytes = True
12991299

1300-
class BytesAsStringTest(FixedStringTest):
1300+
class BytesAsStringTest(FixedStringTest, unittest.TestCase):
13011301
type2test = bytes
13021302
contains_bytes = True
13031303

13041304

1305-
class SubclassTest(unittest.TestCase):
1305+
class SubclassTest:
13061306

13071307
def test_basic(self):
13081308
self.assertTrue(issubclass(self.subclass2test, self.type2test))
@@ -1374,7 +1374,7 @@ class ByteArraySubclass(bytearray):
13741374
class BytesSubclass(bytes):
13751375
pass
13761376

1377-
class ByteArraySubclassTest(SubclassTest):
1377+
class ByteArraySubclassTest(SubclassTest, unittest.TestCase):
13781378
type2test = bytearray
13791379
subclass2test = ByteArraySubclass
13801380

@@ -1389,16 +1389,10 @@ def __init__(me, newarg=1, *args, **kwargs):
13891389
self.assertEqual(x, b"abcd")
13901390

13911391

1392-
class BytesSubclassTest(SubclassTest):
1392+
class BytesSubclassTest(SubclassTest, unittest.TestCase):
13931393
type2test = bytes
13941394
subclass2test = BytesSubclass
13951395

13961396

1397-
def test_main():
1398-
test.support.run_unittest(
1399-
BytesTest, AssortedBytesTest, BytesAsStringTest,
1400-
ByteArrayTest, ByteArrayAsStringTest, BytesSubclassTest,
1401-
ByteArraySubclassTest, BytearrayPEP3137Test)
1402-
14031397
if __name__ == "__main__":
1404-
test_main()
1398+
unittest.main()

Lib/test/test_unicode.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def decode2(input, errors="strict"):
3333

3434
class UnicodeTest(string_tests.CommonTest,
3535
string_tests.MixinStrUnicodeUserStringTest,
36-
string_tests.MixinStrUnicodeTest):
36+
string_tests.MixinStrUnicodeTest,
37+
unittest.TestCase):
3738

3839
type2test = str
3940

@@ -2218,8 +2219,5 @@ def split(name):
22182219
self.assertRaises(TypeError, _string.formatter_field_name_split, 1)
22192220

22202221

2221-
def test_main():
2222-
support.run_unittest(__name__)
2223-
22242222
if __name__ == "__main__":
2225-
test_main()
2223+
unittest.main()

Lib/test/test_userstring.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
# UserString instances should behave similar to builtin string objects.
44

55
import string
6+
import unittest
67
from test import support, string_tests
78

89
from collections import UserString
910

1011
class UserStringTest(
1112
string_tests.CommonTest,
1213
string_tests.MixinStrUnicodeUserStringTest,
14+
unittest.TestCase
1315
):
1416

1517
type2test = UserString
@@ -42,8 +44,5 @@ def checkcall(self, object, methodname, *args):
4244
getattr(object, methodname)(*args)
4345

4446

45-
def test_main():
46-
support.run_unittest(UserStringTest)
47-
4847
if __name__ == "__main__":
49-
test_main()
48+
unittest.main()

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,9 @@ Library
408408
Tests
409409
-----
410410

411+
- Issue #16910: test_bytes, test_unicode, and test_userstring now work with
412+
unittest test discovery. Patch by Zachary Ware.
413+
411414
- Issue #16905: test_warnings now works with unittest test discovery.
412415
Initial patch by Berker Peksag.
413416

0 commit comments

Comments
 (0)