Commit 9118e19a authored by Ezio Melotti's avatar Ezio Melotti

#16910: test_bytes, test_unicode, and test_userstring now work with unittest...

#16910: test_bytes, test_unicode, and test_userstring now work with unittest test discovery.  Patch by Zachary Ware.
parent d1c3f4a0
...@@ -19,7 +19,7 @@ class BadSeq2(Sequence): ...@@ -19,7 +19,7 @@ class BadSeq2(Sequence):
def __init__(self): self.seq = ['a', 'b', 'c'] def __init__(self): self.seq = ['a', 'b', 'c']
def __len__(self): return 8 def __len__(self): return 8
class BaseTest(unittest.TestCase): class BaseTest:
# These tests are for buffers of values (bytes) and not # These tests are for buffers of values (bytes) and not
# specific to character interpretation, used for bytes objects # specific to character interpretation, used for bytes objects
# and various string implementations # and various string implementations
......
...@@ -38,7 +38,7 @@ class Indexable: ...@@ -38,7 +38,7 @@ class Indexable:
return self.value return self.value
class BaseBytesTest(unittest.TestCase): class BaseBytesTest:
def test_basics(self): def test_basics(self):
b = self.type2test() b = self.type2test()
...@@ -682,7 +682,7 @@ class BaseBytesTest(unittest.TestCase): ...@@ -682,7 +682,7 @@ class BaseBytesTest(unittest.TestCase):
x, None, None, None) x, None, None, None)
class BytesTest(BaseBytesTest): class BytesTest(BaseBytesTest, unittest.TestCase):
type2test = bytes type2test = bytes
def test_buffer_is_readonly(self): def test_buffer_is_readonly(self):
...@@ -730,7 +730,7 @@ class BytesTest(BaseBytesTest): ...@@ -730,7 +730,7 @@ class BytesTest(BaseBytesTest):
b's:cstr') b's:cstr')
class ByteArrayTest(BaseBytesTest): class ByteArrayTest(BaseBytesTest, unittest.TestCase):
type2test = bytearray type2test = bytearray
def test_nohash(self): def test_nohash(self):
...@@ -1293,16 +1293,16 @@ class FixedStringTest(test.string_tests.BaseTest): ...@@ -1293,16 +1293,16 @@ class FixedStringTest(test.string_tests.BaseTest):
def test_lower(self): def test_lower(self):
pass pass
class ByteArrayAsStringTest(FixedStringTest): class ByteArrayAsStringTest(FixedStringTest, unittest.TestCase):
type2test = bytearray type2test = bytearray
contains_bytes = True contains_bytes = True
class BytesAsStringTest(FixedStringTest): class BytesAsStringTest(FixedStringTest, unittest.TestCase):
type2test = bytes type2test = bytes
contains_bytes = True contains_bytes = True
class SubclassTest(unittest.TestCase): class SubclassTest:
def test_basic(self): def test_basic(self):
self.assertTrue(issubclass(self.subclass2test, self.type2test)) self.assertTrue(issubclass(self.subclass2test, self.type2test))
...@@ -1374,7 +1374,7 @@ class ByteArraySubclass(bytearray): ...@@ -1374,7 +1374,7 @@ class ByteArraySubclass(bytearray):
class BytesSubclass(bytes): class BytesSubclass(bytes):
pass pass
class ByteArraySubclassTest(SubclassTest): class ByteArraySubclassTest(SubclassTest, unittest.TestCase):
type2test = bytearray type2test = bytearray
subclass2test = ByteArraySubclass subclass2test = ByteArraySubclass
...@@ -1389,16 +1389,10 @@ class ByteArraySubclassTest(SubclassTest): ...@@ -1389,16 +1389,10 @@ class ByteArraySubclassTest(SubclassTest):
self.assertEqual(x, b"abcd") self.assertEqual(x, b"abcd")
class BytesSubclassTest(SubclassTest): class BytesSubclassTest(SubclassTest, unittest.TestCase):
type2test = bytes type2test = bytes
subclass2test = BytesSubclass subclass2test = BytesSubclass
def test_main():
test.support.run_unittest(
BytesTest, AssortedBytesTest, BytesAsStringTest,
ByteArrayTest, ByteArrayAsStringTest, BytesSubclassTest,
ByteArraySubclassTest, BytearrayPEP3137Test)
if __name__ == "__main__": if __name__ == "__main__":
test_main() unittest.main()
...@@ -33,7 +33,8 @@ codecs.register(search_function) ...@@ -33,7 +33,8 @@ codecs.register(search_function)
class UnicodeTest(string_tests.CommonTest, class UnicodeTest(string_tests.CommonTest,
string_tests.MixinStrUnicodeUserStringTest, string_tests.MixinStrUnicodeUserStringTest,
string_tests.MixinStrUnicodeTest): string_tests.MixinStrUnicodeTest,
unittest.TestCase):
type2test = str type2test = str
...@@ -2218,8 +2219,5 @@ class StringModuleTest(unittest.TestCase): ...@@ -2218,8 +2219,5 @@ class StringModuleTest(unittest.TestCase):
self.assertRaises(TypeError, _string.formatter_field_name_split, 1) self.assertRaises(TypeError, _string.formatter_field_name_split, 1)
def test_main():
support.run_unittest(__name__)
if __name__ == "__main__": if __name__ == "__main__":
test_main() unittest.main()
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# UserString instances should behave similar to builtin string objects. # UserString instances should behave similar to builtin string objects.
import string import string
import unittest
from test import support, string_tests from test import support, string_tests
from collections import UserString from collections import UserString
...@@ -10,6 +11,7 @@ from collections import UserString ...@@ -10,6 +11,7 @@ from collections import UserString
class UserStringTest( class UserStringTest(
string_tests.CommonTest, string_tests.CommonTest,
string_tests.MixinStrUnicodeUserStringTest, string_tests.MixinStrUnicodeUserStringTest,
unittest.TestCase
): ):
type2test = UserString type2test = UserString
...@@ -42,8 +44,5 @@ class UserStringTest( ...@@ -42,8 +44,5 @@ class UserStringTest(
getattr(object, methodname)(*args) getattr(object, methodname)(*args)
def test_main():
support.run_unittest(UserStringTest)
if __name__ == "__main__": if __name__ == "__main__":
test_main() unittest.main()
...@@ -408,6 +408,9 @@ Library ...@@ -408,6 +408,9 @@ Library
Tests Tests
----- -----
- Issue #16910: test_bytes, test_unicode, and test_userstring now work with
unittest test discovery. Patch by Zachary Ware.
- Issue #16905: test_warnings now works with unittest test discovery. - Issue #16905: test_warnings now works with unittest test discovery.
Initial patch by Berker Peksag. Initial patch by Berker Peksag.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment