2003-04-17 15:55:45 -03:00
|
|
|
import unittest
|
|
|
|
from test import test_support
|
2014-02-07 04:06:05 -04:00
|
|
|
# Skip this test if the _testcapi module isn't available.
|
|
|
|
test_support.import_module('_testcapi')
|
2008-02-26 13:23:51 -04:00
|
|
|
from _testcapi import getargs_keywords
|
2008-02-23 13:40:11 -04:00
|
|
|
import warnings
|
2003-04-17 15:55:45 -03:00
|
|
|
|
|
|
|
"""
|
|
|
|
> How about the following counterproposal. This also changes some of
|
|
|
|
> the other format codes to be a little more regular.
|
|
|
|
>
|
|
|
|
> Code C type Range check
|
|
|
|
>
|
|
|
|
> b unsigned char 0..UCHAR_MAX
|
2003-04-17 21:13:53 -03:00
|
|
|
> h signed short SHRT_MIN..SHRT_MAX
|
2003-04-17 15:55:45 -03:00
|
|
|
> B unsigned char none **
|
|
|
|
> H unsigned short none **
|
|
|
|
> k * unsigned long none
|
|
|
|
> I * unsigned int 0..UINT_MAX
|
|
|
|
|
|
|
|
|
|
|
|
> i int INT_MIN..INT_MAX
|
|
|
|
> l long LONG_MIN..LONG_MAX
|
|
|
|
|
|
|
|
> K * unsigned long long none
|
|
|
|
> L long long LLONG_MIN..LLONG_MAX
|
|
|
|
|
|
|
|
> Notes:
|
|
|
|
>
|
|
|
|
> * New format codes.
|
|
|
|
>
|
|
|
|
> ** Changed from previous "range-and-a-half" to "none"; the
|
|
|
|
> range-and-a-half checking wasn't particularly useful.
|
|
|
|
|
|
|
|
Plus a C API or two, e.g. PyInt_AsLongMask() ->
|
|
|
|
unsigned long and PyInt_AsLongLongMask() -> unsigned
|
|
|
|
long long (if that exists).
|
|
|
|
"""
|
|
|
|
|
|
|
|
LARGE = 0x7FFFFFFF
|
|
|
|
VERY_LARGE = 0xFF0000121212121212121242L
|
|
|
|
|
|
|
|
from _testcapi import UCHAR_MAX, USHRT_MAX, UINT_MAX, ULONG_MAX, INT_MAX, \
|
2009-12-20 11:57:56 -04:00
|
|
|
INT_MIN, LONG_MIN, LONG_MAX, PY_SSIZE_T_MIN, PY_SSIZE_T_MAX, \
|
|
|
|
SHRT_MIN, SHRT_MAX
|
2003-04-17 15:55:45 -03:00
|
|
|
|
2013-12-10 16:09:20 -04:00
|
|
|
try:
|
|
|
|
from _testcapi import getargs_L, getargs_K
|
|
|
|
except ImportError:
|
|
|
|
_PY_LONG_LONG_available = False
|
|
|
|
else:
|
|
|
|
_PY_LONG_LONG_available = True
|
|
|
|
|
2003-04-17 15:55:45 -03:00
|
|
|
# fake, they are not defined in Python's header files
|
|
|
|
LLONG_MAX = 2**63-1
|
|
|
|
LLONG_MIN = -2**63
|
|
|
|
ULLONG_MAX = 2**64-1
|
|
|
|
|
|
|
|
class Long:
|
|
|
|
def __int__(self):
|
|
|
|
return 99L
|
|
|
|
|
|
|
|
class Int:
|
|
|
|
def __int__(self):
|
|
|
|
return 99
|
|
|
|
|
|
|
|
class Unsigned_TestCase(unittest.TestCase):
|
|
|
|
def test_b(self):
|
2003-04-24 13:15:29 -03:00
|
|
|
from _testcapi import getargs_b
|
2003-04-17 15:55:45 -03:00
|
|
|
# b returns 'unsigned char', and does range checking (0 ... UCHAR_MAX)
|
2010-01-01 13:27:30 -04:00
|
|
|
self.assertRaises(TypeError, getargs_b, 3.14)
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertEqual(99, getargs_b(Long()))
|
|
|
|
self.assertEqual(99, getargs_b(Int()))
|
2003-04-17 15:55:45 -03:00
|
|
|
|
2003-04-24 13:15:29 -03:00
|
|
|
self.assertRaises(OverflowError, getargs_b, -1)
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertEqual(0, getargs_b(0))
|
|
|
|
self.assertEqual(UCHAR_MAX, getargs_b(UCHAR_MAX))
|
2003-04-24 13:15:29 -03:00
|
|
|
self.assertRaises(OverflowError, getargs_b, UCHAR_MAX + 1)
|
2003-04-17 15:55:45 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertEqual(42, getargs_b(42))
|
|
|
|
self.assertEqual(42, getargs_b(42L))
|
2003-04-24 13:15:29 -03:00
|
|
|
self.assertRaises(OverflowError, getargs_b, VERY_LARGE)
|
2003-04-17 15:55:45 -03:00
|
|
|
|
|
|
|
def test_B(self):
|
2003-04-24 13:15:29 -03:00
|
|
|
from _testcapi import getargs_B
|
2003-04-17 15:55:45 -03:00
|
|
|
# B returns 'unsigned char', no range checking
|
2010-01-01 13:27:30 -04:00
|
|
|
self.assertRaises(TypeError, getargs_B, 3.14)
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertEqual(99, getargs_B(Long()))
|
|
|
|
self.assertEqual(99, getargs_B(Int()))
|
2003-04-17 15:55:45 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertEqual(UCHAR_MAX, getargs_B(-1))
|
|
|
|
self.assertEqual(UCHAR_MAX, getargs_B(-1L))
|
|
|
|
self.assertEqual(0, getargs_B(0))
|
|
|
|
self.assertEqual(UCHAR_MAX, getargs_B(UCHAR_MAX))
|
|
|
|
self.assertEqual(0, getargs_B(UCHAR_MAX+1))
|
2003-04-17 15:55:45 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertEqual(42, getargs_B(42))
|
|
|
|
self.assertEqual(42, getargs_B(42L))
|
|
|
|
self.assertEqual(UCHAR_MAX & VERY_LARGE, getargs_B(VERY_LARGE))
|
2003-04-17 15:55:45 -03:00
|
|
|
|
|
|
|
def test_H(self):
|
2003-04-24 13:15:29 -03:00
|
|
|
from _testcapi import getargs_H
|
2003-04-17 15:55:45 -03:00
|
|
|
# H returns 'unsigned short', no range checking
|
2010-01-01 13:27:30 -04:00
|
|
|
self.assertRaises(TypeError, getargs_H, 3.14)
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertEqual(99, getargs_H(Long()))
|
|
|
|
self.assertEqual(99, getargs_H(Int()))
|
2003-04-17 15:55:45 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertEqual(USHRT_MAX, getargs_H(-1))
|
|
|
|
self.assertEqual(0, getargs_H(0))
|
|
|
|
self.assertEqual(USHRT_MAX, getargs_H(USHRT_MAX))
|
|
|
|
self.assertEqual(0, getargs_H(USHRT_MAX+1))
|
2003-04-17 15:55:45 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertEqual(42, getargs_H(42))
|
|
|
|
self.assertEqual(42, getargs_H(42L))
|
2003-04-17 15:55:45 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertEqual(VERY_LARGE & USHRT_MAX, getargs_H(VERY_LARGE))
|
2003-04-17 15:55:45 -03:00
|
|
|
|
|
|
|
def test_I(self):
|
2003-04-24 13:15:29 -03:00
|
|
|
from _testcapi import getargs_I
|
2003-04-17 15:55:45 -03:00
|
|
|
# I returns 'unsigned int', no range checking
|
2010-01-01 13:27:30 -04:00
|
|
|
self.assertRaises(TypeError, getargs_I, 3.14)
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertEqual(99, getargs_I(Long()))
|
|
|
|
self.assertEqual(99, getargs_I(Int()))
|
2003-04-17 15:55:45 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertEqual(UINT_MAX, getargs_I(-1))
|
|
|
|
self.assertEqual(0, getargs_I(0))
|
|
|
|
self.assertEqual(UINT_MAX, getargs_I(UINT_MAX))
|
|
|
|
self.assertEqual(0, getargs_I(UINT_MAX+1))
|
2003-04-17 15:55:45 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertEqual(42, getargs_I(42))
|
|
|
|
self.assertEqual(42, getargs_I(42L))
|
2003-04-17 15:55:45 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertEqual(VERY_LARGE & UINT_MAX, getargs_I(VERY_LARGE))
|
2003-04-17 15:55:45 -03:00
|
|
|
|
|
|
|
def test_k(self):
|
2003-04-24 13:15:29 -03:00
|
|
|
from _testcapi import getargs_k
|
2003-04-17 15:55:45 -03:00
|
|
|
# k returns 'unsigned long', no range checking
|
|
|
|
# it does not accept float, or instances with __int__
|
2003-04-24 13:15:29 -03:00
|
|
|
self.assertRaises(TypeError, getargs_k, 3.14)
|
|
|
|
self.assertRaises(TypeError, getargs_k, Long())
|
|
|
|
self.assertRaises(TypeError, getargs_k, Int())
|
2003-04-17 15:55:45 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertEqual(ULONG_MAX, getargs_k(-1))
|
|
|
|
self.assertEqual(0, getargs_k(0))
|
|
|
|
self.assertEqual(ULONG_MAX, getargs_k(ULONG_MAX))
|
|
|
|
self.assertEqual(0, getargs_k(ULONG_MAX+1))
|
2003-04-17 15:55:45 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertEqual(42, getargs_k(42))
|
|
|
|
self.assertEqual(42, getargs_k(42L))
|
2003-04-17 15:55:45 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertEqual(VERY_LARGE & ULONG_MAX, getargs_k(VERY_LARGE))
|
2003-04-17 15:55:45 -03:00
|
|
|
|
|
|
|
class Signed_TestCase(unittest.TestCase):
|
2009-12-20 11:57:56 -04:00
|
|
|
def test_h(self):
|
|
|
|
from _testcapi import getargs_h
|
|
|
|
# h returns 'short', and does range checking (SHRT_MIN ... SHRT_MAX)
|
2010-01-01 13:27:30 -04:00
|
|
|
self.assertRaises(TypeError, getargs_h, 3.14)
|
2009-12-20 11:57:56 -04:00
|
|
|
self.assertEqual(99, getargs_h(Long()))
|
|
|
|
self.assertEqual(99, getargs_h(Int()))
|
|
|
|
|
|
|
|
self.assertRaises(OverflowError, getargs_h, SHRT_MIN-1)
|
|
|
|
self.assertEqual(SHRT_MIN, getargs_h(SHRT_MIN))
|
|
|
|
self.assertEqual(SHRT_MAX, getargs_h(SHRT_MAX))
|
|
|
|
self.assertRaises(OverflowError, getargs_h, SHRT_MAX+1)
|
|
|
|
|
|
|
|
self.assertEqual(42, getargs_h(42))
|
|
|
|
self.assertEqual(42, getargs_h(42L))
|
|
|
|
self.assertRaises(OverflowError, getargs_h, VERY_LARGE)
|
|
|
|
|
2003-04-17 15:55:45 -03:00
|
|
|
def test_i(self):
|
2003-04-24 13:15:29 -03:00
|
|
|
from _testcapi import getargs_i
|
2003-04-17 15:55:45 -03:00
|
|
|
# i returns 'int', and does range checking (INT_MIN ... INT_MAX)
|
2010-01-01 13:27:30 -04:00
|
|
|
self.assertRaises(TypeError, getargs_i, 3.14)
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertEqual(99, getargs_i(Long()))
|
|
|
|
self.assertEqual(99, getargs_i(Int()))
|
2003-04-17 15:55:45 -03:00
|
|
|
|
2003-04-24 13:15:29 -03:00
|
|
|
self.assertRaises(OverflowError, getargs_i, INT_MIN-1)
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertEqual(INT_MIN, getargs_i(INT_MIN))
|
|
|
|
self.assertEqual(INT_MAX, getargs_i(INT_MAX))
|
2003-04-24 13:15:29 -03:00
|
|
|
self.assertRaises(OverflowError, getargs_i, INT_MAX+1)
|
2003-04-17 15:55:45 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertEqual(42, getargs_i(42))
|
|
|
|
self.assertEqual(42, getargs_i(42L))
|
2003-04-24 13:15:29 -03:00
|
|
|
self.assertRaises(OverflowError, getargs_i, VERY_LARGE)
|
2003-04-17 15:55:45 -03:00
|
|
|
|
|
|
|
def test_l(self):
|
2003-04-24 13:15:29 -03:00
|
|
|
from _testcapi import getargs_l
|
2003-04-17 15:55:45 -03:00
|
|
|
# l returns 'long', and does range checking (LONG_MIN ... LONG_MAX)
|
2010-01-01 13:27:30 -04:00
|
|
|
self.assertRaises(TypeError, getargs_l, 3.14)
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertEqual(99, getargs_l(Long()))
|
|
|
|
self.assertEqual(99, getargs_l(Int()))
|
2003-04-17 15:55:45 -03:00
|
|
|
|
2003-04-24 13:15:29 -03:00
|
|
|
self.assertRaises(OverflowError, getargs_l, LONG_MIN-1)
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertEqual(LONG_MIN, getargs_l(LONG_MIN))
|
|
|
|
self.assertEqual(LONG_MAX, getargs_l(LONG_MAX))
|
2003-04-24 13:15:29 -03:00
|
|
|
self.assertRaises(OverflowError, getargs_l, LONG_MAX+1)
|
2003-04-17 15:55:45 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertEqual(42, getargs_l(42))
|
|
|
|
self.assertEqual(42, getargs_l(42L))
|
2003-04-24 13:15:29 -03:00
|
|
|
self.assertRaises(OverflowError, getargs_l, VERY_LARGE)
|
2003-04-17 15:55:45 -03:00
|
|
|
|
2006-04-13 04:59:30 -03:00
|
|
|
def test_n(self):
|
|
|
|
from _testcapi import getargs_n
|
2006-04-13 19:58:42 -03:00
|
|
|
# n returns 'Py_ssize_t', and does range checking
|
2006-04-13 04:59:30 -03:00
|
|
|
# (PY_SSIZE_T_MIN ... PY_SSIZE_T_MAX)
|
2010-01-01 13:27:30 -04:00
|
|
|
self.assertRaises(TypeError, getargs_n, 3.14)
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertEqual(99, getargs_n(Long()))
|
|
|
|
self.assertEqual(99, getargs_n(Int()))
|
2006-04-13 04:59:30 -03:00
|
|
|
|
|
|
|
self.assertRaises(OverflowError, getargs_n, PY_SSIZE_T_MIN-1)
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertEqual(PY_SSIZE_T_MIN, getargs_n(PY_SSIZE_T_MIN))
|
|
|
|
self.assertEqual(PY_SSIZE_T_MAX, getargs_n(PY_SSIZE_T_MAX))
|
2006-04-13 04:59:30 -03:00
|
|
|
self.assertRaises(OverflowError, getargs_n, PY_SSIZE_T_MAX+1)
|
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertEqual(42, getargs_n(42))
|
|
|
|
self.assertEqual(42, getargs_n(42L))
|
2006-04-13 04:59:30 -03:00
|
|
|
self.assertRaises(OverflowError, getargs_n, VERY_LARGE)
|
|
|
|
|
2003-04-17 15:55:45 -03:00
|
|
|
|
2013-12-10 16:09:20 -04:00
|
|
|
@unittest.skipUnless(_PY_LONG_LONG_available, 'PY_LONG_LONG not available')
|
2003-04-17 15:55:45 -03:00
|
|
|
class LongLong_TestCase(unittest.TestCase):
|
|
|
|
def test_L(self):
|
2003-04-24 13:15:29 -03:00
|
|
|
from _testcapi import getargs_L
|
2010-01-01 13:27:30 -04:00
|
|
|
# L returns 'long long', and does range checking (LLONG_MIN
|
|
|
|
# ... LLONG_MAX)
|
|
|
|
with warnings.catch_warnings():
|
|
|
|
warnings.filterwarnings(
|
|
|
|
"ignore",
|
|
|
|
category=DeprecationWarning,
|
|
|
|
message=".*integer argument expected, got float",
|
|
|
|
module=__name__)
|
|
|
|
self.assertEqual(3, getargs_L(3.14))
|
|
|
|
with warnings.catch_warnings():
|
|
|
|
warnings.filterwarnings(
|
|
|
|
"error",
|
|
|
|
category=DeprecationWarning,
|
|
|
|
message=".*integer argument expected, got float",
|
|
|
|
module="unittest")
|
|
|
|
self.assertRaises(DeprecationWarning, getargs_L, 3.14)
|
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertRaises(TypeError, getargs_L, "Hello")
|
|
|
|
self.assertEqual(99, getargs_L(Long()))
|
|
|
|
self.assertEqual(99, getargs_L(Int()))
|
2003-04-17 15:55:45 -03:00
|
|
|
|
2003-04-24 13:15:29 -03:00
|
|
|
self.assertRaises(OverflowError, getargs_L, LLONG_MIN-1)
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertEqual(LLONG_MIN, getargs_L(LLONG_MIN))
|
|
|
|
self.assertEqual(LLONG_MAX, getargs_L(LLONG_MAX))
|
2003-04-24 13:15:29 -03:00
|
|
|
self.assertRaises(OverflowError, getargs_L, LLONG_MAX+1)
|
2003-04-17 15:55:45 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertEqual(42, getargs_L(42))
|
|
|
|
self.assertEqual(42, getargs_L(42L))
|
2003-04-24 13:15:29 -03:00
|
|
|
self.assertRaises(OverflowError, getargs_L, VERY_LARGE)
|
2003-04-24 13:02:54 -03:00
|
|
|
|
2003-04-17 15:55:45 -03:00
|
|
|
def test_K(self):
|
2003-04-24 13:15:29 -03:00
|
|
|
from _testcapi import getargs_K
|
2003-04-17 15:55:45 -03:00
|
|
|
# K return 'unsigned long long', no range checking
|
2003-04-24 13:15:29 -03:00
|
|
|
self.assertRaises(TypeError, getargs_K, 3.14)
|
|
|
|
self.assertRaises(TypeError, getargs_K, Long())
|
|
|
|
self.assertRaises(TypeError, getargs_K, Int())
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertEqual(ULLONG_MAX, getargs_K(ULLONG_MAX))
|
|
|
|
self.assertEqual(0, getargs_K(0))
|
|
|
|
self.assertEqual(0, getargs_K(ULLONG_MAX+1))
|
2003-04-17 15:55:45 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertEqual(42, getargs_K(42))
|
|
|
|
self.assertEqual(42, getargs_K(42L))
|
2003-04-17 15:55:45 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertEqual(VERY_LARGE & ULLONG_MAX, getargs_K(VERY_LARGE))
|
2003-04-17 15:55:45 -03:00
|
|
|
|
2006-07-26 05:03:10 -03:00
|
|
|
|
|
|
|
class Tuple_TestCase(unittest.TestCase):
|
|
|
|
def test_tuple(self):
|
|
|
|
from _testcapi import getargs_tuple
|
2006-07-26 20:23:15 -03:00
|
|
|
|
2006-07-26 05:03:10 -03:00
|
|
|
ret = getargs_tuple(1, (2, 3))
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(ret, (1,2,3))
|
2006-07-26 05:03:10 -03:00
|
|
|
|
|
|
|
# make sure invalid tuple arguments are handled correctly
|
|
|
|
class seq:
|
|
|
|
def __len__(self):
|
|
|
|
return 2
|
|
|
|
def __getitem__(self, n):
|
|
|
|
raise ValueError
|
|
|
|
self.assertRaises(TypeError, getargs_tuple, 1, seq())
|
|
|
|
|
2008-02-26 13:23:51 -04:00
|
|
|
class Keywords_TestCase(unittest.TestCase):
|
|
|
|
def test_positional_args(self):
|
|
|
|
# using all positional args
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(
|
2008-02-26 13:23:51 -04:00
|
|
|
getargs_keywords((1,2), 3, (4,(5,6)), (7,8,9), 10),
|
|
|
|
(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
|
|
|
|
)
|
|
|
|
def test_mixed_args(self):
|
|
|
|
# positional and keyword args
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(
|
2008-02-26 13:23:51 -04:00
|
|
|
getargs_keywords((1,2), 3, (4,(5,6)), arg4=(7,8,9), arg5=10),
|
|
|
|
(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
|
|
|
|
)
|
|
|
|
def test_keyword_args(self):
|
|
|
|
# all keywords
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(
|
2008-02-26 13:23:51 -04:00
|
|
|
getargs_keywords(arg1=(1,2), arg2=3, arg3=(4,(5,6)), arg4=(7,8,9), arg5=10),
|
|
|
|
(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
|
|
|
|
)
|
|
|
|
def test_optional_args(self):
|
|
|
|
# missing optional keyword args, skipping tuples
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(
|
2008-02-26 13:23:51 -04:00
|
|
|
getargs_keywords(arg1=(1,2), arg2=3, arg5=10),
|
|
|
|
(1, 2, 3, -1, -1, -1, -1, -1, -1, 10)
|
|
|
|
)
|
|
|
|
def test_required_args(self):
|
|
|
|
# required arg missing
|
|
|
|
try:
|
|
|
|
getargs_keywords(arg1=(1,2))
|
|
|
|
except TypeError, err:
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(str(err), "Required argument 'arg2' (pos 2) not found")
|
2008-02-26 13:23:51 -04:00
|
|
|
else:
|
|
|
|
self.fail('TypeError should have been raised')
|
|
|
|
def test_too_many_args(self):
|
|
|
|
try:
|
|
|
|
getargs_keywords((1,2),3,(4,(5,6)),(7,8,9),10,111)
|
|
|
|
except TypeError, err:
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(str(err), "function takes at most 5 arguments (6 given)")
|
2008-02-26 13:23:51 -04:00
|
|
|
else:
|
|
|
|
self.fail('TypeError should have been raised')
|
|
|
|
def test_invalid_keyword(self):
|
|
|
|
# extraneous keyword arg
|
|
|
|
try:
|
|
|
|
getargs_keywords((1,2),3,arg5=10,arg666=666)
|
|
|
|
except TypeError, err:
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(str(err), "'arg666' is an invalid keyword argument for this function")
|
2008-02-26 13:23:51 -04:00
|
|
|
else:
|
|
|
|
self.fail('TypeError should have been raised')
|
2006-07-26 05:03:10 -03:00
|
|
|
|
2003-04-17 15:55:45 -03:00
|
|
|
def test_main():
|
2013-12-10 16:09:20 -04:00
|
|
|
tests = [Signed_TestCase, Unsigned_TestCase, LongLong_TestCase,
|
|
|
|
Tuple_TestCase, Keywords_TestCase]
|
2003-05-01 14:45:56 -03:00
|
|
|
test_support.run_unittest(*tests)
|
2003-04-17 15:55:45 -03:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
test_main()
|