annotate Lib/test/test_getargs2.py @ 58925:eecf1bef052d 2.6

Merged revisions 78207 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line #7930: fix stripid ........
author Ezio Melotti <ezio.melotti@gmail.com>
date Tue, 16 Feb 2010 23:29:44 +0000
parents f33f66a2082f
children 6768b2350c57
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1 import unittest
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
2 from test import test_support
45537
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
3 from _testcapi import getargs_keywords
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
4
45468
1d84bf5f9478 Patch #2167 from calvin: Remove unused imports
Christian Heimes <christian@cheimes.de>
parents: 39199
diff changeset
5 import warnings
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
6 warnings.filterwarnings("ignore",
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
7 category=DeprecationWarning,
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
8 message=".*integer argument expected, got float",
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
9 module=__name__)
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
10 warnings.filterwarnings("ignore",
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
11 category=DeprecationWarning,
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
12 message=".*integer argument expected, got float",
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
13 module="unittest")
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
14
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
15 """
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
16 > How about the following counterproposal. This also changes some of
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
17 > the other format codes to be a little more regular.
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
18 >
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
19 > Code C type Range check
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
20 >
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
21 > b unsigned char 0..UCHAR_MAX
28668
046bc9d7fb0e Delete the 'h' test -- 'h' is no longer unsigned so the machinery here
Guido van Rossum <guido@python.org>
parents: 28652
diff changeset
22 > h signed short SHRT_MIN..SHRT_MAX
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
23 > B unsigned char none **
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
24 > H unsigned short none **
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
25 > k * unsigned long none
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
26 > I * unsigned int 0..UINT_MAX
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
27
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
28
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
29 > i int INT_MIN..INT_MAX
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
30 > l long LONG_MIN..LONG_MAX
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
31
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
32 > K * unsigned long long none
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
33 > L long long LLONG_MIN..LLONG_MAX
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
34
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
35 > Notes:
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
36 >
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
37 > * New format codes.
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
38 >
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
39 > ** Changed from previous "range-and-a-half" to "none"; the
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
40 > range-and-a-half checking wasn't particularly useful.
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
41
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
42 Plus a C API or two, e.g. PyInt_AsLongMask() ->
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
43 unsigned long and PyInt_AsLongLongMask() -> unsigned
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
44 long long (if that exists).
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
45 """
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
46
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
47 LARGE = 0x7FFFFFFF
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
48 VERY_LARGE = 0xFF0000121212121212121242L
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
49
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
50 from _testcapi import UCHAR_MAX, USHRT_MAX, UINT_MAX, ULONG_MAX, INT_MAX, \
37674
a4231aa3201a Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents: 34666
diff changeset
51 INT_MIN, LONG_MIN, LONG_MAX, PY_SSIZE_T_MIN, PY_SSIZE_T_MAX
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
52
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
53 # fake, they are not defined in Python's header files
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
54 LLONG_MAX = 2**63-1
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
55 LLONG_MIN = -2**63
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
56 ULLONG_MAX = 2**64-1
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
57
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
58 class Long:
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
59 def __int__(self):
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
60 return 99L
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
61
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
62 class Int:
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
63 def __int__(self):
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
64 return 99
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
65
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
66 class Unsigned_TestCase(unittest.TestCase):
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
67 def test_b(self):
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
68 from _testcapi import getargs_b
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
69 # b returns 'unsigned char', and does range checking (0 ... UCHAR_MAX)
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
70 self.failUnlessEqual(3, getargs_b(3.14))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
71 self.failUnlessEqual(99, getargs_b(Long()))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
72 self.failUnlessEqual(99, getargs_b(Int()))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
73
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
74 self.assertRaises(OverflowError, getargs_b, -1)
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
75 self.failUnlessEqual(0, getargs_b(0))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
76 self.failUnlessEqual(UCHAR_MAX, getargs_b(UCHAR_MAX))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
77 self.assertRaises(OverflowError, getargs_b, UCHAR_MAX + 1)
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
78
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
79 self.failUnlessEqual(42, getargs_b(42))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
80 self.failUnlessEqual(42, getargs_b(42L))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
81 self.assertRaises(OverflowError, getargs_b, VERY_LARGE)
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
82
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
83 def test_B(self):
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
84 from _testcapi import getargs_B
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
85 # B returns 'unsigned char', no range checking
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
86 self.failUnlessEqual(3, getargs_B(3.14))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
87 self.failUnlessEqual(99, getargs_B(Long()))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
88 self.failUnlessEqual(99, getargs_B(Int()))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
89
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
90 self.failUnlessEqual(UCHAR_MAX, getargs_B(-1))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
91 self.failUnlessEqual(UCHAR_MAX, getargs_B(-1L))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
92 self.failUnlessEqual(0, getargs_B(0))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
93 self.failUnlessEqual(UCHAR_MAX, getargs_B(UCHAR_MAX))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
94 self.failUnlessEqual(0, getargs_B(UCHAR_MAX+1))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
95
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
96 self.failUnlessEqual(42, getargs_B(42))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
97 self.failUnlessEqual(42, getargs_B(42L))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
98 self.failUnlessEqual(UCHAR_MAX & VERY_LARGE, getargs_B(VERY_LARGE))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
99
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
100 def test_H(self):
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
101 from _testcapi import getargs_H
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
102 # H returns 'unsigned short', no range checking
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
103 self.failUnlessEqual(3, getargs_H(3.14))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
104 self.failUnlessEqual(99, getargs_H(Long()))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
105 self.failUnlessEqual(99, getargs_H(Int()))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
106
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
107 self.failUnlessEqual(USHRT_MAX, getargs_H(-1))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
108 self.failUnlessEqual(0, getargs_H(0))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
109 self.failUnlessEqual(USHRT_MAX, getargs_H(USHRT_MAX))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
110 self.failUnlessEqual(0, getargs_H(USHRT_MAX+1))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
111
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
112 self.failUnlessEqual(42, getargs_H(42))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
113 self.failUnlessEqual(42, getargs_H(42L))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
114
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
115 self.failUnlessEqual(VERY_LARGE & USHRT_MAX, getargs_H(VERY_LARGE))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
116
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
117 def test_I(self):
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
118 from _testcapi import getargs_I
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
119 # I returns 'unsigned int', no range checking
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
120 self.failUnlessEqual(3, getargs_I(3.14))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
121 self.failUnlessEqual(99, getargs_I(Long()))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
122 self.failUnlessEqual(99, getargs_I(Int()))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
123
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
124 self.failUnlessEqual(UINT_MAX, getargs_I(-1))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
125 self.failUnlessEqual(0, getargs_I(0))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
126 self.failUnlessEqual(UINT_MAX, getargs_I(UINT_MAX))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
127 self.failUnlessEqual(0, getargs_I(UINT_MAX+1))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
128
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
129 self.failUnlessEqual(42, getargs_I(42))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
130 self.failUnlessEqual(42, getargs_I(42L))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
131
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
132 self.failUnlessEqual(VERY_LARGE & UINT_MAX, getargs_I(VERY_LARGE))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
133
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
134 def test_k(self):
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
135 from _testcapi import getargs_k
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
136 # k returns 'unsigned long', no range checking
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
137 # it does not accept float, or instances with __int__
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
138 self.assertRaises(TypeError, getargs_k, 3.14)
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
139 self.assertRaises(TypeError, getargs_k, Long())
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
140 self.assertRaises(TypeError, getargs_k, Int())
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
141
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
142 self.failUnlessEqual(ULONG_MAX, getargs_k(-1))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
143 self.failUnlessEqual(0, getargs_k(0))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
144 self.failUnlessEqual(ULONG_MAX, getargs_k(ULONG_MAX))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
145 self.failUnlessEqual(0, getargs_k(ULONG_MAX+1))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
146
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
147 self.failUnlessEqual(42, getargs_k(42))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
148 self.failUnlessEqual(42, getargs_k(42L))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
149
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
150 self.failUnlessEqual(VERY_LARGE & ULONG_MAX, getargs_k(VERY_LARGE))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
151
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
152 class Signed_TestCase(unittest.TestCase):
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
153 def test_i(self):
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
154 from _testcapi import getargs_i
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
155 # i returns 'int', and does range checking (INT_MIN ... INT_MAX)
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
156 self.failUnlessEqual(3, getargs_i(3.14))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
157 self.failUnlessEqual(99, getargs_i(Long()))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
158 self.failUnlessEqual(99, getargs_i(Int()))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
159
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
160 self.assertRaises(OverflowError, getargs_i, INT_MIN-1)
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
161 self.failUnlessEqual(INT_MIN, getargs_i(INT_MIN))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
162 self.failUnlessEqual(INT_MAX, getargs_i(INT_MAX))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
163 self.assertRaises(OverflowError, getargs_i, INT_MAX+1)
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
164
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
165 self.failUnlessEqual(42, getargs_i(42))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
166 self.failUnlessEqual(42, getargs_i(42L))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
167 self.assertRaises(OverflowError, getargs_i, VERY_LARGE)
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
168
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
169 def test_l(self):
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
170 from _testcapi import getargs_l
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
171 # l returns 'long', and does range checking (LONG_MIN ... LONG_MAX)
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
172 self.failUnlessEqual(3, getargs_l(3.14))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
173 self.failUnlessEqual(99, getargs_l(Long()))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
174 self.failUnlessEqual(99, getargs_l(Int()))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
175
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
176 self.assertRaises(OverflowError, getargs_l, LONG_MIN-1)
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
177 self.failUnlessEqual(LONG_MIN, getargs_l(LONG_MIN))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
178 self.failUnlessEqual(LONG_MAX, getargs_l(LONG_MAX))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
179 self.assertRaises(OverflowError, getargs_l, LONG_MAX+1)
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
180
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
181 self.failUnlessEqual(42, getargs_l(42))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
182 self.failUnlessEqual(42, getargs_l(42L))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
183 self.assertRaises(OverflowError, getargs_l, VERY_LARGE)
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
184
37674
a4231aa3201a Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents: 34666
diff changeset
185 def test_n(self):
a4231aa3201a Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents: 34666
diff changeset
186 from _testcapi import getargs_n
37693
308e2e8ed676 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 37674
diff changeset
187 # n returns 'Py_ssize_t', and does range checking
37674
a4231aa3201a Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents: 34666
diff changeset
188 # (PY_SSIZE_T_MIN ... PY_SSIZE_T_MAX)
a4231aa3201a Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents: 34666
diff changeset
189 self.failUnlessEqual(3, getargs_n(3.14))
a4231aa3201a Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents: 34666
diff changeset
190 self.failUnlessEqual(99, getargs_n(Long()))
a4231aa3201a Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents: 34666
diff changeset
191 self.failUnlessEqual(99, getargs_n(Int()))
a4231aa3201a Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents: 34666
diff changeset
192
a4231aa3201a Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents: 34666
diff changeset
193 self.assertRaises(OverflowError, getargs_n, PY_SSIZE_T_MIN-1)
a4231aa3201a Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents: 34666
diff changeset
194 self.failUnlessEqual(PY_SSIZE_T_MIN, getargs_n(PY_SSIZE_T_MIN))
a4231aa3201a Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents: 34666
diff changeset
195 self.failUnlessEqual(PY_SSIZE_T_MAX, getargs_n(PY_SSIZE_T_MAX))
a4231aa3201a Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents: 34666
diff changeset
196 self.assertRaises(OverflowError, getargs_n, PY_SSIZE_T_MAX+1)
a4231aa3201a Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents: 34666
diff changeset
197
a4231aa3201a Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents: 34666
diff changeset
198 self.failUnlessEqual(42, getargs_n(42))
a4231aa3201a Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents: 34666
diff changeset
199 self.failUnlessEqual(42, getargs_n(42L))
a4231aa3201a Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents: 34666
diff changeset
200 self.assertRaises(OverflowError, getargs_n, VERY_LARGE)
a4231aa3201a Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents: 34666
diff changeset
201
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
202
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
203 class LongLong_TestCase(unittest.TestCase):
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
204 def test_L(self):
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
205 from _testcapi import getargs_L
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
206 # L returns 'long long', and does range checking (LLONG_MIN ... LLONG_MAX)
34666
4812f6a7f735 Revert previous checkin on getargs 'L' code. Try to convert all
Martin v. Löwis <martin@v.loewis.de>
parents: 28917
diff changeset
207 self.failUnlessRaises(TypeError, getargs_L, "Hello")
4812f6a7f735 Revert previous checkin on getargs 'L' code. Try to convert all
Martin v. Löwis <martin@v.loewis.de>
parents: 28917
diff changeset
208 self.failUnlessEqual(3, getargs_L(3.14))
4812f6a7f735 Revert previous checkin on getargs 'L' code. Try to convert all
Martin v. Löwis <martin@v.loewis.de>
parents: 28917
diff changeset
209 self.failUnlessEqual(99, getargs_L(Long()))
4812f6a7f735 Revert previous checkin on getargs 'L' code. Try to convert all
Martin v. Löwis <martin@v.loewis.de>
parents: 28917
diff changeset
210 self.failUnlessEqual(99, getargs_L(Int()))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
211
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
212 self.assertRaises(OverflowError, getargs_L, LLONG_MIN-1)
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
213 self.failUnlessEqual(LLONG_MIN, getargs_L(LLONG_MIN))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
214 self.failUnlessEqual(LLONG_MAX, getargs_L(LLONG_MAX))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
215 self.assertRaises(OverflowError, getargs_L, LLONG_MAX+1)
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
216
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
217 self.failUnlessEqual(42, getargs_L(42))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
218 self.failUnlessEqual(42, getargs_L(42L))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
219 self.assertRaises(OverflowError, getargs_L, VERY_LARGE)
28774
c9bee11eaa8b Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 28668
diff changeset
220
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
221 def test_K(self):
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
222 from _testcapi import getargs_K
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
223 # K return 'unsigned long long', no range checking
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
224 self.assertRaises(TypeError, getargs_K, 3.14)
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
225 self.assertRaises(TypeError, getargs_K, Long())
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
226 self.assertRaises(TypeError, getargs_K, Int())
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
227 self.failUnlessEqual(ULLONG_MAX, getargs_K(ULLONG_MAX))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
228 self.failUnlessEqual(0, getargs_K(0))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
229 self.failUnlessEqual(0, getargs_K(ULLONG_MAX+1))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
230
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
231 self.failUnlessEqual(42, getargs_K(42))
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
232 self.failUnlessEqual(42, getargs_K(42L))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
233
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
234 self.failUnlessEqual(VERY_LARGE & ULLONG_MAX, getargs_K(VERY_LARGE))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
235
39189
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 37693
diff changeset
236
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 37693
diff changeset
237 class Tuple_TestCase(unittest.TestCase):
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 37693
diff changeset
238 def test_tuple(self):
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 37693
diff changeset
239 from _testcapi import getargs_tuple
39199
29c2fee6c984 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 39189
diff changeset
240
39189
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 37693
diff changeset
241 ret = getargs_tuple(1, (2, 3))
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 37693
diff changeset
242 self.assertEquals(ret, (1,2,3))
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 37693
diff changeset
243
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 37693
diff changeset
244 # make sure invalid tuple arguments are handled correctly
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 37693
diff changeset
245 class seq:
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 37693
diff changeset
246 def __len__(self):
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 37693
diff changeset
247 return 2
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 37693
diff changeset
248 def __getitem__(self, n):
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 37693
diff changeset
249 raise ValueError
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 37693
diff changeset
250 self.assertRaises(TypeError, getargs_tuple, 1, seq())
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 37693
diff changeset
251
45537
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
252 class Keywords_TestCase(unittest.TestCase):
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
253 def test_positional_args(self):
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
254 # using all positional args
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
255 self.assertEquals(
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
256 getargs_keywords((1,2), 3, (4,(5,6)), (7,8,9), 10),
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
257 (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
258 )
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
259 def test_mixed_args(self):
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
260 # positional and keyword args
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
261 self.assertEquals(
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
262 getargs_keywords((1,2), 3, (4,(5,6)), arg4=(7,8,9), arg5=10),
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
263 (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
264 )
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
265 def test_keyword_args(self):
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
266 # all keywords
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
267 self.assertEquals(
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
268 getargs_keywords(arg1=(1,2), arg2=3, arg3=(4,(5,6)), arg4=(7,8,9), arg5=10),
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
269 (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
270 )
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
271 def test_optional_args(self):
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
272 # missing optional keyword args, skipping tuples
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
273 self.assertEquals(
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
274 getargs_keywords(arg1=(1,2), arg2=3, arg5=10),
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
275 (1, 2, 3, -1, -1, -1, -1, -1, -1, 10)
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
276 )
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
277 def test_required_args(self):
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
278 # required arg missing
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
279 try:
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
280 getargs_keywords(arg1=(1,2))
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
281 except TypeError, err:
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
282 self.assertEquals(str(err), "Required argument 'arg2' (pos 2) not found")
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
283 else:
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
284 self.fail('TypeError should have been raised')
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
285 def test_too_many_args(self):
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
286 try:
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
287 getargs_keywords((1,2),3,(4,(5,6)),(7,8,9),10,111)
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
288 except TypeError, err:
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
289 self.assertEquals(str(err), "function takes at most 5 arguments (6 given)")
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
290 else:
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
291 self.fail('TypeError should have been raised')
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
292 def test_invalid_keyword(self):
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
293 # extraneous keyword arg
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
294 try:
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
295 getargs_keywords((1,2),3,arg5=10,arg666=666)
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
296 except TypeError, err:
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
297 self.assertEquals(str(err), "'arg666' is an invalid keyword argument for this function")
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
298 else:
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
299 self.fail('TypeError should have been raised')
39189
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 37693
diff changeset
300
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
301 def test_main():
45537
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
302 tests = [Signed_TestCase, Unsigned_TestCase, Tuple_TestCase, Keywords_TestCase]
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
303 try:
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
304 from _testcapi import getargs_L, getargs_K
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
305 except ImportError:
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
306 pass # PY_LONG_LONG not available
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
307 else:
28917
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28776
diff changeset
308 tests.append(LongLong_TestCase)
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28776
diff changeset
309 test_support.run_unittest(*tests)
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
310
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
311 if __name__ == "__main__":
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
312 test_main()