annotate Lib/test/test_getargs2.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents 614c84670c63
children
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
45468
1d84bf5f9478 Patch #2167 from calvin: Remove unused imports
Christian Heimes <christian@cheimes.de>
parents: 39199
diff changeset
4 import warnings
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
5
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
6 """
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
7 > 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
8 > 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
9 >
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
10 > Code C type Range check
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
11 >
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
12 > 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
13 > 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
14 > B unsigned char none **
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
15 > H unsigned short none **
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
16 > k * unsigned long none
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
17 > I * unsigned int 0..UINT_MAX
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
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
20 > i int INT_MIN..INT_MAX
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
21 > l long LONG_MIN..LONG_MAX
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
22
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
23 > K * unsigned long long none
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
24 > L long long LLONG_MIN..LLONG_MAX
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
25
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
26 > Notes:
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 > * New format codes.
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
29 >
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
30 > ** 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
31 > 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
32
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
33 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
34 unsigned long and PyInt_AsLongLongMask() -> unsigned
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
35 long long (if that exists).
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
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
38 LARGE = 0x7FFFFFFF
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
39 VERY_LARGE = 0xFF0000121212121212121242L
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
40
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
41 from _testcapi import UCHAR_MAX, USHRT_MAX, UINT_MAX, ULONG_MAX, INT_MAX, \
57821
7941a9f865c2 Add missing tests for PyArg_Parse* with format 'h'
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
42 INT_MIN, LONG_MIN, LONG_MAX, PY_SSIZE_T_MIN, PY_SSIZE_T_MAX, \
7941a9f865c2 Add missing tests for PyArg_Parse* with format 'h'
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
43 SHRT_MIN, SHRT_MAX
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
44
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
45 # 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
46 LLONG_MAX = 2**63-1
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
47 LLONG_MIN = -2**63
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
48 ULLONG_MAX = 2**64-1
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 class Long:
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
51 def __int__(self):
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
52 return 99L
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
53
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
54 class Int:
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
55 def __int__(self):
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
56 return 99
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 Unsigned_TestCase(unittest.TestCase):
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
59 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
60 from _testcapi import getargs_b
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
61 # b returns 'unsigned char', and does range checking (0 ... UCHAR_MAX)
58070
2de24bb33cc5 Issue #5080: turn the DeprecationWarning from float arguments passed
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
62 self.assertRaises(TypeError, getargs_b, 3.14)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
63 self.assertEqual(99, getargs_b(Long()))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
64 self.assertEqual(99, getargs_b(Int()))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
65
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
66 self.assertRaises(OverflowError, getargs_b, -1)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
67 self.assertEqual(0, getargs_b(0))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
68 self.assertEqual(UCHAR_MAX, getargs_b(UCHAR_MAX))
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
69 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
70
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
71 self.assertEqual(42, getargs_b(42))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
72 self.assertEqual(42, getargs_b(42L))
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
73 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
74
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
75 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
76 from _testcapi import getargs_B
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
77 # B returns 'unsigned char', no range checking
58070
2de24bb33cc5 Issue #5080: turn the DeprecationWarning from float arguments passed
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
78 self.assertRaises(TypeError, getargs_B, 3.14)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
79 self.assertEqual(99, getargs_B(Long()))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
80 self.assertEqual(99, getargs_B(Int()))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
81
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
82 self.assertEqual(UCHAR_MAX, getargs_B(-1))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
83 self.assertEqual(UCHAR_MAX, getargs_B(-1L))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
84 self.assertEqual(0, getargs_B(0))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
85 self.assertEqual(UCHAR_MAX, getargs_B(UCHAR_MAX))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
86 self.assertEqual(0, getargs_B(UCHAR_MAX+1))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
87
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
88 self.assertEqual(42, getargs_B(42))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
89 self.assertEqual(42, getargs_B(42L))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
90 self.assertEqual(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
91
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
92 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
93 from _testcapi import getargs_H
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
94 # H returns 'unsigned short', no range checking
58070
2de24bb33cc5 Issue #5080: turn the DeprecationWarning from float arguments passed
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
95 self.assertRaises(TypeError, getargs_H, 3.14)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
96 self.assertEqual(99, getargs_H(Long()))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
97 self.assertEqual(99, getargs_H(Int()))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
98
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
99 self.assertEqual(USHRT_MAX, getargs_H(-1))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
100 self.assertEqual(0, getargs_H(0))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
101 self.assertEqual(USHRT_MAX, getargs_H(USHRT_MAX))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
102 self.assertEqual(0, getargs_H(USHRT_MAX+1))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
103
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
104 self.assertEqual(42, getargs_H(42))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
105 self.assertEqual(42, getargs_H(42L))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
106
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
107 self.assertEqual(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
108
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
109 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
110 from _testcapi import getargs_I
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
111 # I returns 'unsigned int', no range checking
58070
2de24bb33cc5 Issue #5080: turn the DeprecationWarning from float arguments passed
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
112 self.assertRaises(TypeError, getargs_I, 3.14)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
113 self.assertEqual(99, getargs_I(Long()))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
114 self.assertEqual(99, getargs_I(Int()))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
115
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
116 self.assertEqual(UINT_MAX, getargs_I(-1))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
117 self.assertEqual(0, getargs_I(0))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
118 self.assertEqual(UINT_MAX, getargs_I(UINT_MAX))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
119 self.assertEqual(0, getargs_I(UINT_MAX+1))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
120
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
121 self.assertEqual(42, getargs_I(42))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
122 self.assertEqual(42, getargs_I(42L))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
123
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
124 self.assertEqual(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
125
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
126 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
127 from _testcapi import getargs_k
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
128 # k returns 'unsigned long', no range checking
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
129 # 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
130 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
131 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
132 self.assertRaises(TypeError, getargs_k, Int())
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
133
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
134 self.assertEqual(ULONG_MAX, getargs_k(-1))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
135 self.assertEqual(0, getargs_k(0))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
136 self.assertEqual(ULONG_MAX, getargs_k(ULONG_MAX))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
137 self.assertEqual(0, getargs_k(ULONG_MAX+1))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
138
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
139 self.assertEqual(42, getargs_k(42))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
140 self.assertEqual(42, getargs_k(42L))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
141
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
142 self.assertEqual(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
143
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
144 class Signed_TestCase(unittest.TestCase):
57821
7941a9f865c2 Add missing tests for PyArg_Parse* with format 'h'
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
145 def test_h(self):
7941a9f865c2 Add missing tests for PyArg_Parse* with format 'h'
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
146 from _testcapi import getargs_h
7941a9f865c2 Add missing tests for PyArg_Parse* with format 'h'
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
147 # h returns 'short', and does range checking (SHRT_MIN ... SHRT_MAX)
58070
2de24bb33cc5 Issue #5080: turn the DeprecationWarning from float arguments passed
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
148 self.assertRaises(TypeError, getargs_h, 3.14)
57821
7941a9f865c2 Add missing tests for PyArg_Parse* with format 'h'
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
149 self.assertEqual(99, getargs_h(Long()))
7941a9f865c2 Add missing tests for PyArg_Parse* with format 'h'
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
150 self.assertEqual(99, getargs_h(Int()))
7941a9f865c2 Add missing tests for PyArg_Parse* with format 'h'
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
151
7941a9f865c2 Add missing tests for PyArg_Parse* with format 'h'
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
152 self.assertRaises(OverflowError, getargs_h, SHRT_MIN-1)
7941a9f865c2 Add missing tests for PyArg_Parse* with format 'h'
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
153 self.assertEqual(SHRT_MIN, getargs_h(SHRT_MIN))
7941a9f865c2 Add missing tests for PyArg_Parse* with format 'h'
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
154 self.assertEqual(SHRT_MAX, getargs_h(SHRT_MAX))
7941a9f865c2 Add missing tests for PyArg_Parse* with format 'h'
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
155 self.assertRaises(OverflowError, getargs_h, SHRT_MAX+1)
7941a9f865c2 Add missing tests for PyArg_Parse* with format 'h'
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
156
7941a9f865c2 Add missing tests for PyArg_Parse* with format 'h'
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
157 self.assertEqual(42, getargs_h(42))
7941a9f865c2 Add missing tests for PyArg_Parse* with format 'h'
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
158 self.assertEqual(42, getargs_h(42L))
7941a9f865c2 Add missing tests for PyArg_Parse* with format 'h'
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
159 self.assertRaises(OverflowError, getargs_h, VERY_LARGE)
7941a9f865c2 Add missing tests for PyArg_Parse* with format 'h'
Mark Dickinson <dickinsm@gmail.com>
parents: 55002
diff changeset
160
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
161 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
162 from _testcapi import getargs_i
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
163 # i returns 'int', and does range checking (INT_MIN ... INT_MAX)
58070
2de24bb33cc5 Issue #5080: turn the DeprecationWarning from float arguments passed
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
164 self.assertRaises(TypeError, getargs_i, 3.14)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
165 self.assertEqual(99, getargs_i(Long()))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
166 self.assertEqual(99, getargs_i(Int()))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
167
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
168 self.assertRaises(OverflowError, getargs_i, INT_MIN-1)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
169 self.assertEqual(INT_MIN, getargs_i(INT_MIN))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
170 self.assertEqual(INT_MAX, getargs_i(INT_MAX))
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
171 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
172
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
173 self.assertEqual(42, getargs_i(42))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
174 self.assertEqual(42, getargs_i(42L))
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
175 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
176
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
177 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
178 from _testcapi import getargs_l
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
179 # l returns 'long', and does range checking (LONG_MIN ... LONG_MAX)
58070
2de24bb33cc5 Issue #5080: turn the DeprecationWarning from float arguments passed
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
180 self.assertRaises(TypeError, getargs_l, 3.14)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
181 self.assertEqual(99, getargs_l(Long()))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
182 self.assertEqual(99, getargs_l(Int()))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
183
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
184 self.assertRaises(OverflowError, getargs_l, LONG_MIN-1)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
185 self.assertEqual(LONG_MIN, getargs_l(LONG_MIN))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
186 self.assertEqual(LONG_MAX, getargs_l(LONG_MAX))
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
187 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
188
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
189 self.assertEqual(42, getargs_l(42))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
190 self.assertEqual(42, getargs_l(42L))
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
191 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
192
37674
a4231aa3201a Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents: 34666
diff changeset
193 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
194 from _testcapi import getargs_n
37693
308e2e8ed676 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 37674
diff changeset
195 # 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
196 # (PY_SSIZE_T_MIN ... PY_SSIZE_T_MAX)
58070
2de24bb33cc5 Issue #5080: turn the DeprecationWarning from float arguments passed
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
197 self.assertRaises(TypeError, getargs_n, 3.14)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
198 self.assertEqual(99, getargs_n(Long()))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
199 self.assertEqual(99, getargs_n(Int()))
37674
a4231aa3201a Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents: 34666
diff changeset
200
a4231aa3201a Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents: 34666
diff changeset
201 self.assertRaises(OverflowError, getargs_n, PY_SSIZE_T_MIN-1)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
202 self.assertEqual(PY_SSIZE_T_MIN, getargs_n(PY_SSIZE_T_MIN))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
203 self.assertEqual(PY_SSIZE_T_MAX, getargs_n(PY_SSIZE_T_MAX))
37674
a4231aa3201a Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents: 34666
diff changeset
204 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
205
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
206 self.assertEqual(42, getargs_n(42))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
207 self.assertEqual(42, getargs_n(42L))
37674
a4231aa3201a Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents: 34666
diff changeset
208 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
209
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
210
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
211 class LongLong_TestCase(unittest.TestCase):
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
212 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
213 from _testcapi import getargs_L
58070
2de24bb33cc5 Issue #5080: turn the DeprecationWarning from float arguments passed
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
214 # L returns 'long long', and does range checking (LLONG_MIN
2de24bb33cc5 Issue #5080: turn the DeprecationWarning from float arguments passed
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
215 # ... LLONG_MAX)
2de24bb33cc5 Issue #5080: turn the DeprecationWarning from float arguments passed
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
216 with warnings.catch_warnings():
2de24bb33cc5 Issue #5080: turn the DeprecationWarning from float arguments passed
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
217 warnings.filterwarnings(
2de24bb33cc5 Issue #5080: turn the DeprecationWarning from float arguments passed
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
218 "ignore",
2de24bb33cc5 Issue #5080: turn the DeprecationWarning from float arguments passed
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
219 category=DeprecationWarning,
2de24bb33cc5 Issue #5080: turn the DeprecationWarning from float arguments passed
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
220 message=".*integer argument expected, got float",
2de24bb33cc5 Issue #5080: turn the DeprecationWarning from float arguments passed
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
221 module=__name__)
2de24bb33cc5 Issue #5080: turn the DeprecationWarning from float arguments passed
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
222 self.assertEqual(3, getargs_L(3.14))
2de24bb33cc5 Issue #5080: turn the DeprecationWarning from float arguments passed
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
223 with warnings.catch_warnings():
2de24bb33cc5 Issue #5080: turn the DeprecationWarning from float arguments passed
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
224 warnings.filterwarnings(
2de24bb33cc5 Issue #5080: turn the DeprecationWarning from float arguments passed
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
225 "error",
2de24bb33cc5 Issue #5080: turn the DeprecationWarning from float arguments passed
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
226 category=DeprecationWarning,
2de24bb33cc5 Issue #5080: turn the DeprecationWarning from float arguments passed
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
227 message=".*integer argument expected, got float",
2de24bb33cc5 Issue #5080: turn the DeprecationWarning from float arguments passed
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
228 module="unittest")
2de24bb33cc5 Issue #5080: turn the DeprecationWarning from float arguments passed
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
229 self.assertRaises(DeprecationWarning, getargs_L, 3.14)
2de24bb33cc5 Issue #5080: turn the DeprecationWarning from float arguments passed
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
230
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
231 self.assertRaises(TypeError, getargs_L, "Hello")
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
232 self.assertEqual(99, getargs_L(Long()))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
233 self.assertEqual(99, getargs_L(Int()))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
234
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
235 self.assertRaises(OverflowError, getargs_L, LLONG_MIN-1)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
236 self.assertEqual(LLONG_MIN, getargs_L(LLONG_MIN))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
237 self.assertEqual(LLONG_MAX, getargs_L(LLONG_MAX))
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
238 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
239
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
240 self.assertEqual(42, getargs_L(42))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
241 self.assertEqual(42, getargs_L(42L))
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
242 self.assertRaises(OverflowError, getargs_L, VERY_LARGE)
28774
c9bee11eaa8b Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 28668
diff changeset
243
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
244 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
245 from _testcapi import getargs_K
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
246 # 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
247 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
248 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
249 self.assertRaises(TypeError, getargs_K, Int())
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
250 self.assertEqual(ULLONG_MAX, getargs_K(ULLONG_MAX))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
251 self.assertEqual(0, getargs_K(0))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
252 self.assertEqual(0, getargs_K(ULLONG_MAX+1))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
253
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
254 self.assertEqual(42, getargs_K(42))
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
255 self.assertEqual(42, getargs_K(42L))
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
256
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45537
diff changeset
257 self.assertEqual(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
258
39189
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 37693
diff changeset
259
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 37693
diff changeset
260 class Tuple_TestCase(unittest.TestCase):
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 37693
diff changeset
261 def test_tuple(self):
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 37693
diff changeset
262 from _testcapi import getargs_tuple
39199
29c2fee6c984 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 39189
diff changeset
263
39189
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 37693
diff changeset
264 ret = getargs_tuple(1, (2, 3))
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58070
diff changeset
265 self.assertEqual(ret, (1,2,3))
39189
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 37693
diff changeset
266
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 37693
diff changeset
267 # 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
268 class seq:
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 37693
diff changeset
269 def __len__(self):
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 37693
diff changeset
270 return 2
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 37693
diff changeset
271 def __getitem__(self, n):
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 37693
diff changeset
272 raise ValueError
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 37693
diff changeset
273 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
274
45537
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
275 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
276 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
277 # using all positional args
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58070
diff changeset
278 self.assertEqual(
45537
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
279 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
280 (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
281 )
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
282 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
283 # positional and keyword args
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58070
diff changeset
284 self.assertEqual(
45537
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
285 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
286 (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
287 )
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
288 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
289 # all keywords
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58070
diff changeset
290 self.assertEqual(
45537
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
291 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
292 (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
293 )
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
294 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
295 # missing optional keyword args, skipping tuples
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58070
diff changeset
296 self.assertEqual(
45537
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
297 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
298 (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
299 )
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
300 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
301 # 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
302 try:
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
303 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
304 except TypeError, err:
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58070
diff changeset
305 self.assertEqual(str(err), "Required argument 'arg2' (pos 2) not found")
45537
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
306 else:
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
307 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
308 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
309 try:
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
310 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
311 except TypeError, err:
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58070
diff changeset
312 self.assertEqual(str(err), "function takes at most 5 arguments (6 given)")
45537
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
313 else:
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
314 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
315 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
316 # 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
317 try:
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
318 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
319 except TypeError, err:
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58070
diff changeset
320 self.assertEqual(str(err), "'arg666' is an invalid keyword argument for this function")
45537
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
321 else:
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 45468
diff changeset
322 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
323
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
324 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
325 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
326 try:
28776
211c02fb6570 This test now uses the separate getargs_X functions from _testcapimodule.
Thomas Heller <theller@ctypes.org>
parents: 28774
diff changeset
327 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
328 except ImportError:
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
329 pass # PY_LONG_LONG not available
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
330 else:
28917
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28776
diff changeset
331 tests.append(LongLong_TestCase)
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28776
diff changeset
332 test_support.run_unittest(*tests)
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
333
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
334 if __name__ == "__main__":
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
335 test_main()