mirror of
https://github.com/python/cpython.git
synced 2025-11-01 06:01:29 +00:00
#16888: test_array now works with unittest test discovery. Patch by Zachary Ware.
This commit is contained in:
parent
47236db1d0
commit
1d3e96dbe2
2 changed files with 18 additions and 49 deletions
|
|
@ -31,7 +31,6 @@ class ArraySubclassWithKwargs(array.array):
|
||||||
def __init__(self, typecode, newarg=None):
|
def __init__(self, typecode, newarg=None):
|
||||||
array.array.__init__(self)
|
array.array.__init__(self)
|
||||||
|
|
||||||
tests = [] # list to accumulate all tests
|
|
||||||
typecodes = "ubBhHiIlLfd"
|
typecodes = "ubBhHiIlLfd"
|
||||||
if have_long_long:
|
if have_long_long:
|
||||||
typecodes += 'qQ'
|
typecodes += 'qQ'
|
||||||
|
|
@ -44,7 +43,6 @@ def test_constructor(self):
|
||||||
self.assertRaises(TypeError, array.array, 'xx')
|
self.assertRaises(TypeError, array.array, 'xx')
|
||||||
self.assertRaises(ValueError, array.array, 'x')
|
self.assertRaises(ValueError, array.array, 'x')
|
||||||
|
|
||||||
tests.append(BadConstructorTest)
|
|
||||||
|
|
||||||
# Machine format codes.
|
# Machine format codes.
|
||||||
#
|
#
|
||||||
|
|
@ -174,10 +172,7 @@ def test_unicode(self):
|
||||||
msg="{0!r} != {1!r}; testcase={2!r}".format(a, b, testcase))
|
msg="{0!r} != {1!r}; testcase={2!r}".format(a, b, testcase))
|
||||||
|
|
||||||
|
|
||||||
tests.append(ArrayReconstructorTest)
|
class BaseTest:
|
||||||
|
|
||||||
|
|
||||||
class BaseTest(unittest.TestCase):
|
|
||||||
# Required class attributes (provided by subclasses
|
# Required class attributes (provided by subclasses
|
||||||
# typecode: the typecode to test
|
# typecode: the typecode to test
|
||||||
# example: an initializer usable in the constructor for this type
|
# example: an initializer usable in the constructor for this type
|
||||||
|
|
@ -1036,7 +1031,7 @@ def test_setitem(self):
|
||||||
a = array.array(self.typecode, self.example)
|
a = array.array(self.typecode, self.example)
|
||||||
self.assertRaises(TypeError, a.__setitem__, 0, self.example[:2])
|
self.assertRaises(TypeError, a.__setitem__, 0, self.example[:2])
|
||||||
|
|
||||||
class UnicodeTest(StringTest):
|
class UnicodeTest(StringTest, unittest.TestCase):
|
||||||
typecode = 'u'
|
typecode = 'u'
|
||||||
example = '\x01\u263a\x00\ufeff'
|
example = '\x01\u263a\x00\ufeff'
|
||||||
smallerexample = '\x01\u263a\x00\ufefe'
|
smallerexample = '\x01\u263a\x00\ufefe'
|
||||||
|
|
@ -1074,8 +1069,6 @@ def test_unicode(self):
|
||||||
|
|
||||||
self.assertRaises(TypeError, a.fromunicode)
|
self.assertRaises(TypeError, a.fromunicode)
|
||||||
|
|
||||||
tests.append(UnicodeTest)
|
|
||||||
|
|
||||||
class NumberTest(BaseTest):
|
class NumberTest(BaseTest):
|
||||||
|
|
||||||
def test_extslice(self):
|
def test_extslice(self):
|
||||||
|
|
@ -1216,57 +1209,47 @@ def test_bytes_extend(self):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ByteTest(SignedNumberTest):
|
class ByteTest(SignedNumberTest, unittest.TestCase):
|
||||||
typecode = 'b'
|
typecode = 'b'
|
||||||
minitemsize = 1
|
minitemsize = 1
|
||||||
tests.append(ByteTest)
|
|
||||||
|
|
||||||
class UnsignedByteTest(UnsignedNumberTest):
|
class UnsignedByteTest(UnsignedNumberTest, unittest.TestCase):
|
||||||
typecode = 'B'
|
typecode = 'B'
|
||||||
minitemsize = 1
|
minitemsize = 1
|
||||||
tests.append(UnsignedByteTest)
|
|
||||||
|
|
||||||
class ShortTest(SignedNumberTest):
|
class ShortTest(SignedNumberTest, unittest.TestCase):
|
||||||
typecode = 'h'
|
typecode = 'h'
|
||||||
minitemsize = 2
|
minitemsize = 2
|
||||||
tests.append(ShortTest)
|
|
||||||
|
|
||||||
class UnsignedShortTest(UnsignedNumberTest):
|
class UnsignedShortTest(UnsignedNumberTest, unittest.TestCase):
|
||||||
typecode = 'H'
|
typecode = 'H'
|
||||||
minitemsize = 2
|
minitemsize = 2
|
||||||
tests.append(UnsignedShortTest)
|
|
||||||
|
|
||||||
class IntTest(SignedNumberTest):
|
class IntTest(SignedNumberTest, unittest.TestCase):
|
||||||
typecode = 'i'
|
typecode = 'i'
|
||||||
minitemsize = 2
|
minitemsize = 2
|
||||||
tests.append(IntTest)
|
|
||||||
|
|
||||||
class UnsignedIntTest(UnsignedNumberTest):
|
class UnsignedIntTest(UnsignedNumberTest, unittest.TestCase):
|
||||||
typecode = 'I'
|
typecode = 'I'
|
||||||
minitemsize = 2
|
minitemsize = 2
|
||||||
tests.append(UnsignedIntTest)
|
|
||||||
|
|
||||||
class LongTest(SignedNumberTest):
|
class LongTest(SignedNumberTest, unittest.TestCase):
|
||||||
typecode = 'l'
|
typecode = 'l'
|
||||||
minitemsize = 4
|
minitemsize = 4
|
||||||
tests.append(LongTest)
|
|
||||||
|
|
||||||
class UnsignedLongTest(UnsignedNumberTest):
|
class UnsignedLongTest(UnsignedNumberTest, unittest.TestCase):
|
||||||
typecode = 'L'
|
typecode = 'L'
|
||||||
minitemsize = 4
|
minitemsize = 4
|
||||||
tests.append(UnsignedLongTest)
|
|
||||||
|
|
||||||
@unittest.skipIf(not have_long_long, 'need long long support')
|
@unittest.skipIf(not have_long_long, 'need long long support')
|
||||||
class LongLongTest(SignedNumberTest):
|
class LongLongTest(SignedNumberTest, unittest.TestCase):
|
||||||
typecode = 'q'
|
typecode = 'q'
|
||||||
minitemsize = 8
|
minitemsize = 8
|
||||||
tests.append(LongLongTest)
|
|
||||||
|
|
||||||
@unittest.skipIf(not have_long_long, 'need long long support')
|
@unittest.skipIf(not have_long_long, 'need long long support')
|
||||||
class UnsignedLongLongTest(UnsignedNumberTest):
|
class UnsignedLongLongTest(UnsignedNumberTest, unittest.TestCase):
|
||||||
typecode = 'Q'
|
typecode = 'Q'
|
||||||
minitemsize = 8
|
minitemsize = 8
|
||||||
tests.append(UnsignedLongLongTest)
|
|
||||||
|
|
||||||
class FPTest(NumberTest):
|
class FPTest(NumberTest):
|
||||||
example = [-42.0, 0, 42, 1e5, -1e10]
|
example = [-42.0, 0, 42, 1e5, -1e10]
|
||||||
|
|
@ -1293,12 +1276,11 @@ def test_byteswap(self):
|
||||||
b.byteswap()
|
b.byteswap()
|
||||||
self.assertEqual(a, b)
|
self.assertEqual(a, b)
|
||||||
|
|
||||||
class FloatTest(FPTest):
|
class FloatTest(FPTest, unittest.TestCase):
|
||||||
typecode = 'f'
|
typecode = 'f'
|
||||||
minitemsize = 4
|
minitemsize = 4
|
||||||
tests.append(FloatTest)
|
|
||||||
|
|
||||||
class DoubleTest(FPTest):
|
class DoubleTest(FPTest, unittest.TestCase):
|
||||||
typecode = 'd'
|
typecode = 'd'
|
||||||
minitemsize = 8
|
minitemsize = 8
|
||||||
|
|
||||||
|
|
@ -1319,22 +1301,6 @@ def test_alloc_overflow(self):
|
||||||
else:
|
else:
|
||||||
self.fail("Array of size > maxsize created - MemoryError expected")
|
self.fail("Array of size > maxsize created - MemoryError expected")
|
||||||
|
|
||||||
tests.append(DoubleTest)
|
|
||||||
|
|
||||||
def test_main(verbose=None):
|
|
||||||
import sys
|
|
||||||
|
|
||||||
support.run_unittest(*tests)
|
|
||||||
|
|
||||||
# verify reference counting
|
|
||||||
if verbose and hasattr(sys, "gettotalrefcount"):
|
|
||||||
import gc
|
|
||||||
counts = [None] * 5
|
|
||||||
for i in range(len(counts)):
|
|
||||||
support.run_unittest(*tests)
|
|
||||||
gc.collect()
|
|
||||||
counts[i] = sys.gettotalrefcount()
|
|
||||||
print(counts)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_main(verbose=True)
|
unittest.main()
|
||||||
|
|
|
||||||
|
|
@ -408,6 +408,9 @@ Library
|
||||||
Tests
|
Tests
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
- Issue #16888: test_array now works with unittest test discovery.
|
||||||
|
Patch by Zachary Ware.
|
||||||
|
|
||||||
- Issue #16896: test_asyncore now works with unittest test discovery.
|
- Issue #16896: test_asyncore now works with unittest test discovery.
|
||||||
Patch by Zachary Ware.
|
Patch by Zachary Ware.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue