summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_getargs2.py
diff options
context:
space:
mode:
authorThomas Heller <theller@ctypes.org>2003-04-24 16:15:29 (GMT)
committerThomas Heller <theller@ctypes.org>2003-04-24 16:15:29 (GMT)
commit54aa5781d50adf2ab2168399c2f6d16ccff0a5aa (patch)
treed233851ff5844514ab7194c8f1726c47effdbb85 /Lib/test/test_getargs2.py
parent3457e4bd80fc2496bc3b9e1410365c97ee8dcb8f (diff)
downloadcpython-54aa5781d50adf2ab2168399c2f6d16ccff0a5aa.zip
cpython-54aa5781d50adf2ab2168399c2f6d16ccff0a5aa.tar.gz
cpython-54aa5781d50adf2ab2168399c2f6d16ccff0a5aa.tar.bz2
This test now uses the separate getargs_X functions from _testcapimodule.
Diffstat (limited to 'Lib/test/test_getargs2.py')
-rw-r--r--Lib/test/test_getargs2.py210
1 files changed, 109 insertions, 101 deletions
diff --git a/Lib/test/test_getargs2.py b/Lib/test/test_getargs2.py
index 0096c91..aaa64e0 100644
--- a/Lib/test/test_getargs2.py
+++ b/Lib/test/test_getargs2.py
@@ -3,7 +3,14 @@ from test import test_support
import sys
import warnings, re
-warnings.filterwarnings("ignore", category=DeprecationWarning, module=__name__)
+warnings.filterwarnings("ignore",
+ category=DeprecationWarning,
+ message=".*integer argument expected, got float",
+ module=__name__)
+warnings.filterwarnings("ignore",
+ category=DeprecationWarning,
+ message=".*integer argument expected, got float",
+ module="unittest")
"""
> How about the following counterproposal. This also changes some of
@@ -43,14 +50,6 @@ VERY_LARGE = 0xFF0000121212121212121242L
from _testcapi import UCHAR_MAX, USHRT_MAX, UINT_MAX, ULONG_MAX, INT_MAX, \
INT_MIN, LONG_MIN, LONG_MAX
-from _testcapi import getargs_ul as ul_convert
-from _testcapi import getargs_l as l_convert
-try:
- from _testcapi import getargs_ll as ll_convert
- from _testcapi import getargs_ull as ull_convert
-except ImportError:
- pass
-
# fake, they are not defined in Python's header files
LLONG_MAX = 2**63-1
LLONG_MIN = -2**63
@@ -66,119 +65,127 @@ class Int:
class Unsigned_TestCase(unittest.TestCase):
def test_b(self):
+ from _testcapi import getargs_b
# b returns 'unsigned char', and does range checking (0 ... UCHAR_MAX)
- self.failUnlessEqual(3, ul_convert("b", 3.14))
- self.failUnlessEqual(99, ul_convert("b", Long()))
- self.failUnlessEqual(99, ul_convert("b", Int()))
+ self.failUnlessEqual(3, getargs_b(3.14))
+ self.failUnlessEqual(99, getargs_b(Long()))
+ self.failUnlessEqual(99, getargs_b(Int()))
- self.assertRaises(OverflowError, ul_convert, "b", -1)
- self.failUnlessEqual(0, ul_convert("b", 0))
- self.failUnlessEqual(UCHAR_MAX, ul_convert("b", UCHAR_MAX))
- self.assertRaises(OverflowError, ul_convert, "b", UCHAR_MAX + 1)
+ self.assertRaises(OverflowError, getargs_b, -1)
+ self.failUnlessEqual(0, getargs_b(0))
+ self.failUnlessEqual(UCHAR_MAX, getargs_b(UCHAR_MAX))
+ self.assertRaises(OverflowError, getargs_b, UCHAR_MAX + 1)
- self.failUnlessEqual(42, ul_convert("b", 42))
- self.failUnlessEqual(42, ul_convert("b", 42L))
- self.assertRaises(OverflowError, ul_convert, "b", VERY_LARGE)
+ self.failUnlessEqual(42, getargs_b(42))
+ self.failUnlessEqual(42, getargs_b(42L))
+ self.assertRaises(OverflowError, getargs_b, VERY_LARGE)
def test_B(self):
+ from _testcapi import getargs_B
# B returns 'unsigned char', no range checking
- self.failUnless(3 == ul_convert("B", 3.14))
- self.failUnlessEqual(99, ul_convert("B", Long()))
- self.failUnlessEqual(99, ul_convert("B", Int()))
+ self.failUnlessEqual(3, getargs_B(3.14))
+ self.failUnlessEqual(99, getargs_B(Long()))
+ self.failUnlessEqual(99, getargs_B(Int()))
- self.failUnlessEqual(UCHAR_MAX, ul_convert("B", -1))
- self.failUnlessEqual(UCHAR_MAX, ul_convert("B", -1L))
- self.failUnlessEqual(0, ul_convert("B", 0))
- self.failUnlessEqual(UCHAR_MAX, ul_convert("B", UCHAR_MAX))
- self.failUnlessEqual(0, ul_convert("B", UCHAR_MAX+1))
+ self.failUnlessEqual(UCHAR_MAX, getargs_B(-1))
+ self.failUnlessEqual(UCHAR_MAX, getargs_B(-1L))
+ self.failUnlessEqual(0, getargs_B(0))
+ self.failUnlessEqual(UCHAR_MAX, getargs_B(UCHAR_MAX))
+ self.failUnlessEqual(0, getargs_B(UCHAR_MAX+1))
- self.failUnlessEqual(42, ul_convert("B", 42))
- self.failUnlessEqual(42, ul_convert("B", 42L))
- self.failUnlessEqual(UCHAR_MAX & VERY_LARGE, ul_convert("B", VERY_LARGE))
+ self.failUnlessEqual(42, getargs_B(42))
+ self.failUnlessEqual(42, getargs_B(42L))
+ self.failUnlessEqual(UCHAR_MAX & VERY_LARGE, getargs_B(VERY_LARGE))
def test_H(self):
+ from _testcapi import getargs_H
# H returns 'unsigned short', no range checking
- self.failUnlessEqual(3, ul_convert("H", 3.14))
- self.failUnlessEqual(99, ul_convert("H", Long()))
- self.failUnlessEqual(99, ul_convert("H", Int()))
+ self.failUnlessEqual(3, getargs_H(3.14))
+ self.failUnlessEqual(99, getargs_H(Long()))
+ self.failUnlessEqual(99, getargs_H(Int()))
- self.failUnlessEqual(USHRT_MAX, ul_convert("H", -1))
- self.failUnlessEqual(0, ul_convert("H", 0))
- self.failUnlessEqual(USHRT_MAX, ul_convert("H", USHRT_MAX))
- self.failUnlessEqual(0, ul_convert("H", USHRT_MAX+1))
+ self.failUnlessEqual(USHRT_MAX, getargs_H(-1))
+ self.failUnlessEqual(0, getargs_H(0))
+ self.failUnlessEqual(USHRT_MAX, getargs_H(USHRT_MAX))
+ self.failUnlessEqual(0, getargs_H(USHRT_MAX+1))
- self.failUnlessEqual(42, ul_convert("H", 42))
- self.failUnlessEqual(42, ul_convert("H", 42L))
+ self.failUnlessEqual(42, getargs_H(42))
+ self.failUnlessEqual(42, getargs_H(42L))
- self.failUnlessEqual(VERY_LARGE & USHRT_MAX, ul_convert("H", VERY_LARGE))
+ self.failUnlessEqual(VERY_LARGE & USHRT_MAX, getargs_H(VERY_LARGE))
def test_I(self):
+ from _testcapi import getargs_I
# I returns 'unsigned int', no range checking
- self.failUnlessEqual(3, ul_convert("I", 3.14))
- self.failUnlessEqual(99, ul_convert("I", Long()))
- self.failUnlessEqual(99, ul_convert("I", Int()))
+ self.failUnlessEqual(3, getargs_I(3.14))
+ self.failUnlessEqual(99, getargs_I(Long()))
+ self.failUnlessEqual(99, getargs_I(Int()))
- self.failUnlessEqual(UINT_MAX, ul_convert("I", -1))
- self.failUnlessEqual(0, ul_convert("I", 0))
- self.failUnlessEqual(UINT_MAX, ul_convert("I", UINT_MAX))
- self.failUnlessEqual(0, ul_convert("I", UINT_MAX+1))
+ self.failUnlessEqual(UINT_MAX, getargs_I(-1))
+ self.failUnlessEqual(0, getargs_I(0))
+ self.failUnlessEqual(UINT_MAX, getargs_I(UINT_MAX))
+ self.failUnlessEqual(0, getargs_I(UINT_MAX+1))
- self.failUnlessEqual(42, ul_convert("I", 42))
- self.failUnlessEqual(42, ul_convert("I", 42L))
+ self.failUnlessEqual(42, getargs_I(42))
+ self.failUnlessEqual(42, getargs_I(42L))
- self.failUnlessEqual(VERY_LARGE & UINT_MAX, ul_convert("I", VERY_LARGE))
+ self.failUnlessEqual(VERY_LARGE & UINT_MAX, getargs_I(VERY_LARGE))
def test_k(self):
+ from _testcapi import getargs_k
# k returns 'unsigned long', no range checking
# it does not accept float, or instances with __int__
- self.assertRaises(TypeError, ul_convert, "k", 3.14)
- self.assertRaises(TypeError, ul_convert, "k", Long())
- self.assertRaises(TypeError, ul_convert, "k", Int())
+ self.assertRaises(TypeError, getargs_k, 3.14)
+ self.assertRaises(TypeError, getargs_k, Long())
+ self.assertRaises(TypeError, getargs_k, Int())
- self.failUnlessEqual(ULONG_MAX, ul_convert("k", -1))
- self.failUnlessEqual(0, ul_convert("k", 0))
- self.failUnlessEqual(ULONG_MAX, ul_convert("k", ULONG_MAX))
- self.failUnlessEqual(0, ul_convert("k", ULONG_MAX+1))
+ self.failUnlessEqual(ULONG_MAX, getargs_k(-1))
+ self.failUnlessEqual(0, getargs_k(0))
+ self.failUnlessEqual(ULONG_MAX, getargs_k(ULONG_MAX))
+ self.failUnlessEqual(0, getargs_k(ULONG_MAX+1))
- self.failUnlessEqual(42, ul_convert("k", 42))
- self.failUnlessEqual(42, ul_convert("k", 42L))
+ self.failUnlessEqual(42, getargs_k(42))
+ self.failUnlessEqual(42, getargs_k(42L))
- self.failUnlessEqual(VERY_LARGE & ULONG_MAX, ul_convert("k", VERY_LARGE))
+ self.failUnlessEqual(VERY_LARGE & ULONG_MAX, getargs_k(VERY_LARGE))
class Signed_TestCase(unittest.TestCase):
def test_i(self):
+ from _testcapi import getargs_i
# i returns 'int', and does range checking (INT_MIN ... INT_MAX)
- self.failUnlessEqual(3, l_convert("i", 3.14))
- self.failUnlessEqual(99, l_convert("i", Long()))
- self.failUnlessEqual(99, l_convert("i", Int()))
+ self.failUnlessEqual(3, getargs_i(3.14))
+ self.failUnlessEqual(99, getargs_i(Long()))
+ self.failUnlessEqual(99, getargs_i(Int()))
- self.assertRaises(OverflowError, l_convert, "i", INT_MIN-1)
- self.failUnlessEqual(INT_MIN, l_convert("i", INT_MIN))
- self.failUnlessEqual(INT_MAX, l_convert("i", INT_MAX))
- self.assertRaises(OverflowError, l_convert, "i", INT_MAX+1)
+ self.assertRaises(OverflowError, getargs_i, INT_MIN-1)
+ self.failUnlessEqual(INT_MIN, getargs_i(INT_MIN))
+ self.failUnlessEqual(INT_MAX, getargs_i(INT_MAX))
+ self.assertRaises(OverflowError, getargs_i, INT_MAX+1)
- self.failUnlessEqual(42, l_convert("i", 42))
- self.failUnlessEqual(42, l_convert("i", 42L))
- self.assertRaises(OverflowError, l_convert, "i", VERY_LARGE)
+ self.failUnlessEqual(42, getargs_i(42))
+ self.failUnlessEqual(42, getargs_i(42L))
+ self.assertRaises(OverflowError, getargs_i, VERY_LARGE)
def test_l(self):
+ from _testcapi import getargs_l
# l returns 'long', and does range checking (LONG_MIN ... LONG_MAX)
- self.failUnlessEqual(3, l_convert("l", 3.14))
- self.failUnlessEqual(99, l_convert("l", Long()))
- self.failUnlessEqual(99, l_convert("l", Int()))
+ self.failUnlessEqual(3, getargs_l(3.14))
+ self.failUnlessEqual(99, getargs_l(Long()))
+ self.failUnlessEqual(99, getargs_l(Int()))
- self.assertRaises(OverflowError, l_convert, "l", LONG_MIN-1)
- self.failUnlessEqual(LONG_MIN, l_convert("l", LONG_MIN))
- self.failUnlessEqual(LONG_MAX, l_convert("l", LONG_MAX))
- self.assertRaises(OverflowError, l_convert, "l", LONG_MAX+1)
+ self.assertRaises(OverflowError, getargs_l, LONG_MIN-1)
+ self.failUnlessEqual(LONG_MIN, getargs_l(LONG_MIN))
+ self.failUnlessEqual(LONG_MAX, getargs_l(LONG_MAX))
+ self.assertRaises(OverflowError, getargs_l, LONG_MAX+1)
- self.failUnlessEqual(42, l_convert("l", 42))
- self.failUnlessEqual(42, l_convert("l", 42L))
- self.assertRaises(OverflowError, l_convert, "l", VERY_LARGE)
+ self.failUnlessEqual(42, getargs_l(42))
+ self.failUnlessEqual(42, getargs_l(42L))
+ self.assertRaises(OverflowError, getargs_l, VERY_LARGE)
class LongLong_TestCase(unittest.TestCase):
def test_L(self):
+ from _testcapi import getargs_L
# L returns 'long long', and does range checking (LLONG_MIN ... LLONG_MAX)
# XXX There's a bug in getargs.c, format code "L":
@@ -187,40 +194,41 @@ class LongLong_TestCase(unittest.TestCase):
# So these three tests are commented out:
-## self.failUnlessEqual(3, ll_convert("L", 3.14))
-## self.failUnlessEqual(99, ll_convert("L", Long()))
-## self.failUnlessEqual(99, ll_convert("L", Int()))
+## self.failUnlessEqual(3, getargs_L(3.14))
+## self.failUnlessEqual(99, getargs_L(Long()))
+## self.failUnlessEqual(99, getargs_L(Int()))
- self.assertRaises(OverflowError, ll_convert, "L", LLONG_MIN-1)
- self.failUnlessEqual(LLONG_MIN, ll_convert("L", LLONG_MIN))
- self.failUnlessEqual(LLONG_MAX, ll_convert("L", LLONG_MAX))
- self.assertRaises(OverflowError, ll_convert, "L", LLONG_MAX+1)
+ self.assertRaises(OverflowError, getargs_L, LLONG_MIN-1)
+ self.failUnlessEqual(LLONG_MIN, getargs_L(LLONG_MIN))
+ self.failUnlessEqual(LLONG_MAX, getargs_L(LLONG_MAX))
+ self.assertRaises(OverflowError, getargs_L, LLONG_MAX+1)
- self.failUnlessEqual(42, ll_convert("L", 42))
- self.failUnlessEqual(42, ll_convert("L", 42L))
- self.assertRaises(OverflowError, ll_convert, "L", VERY_LARGE)
+ self.failUnlessEqual(42, getargs_L(42))
+ self.failUnlessEqual(42, getargs_L(42L))
+ self.assertRaises(OverflowError, getargs_L, VERY_LARGE)
def test_K(self):
+ from _testcapi import getargs_K
# K return 'unsigned long long', no range checking
- self.assertRaises(TypeError, ull_convert, "K", 3.14)
- self.assertRaises(TypeError, ull_convert, "K", Long())
- self.assertRaises(TypeError, ull_convert, "K", Int())
- self.failUnlessEqual(ULLONG_MAX, ull_convert("K", ULLONG_MAX))
- self.failUnlessEqual(0, ull_convert("K", 0))
- self.failUnlessEqual(0, ull_convert("K", ULLONG_MAX+1))
+ self.assertRaises(TypeError, getargs_K, 3.14)
+ self.assertRaises(TypeError, getargs_K, Long())
+ self.assertRaises(TypeError, getargs_K, Int())
+ self.failUnlessEqual(ULLONG_MAX, getargs_K(ULLONG_MAX))
+ self.failUnlessEqual(0, getargs_K(0))
+ self.failUnlessEqual(0, getargs_K(ULLONG_MAX+1))
- self.failUnlessEqual(42, ull_convert("K", 42))
- self.failUnlessEqual(42, ull_convert("K", 42L))
+ self.failUnlessEqual(42, getargs_K(42))
+ self.failUnlessEqual(42, getargs_K(42L))
- self.failUnlessEqual(VERY_LARGE & ULLONG_MAX, ull_convert("K", VERY_LARGE))
+ self.failUnlessEqual(VERY_LARGE & ULLONG_MAX, getargs_K(VERY_LARGE))
def test_main():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(Signed_TestCase))
suite.addTest(unittest.makeSuite(Unsigned_TestCase))
try:
- ll_convert
- except NameError:
+ from _testcapi import getargs_L, getargs_K
+ except ImportError:
pass # PY_LONG_LONG not available
else:
suite.addTest(unittest.makeSuite(LongLong_TestCase))