ยปCore Development>Code coverage>Lib/test/test_getargs2.py

Python code coverage for Lib/test/test_getargs2.py

#countcontent
1n/aimport unittest
2n/aimport math
3n/aimport sys
4n/afrom test import support
5n/a# Skip this test if the _testcapi module isn't available.
6n/asupport.import_module('_testcapi')
7n/afrom _testcapi import getargs_keywords, getargs_keyword_only
8n/a
9n/a# > How about the following counterproposal. This also changes some of
10n/a# > the other format codes to be a little more regular.
11n/a# >
12n/a# > Code C type Range check
13n/a# >
14n/a# > b unsigned char 0..UCHAR_MAX
15n/a# > h signed short SHRT_MIN..SHRT_MAX
16n/a# > B unsigned char none **
17n/a# > H unsigned short none **
18n/a# > k * unsigned long none
19n/a# > I * unsigned int 0..UINT_MAX
20n/a#
21n/a#
22n/a# > i int INT_MIN..INT_MAX
23n/a# > l long LONG_MIN..LONG_MAX
24n/a#
25n/a# > K * unsigned long long none
26n/a# > L long long LLONG_MIN..LLONG_MAX
27n/a#
28n/a# > Notes:
29n/a# >
30n/a# > * New format codes.
31n/a# >
32n/a# > ** Changed from previous "range-and-a-half" to "none"; the
33n/a# > range-and-a-half checking wasn't particularly useful.
34n/a#
35n/a# Plus a C API or two, e.g. PyLong_AsUnsignedLongMask() ->
36n/a# unsigned long and PyLong_AsUnsignedLongLongMask() -> unsigned
37n/a# long long (if that exists).
38n/a
39n/aLARGE = 0x7FFFFFFF
40n/aVERY_LARGE = 0xFF0000121212121212121242
41n/a
42n/afrom _testcapi import UCHAR_MAX, USHRT_MAX, UINT_MAX, ULONG_MAX, INT_MAX, \
43n/a INT_MIN, LONG_MIN, LONG_MAX, PY_SSIZE_T_MIN, PY_SSIZE_T_MAX, \
44n/a SHRT_MIN, SHRT_MAX, FLT_MIN, FLT_MAX, DBL_MIN, DBL_MAX
45n/a
46n/aDBL_MAX_EXP = sys.float_info.max_exp
47n/aINF = float('inf')
48n/aNAN = float('nan')
49n/a
50n/a# fake, they are not defined in Python's header files
51n/aLLONG_MAX = 2**63-1
52n/aLLONG_MIN = -2**63
53n/aULLONG_MAX = 2**64-1
54n/a
55n/aclass Int:
56n/a def __int__(self):
57n/a return 99
58n/a
59n/aclass IntSubclass(int):
60n/a def __int__(self):
61n/a return 99
62n/a
63n/aclass BadInt:
64n/a def __int__(self):
65n/a return 1.0
66n/a
67n/aclass BadInt2:
68n/a def __int__(self):
69n/a return True
70n/a
71n/aclass BadInt3(int):
72n/a def __int__(self):
73n/a return True
74n/a
75n/a
76n/aclass Float:
77n/a def __float__(self):
78n/a return 4.25
79n/a
80n/aclass FloatSubclass(float):
81n/a pass
82n/a
83n/aclass FloatSubclass2(float):
84n/a def __float__(self):
85n/a return 4.25
86n/a
87n/aclass BadFloat:
88n/a def __float__(self):
89n/a return 687
90n/a
91n/aclass BadFloat2:
92n/a def __float__(self):
93n/a return FloatSubclass(4.25)
94n/a
95n/aclass BadFloat3(float):
96n/a def __float__(self):
97n/a return FloatSubclass(4.25)
98n/a
99n/a
100n/aclass Complex:
101n/a def __complex__(self):
102n/a return 4.25+0.5j
103n/a
104n/aclass ComplexSubclass(complex):
105n/a pass
106n/a
107n/aclass ComplexSubclass2(complex):
108n/a def __complex__(self):
109n/a return 4.25+0.5j
110n/a
111n/aclass BadComplex:
112n/a def __complex__(self):
113n/a return 1.25
114n/a
115n/aclass BadComplex2:
116n/a def __complex__(self):
117n/a return ComplexSubclass(4.25+0.5j)
118n/a
119n/aclass BadComplex3(complex):
120n/a def __complex__(self):
121n/a return ComplexSubclass(4.25+0.5j)
122n/a
123n/a
124n/aclass TupleSubclass(tuple):
125n/a pass
126n/a
127n/aclass DictSubclass(dict):
128n/a pass
129n/a
130n/a
131n/aclass Unsigned_TestCase(unittest.TestCase):
132n/a def test_b(self):
133n/a from _testcapi import getargs_b
134n/a # b returns 'unsigned char', and does range checking (0 ... UCHAR_MAX)
135n/a self.assertRaises(TypeError, getargs_b, 3.14)
136n/a self.assertEqual(99, getargs_b(Int()))
137n/a self.assertEqual(0, getargs_b(IntSubclass()))
138n/a self.assertRaises(TypeError, getargs_b, BadInt())
139n/a with self.assertWarns(DeprecationWarning):
140n/a self.assertEqual(1, getargs_b(BadInt2()))
141n/a self.assertEqual(0, getargs_b(BadInt3()))
142n/a
143n/a self.assertRaises(OverflowError, getargs_b, -1)
144n/a self.assertEqual(0, getargs_b(0))
145n/a self.assertEqual(UCHAR_MAX, getargs_b(UCHAR_MAX))
146n/a self.assertRaises(OverflowError, getargs_b, UCHAR_MAX + 1)
147n/a
148n/a self.assertEqual(42, getargs_b(42))
149n/a self.assertRaises(OverflowError, getargs_b, VERY_LARGE)
150n/a
151n/a def test_B(self):
152n/a from _testcapi import getargs_B
153n/a # B returns 'unsigned char', no range checking
154n/a self.assertRaises(TypeError, getargs_B, 3.14)
155n/a self.assertEqual(99, getargs_B(Int()))
156n/a self.assertEqual(0, getargs_B(IntSubclass()))
157n/a self.assertRaises(TypeError, getargs_B, BadInt())
158n/a with self.assertWarns(DeprecationWarning):
159n/a self.assertEqual(1, getargs_B(BadInt2()))
160n/a self.assertEqual(0, getargs_B(BadInt3()))
161n/a
162n/a self.assertEqual(UCHAR_MAX, getargs_B(-1))
163n/a self.assertEqual(0, getargs_B(0))
164n/a self.assertEqual(UCHAR_MAX, getargs_B(UCHAR_MAX))
165n/a self.assertEqual(0, getargs_B(UCHAR_MAX+1))
166n/a
167n/a self.assertEqual(42, getargs_B(42))
168n/a self.assertEqual(UCHAR_MAX & VERY_LARGE, getargs_B(VERY_LARGE))
169n/a
170n/a def test_H(self):
171n/a from _testcapi import getargs_H
172n/a # H returns 'unsigned short', no range checking
173n/a self.assertRaises(TypeError, getargs_H, 3.14)
174n/a self.assertEqual(99, getargs_H(Int()))
175n/a self.assertEqual(0, getargs_H(IntSubclass()))
176n/a self.assertRaises(TypeError, getargs_H, BadInt())
177n/a with self.assertWarns(DeprecationWarning):
178n/a self.assertEqual(1, getargs_H(BadInt2()))
179n/a self.assertEqual(0, getargs_H(BadInt3()))
180n/a
181n/a self.assertEqual(USHRT_MAX, getargs_H(-1))
182n/a self.assertEqual(0, getargs_H(0))
183n/a self.assertEqual(USHRT_MAX, getargs_H(USHRT_MAX))
184n/a self.assertEqual(0, getargs_H(USHRT_MAX+1))
185n/a
186n/a self.assertEqual(42, getargs_H(42))
187n/a
188n/a self.assertEqual(VERY_LARGE & USHRT_MAX, getargs_H(VERY_LARGE))
189n/a
190n/a def test_I(self):
191n/a from _testcapi import getargs_I
192n/a # I returns 'unsigned int', no range checking
193n/a self.assertRaises(TypeError, getargs_I, 3.14)
194n/a self.assertEqual(99, getargs_I(Int()))
195n/a self.assertEqual(0, getargs_I(IntSubclass()))
196n/a self.assertRaises(TypeError, getargs_I, BadInt())
197n/a with self.assertWarns(DeprecationWarning):
198n/a self.assertEqual(1, getargs_I(BadInt2()))
199n/a self.assertEqual(0, getargs_I(BadInt3()))
200n/a
201n/a self.assertEqual(UINT_MAX, getargs_I(-1))
202n/a self.assertEqual(0, getargs_I(0))
203n/a self.assertEqual(UINT_MAX, getargs_I(UINT_MAX))
204n/a self.assertEqual(0, getargs_I(UINT_MAX+1))
205n/a
206n/a self.assertEqual(42, getargs_I(42))
207n/a
208n/a self.assertEqual(VERY_LARGE & UINT_MAX, getargs_I(VERY_LARGE))
209n/a
210n/a def test_k(self):
211n/a from _testcapi import getargs_k
212n/a # k returns 'unsigned long', no range checking
213n/a # it does not accept float, or instances with __int__
214n/a self.assertRaises(TypeError, getargs_k, 3.14)
215n/a self.assertRaises(TypeError, getargs_k, Int())
216n/a self.assertEqual(0, getargs_k(IntSubclass()))
217n/a self.assertRaises(TypeError, getargs_k, BadInt())
218n/a self.assertRaises(TypeError, getargs_k, BadInt2())
219n/a self.assertEqual(0, getargs_k(BadInt3()))
220n/a
221n/a self.assertEqual(ULONG_MAX, getargs_k(-1))
222n/a self.assertEqual(0, getargs_k(0))
223n/a self.assertEqual(ULONG_MAX, getargs_k(ULONG_MAX))
224n/a self.assertEqual(0, getargs_k(ULONG_MAX+1))
225n/a
226n/a self.assertEqual(42, getargs_k(42))
227n/a
228n/a self.assertEqual(VERY_LARGE & ULONG_MAX, getargs_k(VERY_LARGE))
229n/a
230n/aclass Signed_TestCase(unittest.TestCase):
231n/a def test_h(self):
232n/a from _testcapi import getargs_h
233n/a # h returns 'short', and does range checking (SHRT_MIN ... SHRT_MAX)
234n/a self.assertRaises(TypeError, getargs_h, 3.14)
235n/a self.assertEqual(99, getargs_h(Int()))
236n/a self.assertEqual(0, getargs_h(IntSubclass()))
237n/a self.assertRaises(TypeError, getargs_h, BadInt())
238n/a with self.assertWarns(DeprecationWarning):
239n/a self.assertEqual(1, getargs_h(BadInt2()))
240n/a self.assertEqual(0, getargs_h(BadInt3()))
241n/a
242n/a self.assertRaises(OverflowError, getargs_h, SHRT_MIN-1)
243n/a self.assertEqual(SHRT_MIN, getargs_h(SHRT_MIN))
244n/a self.assertEqual(SHRT_MAX, getargs_h(SHRT_MAX))
245n/a self.assertRaises(OverflowError, getargs_h, SHRT_MAX+1)
246n/a
247n/a self.assertEqual(42, getargs_h(42))
248n/a self.assertRaises(OverflowError, getargs_h, VERY_LARGE)
249n/a
250n/a def test_i(self):
251n/a from _testcapi import getargs_i
252n/a # i returns 'int', and does range checking (INT_MIN ... INT_MAX)
253n/a self.assertRaises(TypeError, getargs_i, 3.14)
254n/a self.assertEqual(99, getargs_i(Int()))
255n/a self.assertEqual(0, getargs_i(IntSubclass()))
256n/a self.assertRaises(TypeError, getargs_i, BadInt())
257n/a with self.assertWarns(DeprecationWarning):
258n/a self.assertEqual(1, getargs_i(BadInt2()))
259n/a self.assertEqual(0, getargs_i(BadInt3()))
260n/a
261n/a self.assertRaises(OverflowError, getargs_i, INT_MIN-1)
262n/a self.assertEqual(INT_MIN, getargs_i(INT_MIN))
263n/a self.assertEqual(INT_MAX, getargs_i(INT_MAX))
264n/a self.assertRaises(OverflowError, getargs_i, INT_MAX+1)
265n/a
266n/a self.assertEqual(42, getargs_i(42))
267n/a self.assertRaises(OverflowError, getargs_i, VERY_LARGE)
268n/a
269n/a def test_l(self):
270n/a from _testcapi import getargs_l
271n/a # l returns 'long', and does range checking (LONG_MIN ... LONG_MAX)
272n/a self.assertRaises(TypeError, getargs_l, 3.14)
273n/a self.assertEqual(99, getargs_l(Int()))
274n/a self.assertEqual(0, getargs_l(IntSubclass()))
275n/a self.assertRaises(TypeError, getargs_l, BadInt())
276n/a with self.assertWarns(DeprecationWarning):
277n/a self.assertEqual(1, getargs_l(BadInt2()))
278n/a self.assertEqual(0, getargs_l(BadInt3()))
279n/a
280n/a self.assertRaises(OverflowError, getargs_l, LONG_MIN-1)
281n/a self.assertEqual(LONG_MIN, getargs_l(LONG_MIN))
282n/a self.assertEqual(LONG_MAX, getargs_l(LONG_MAX))
283n/a self.assertRaises(OverflowError, getargs_l, LONG_MAX+1)
284n/a
285n/a self.assertEqual(42, getargs_l(42))
286n/a self.assertRaises(OverflowError, getargs_l, VERY_LARGE)
287n/a
288n/a def test_n(self):
289n/a from _testcapi import getargs_n
290n/a # n returns 'Py_ssize_t', and does range checking
291n/a # (PY_SSIZE_T_MIN ... PY_SSIZE_T_MAX)
292n/a self.assertRaises(TypeError, getargs_n, 3.14)
293n/a self.assertRaises(TypeError, getargs_n, Int())
294n/a self.assertEqual(0, getargs_n(IntSubclass()))
295n/a self.assertRaises(TypeError, getargs_n, BadInt())
296n/a self.assertRaises(TypeError, getargs_n, BadInt2())
297n/a self.assertEqual(0, getargs_n(BadInt3()))
298n/a
299n/a self.assertRaises(OverflowError, getargs_n, PY_SSIZE_T_MIN-1)
300n/a self.assertEqual(PY_SSIZE_T_MIN, getargs_n(PY_SSIZE_T_MIN))
301n/a self.assertEqual(PY_SSIZE_T_MAX, getargs_n(PY_SSIZE_T_MAX))
302n/a self.assertRaises(OverflowError, getargs_n, PY_SSIZE_T_MAX+1)
303n/a
304n/a self.assertEqual(42, getargs_n(42))
305n/a self.assertRaises(OverflowError, getargs_n, VERY_LARGE)
306n/a
307n/a
308n/aclass LongLong_TestCase(unittest.TestCase):
309n/a def test_L(self):
310n/a from _testcapi import getargs_L
311n/a # L returns 'long long', and does range checking (LLONG_MIN
312n/a # ... LLONG_MAX)
313n/a self.assertRaises(TypeError, getargs_L, 3.14)
314n/a self.assertRaises(TypeError, getargs_L, "Hello")
315n/a self.assertEqual(99, getargs_L(Int()))
316n/a self.assertEqual(0, getargs_L(IntSubclass()))
317n/a self.assertRaises(TypeError, getargs_L, BadInt())
318n/a with self.assertWarns(DeprecationWarning):
319n/a self.assertEqual(1, getargs_L(BadInt2()))
320n/a self.assertEqual(0, getargs_L(BadInt3()))
321n/a
322n/a self.assertRaises(OverflowError, getargs_L, LLONG_MIN-1)
323n/a self.assertEqual(LLONG_MIN, getargs_L(LLONG_MIN))
324n/a self.assertEqual(LLONG_MAX, getargs_L(LLONG_MAX))
325n/a self.assertRaises(OverflowError, getargs_L, LLONG_MAX+1)
326n/a
327n/a self.assertEqual(42, getargs_L(42))
328n/a self.assertRaises(OverflowError, getargs_L, VERY_LARGE)
329n/a
330n/a def test_K(self):
331n/a from _testcapi import getargs_K
332n/a # K return 'unsigned long long', no range checking
333n/a self.assertRaises(TypeError, getargs_K, 3.14)
334n/a self.assertRaises(TypeError, getargs_K, Int())
335n/a self.assertEqual(0, getargs_K(IntSubclass()))
336n/a self.assertRaises(TypeError, getargs_K, BadInt())
337n/a self.assertRaises(TypeError, getargs_K, BadInt2())
338n/a self.assertEqual(0, getargs_K(BadInt3()))
339n/a
340n/a self.assertEqual(ULLONG_MAX, getargs_K(ULLONG_MAX))
341n/a self.assertEqual(0, getargs_K(0))
342n/a self.assertEqual(0, getargs_K(ULLONG_MAX+1))
343n/a
344n/a self.assertEqual(42, getargs_K(42))
345n/a
346n/a self.assertEqual(VERY_LARGE & ULLONG_MAX, getargs_K(VERY_LARGE))
347n/a
348n/a
349n/aclass Float_TestCase(unittest.TestCase):
350n/a def assertEqualWithSign(self, actual, expected):
351n/a self.assertEqual(actual, expected)
352n/a self.assertEqual(math.copysign(1, actual), math.copysign(1, expected))
353n/a
354n/a def test_f(self):
355n/a from _testcapi import getargs_f
356n/a self.assertEqual(getargs_f(4.25), 4.25)
357n/a self.assertEqual(getargs_f(4), 4.0)
358n/a self.assertRaises(TypeError, getargs_f, 4.25+0j)
359n/a self.assertEqual(getargs_f(Float()), 4.25)
360n/a self.assertEqual(getargs_f(FloatSubclass(7.5)), 7.5)
361n/a self.assertEqual(getargs_f(FloatSubclass2(7.5)), 7.5)
362n/a self.assertRaises(TypeError, getargs_f, BadFloat())
363n/a with self.assertWarns(DeprecationWarning):
364n/a self.assertEqual(getargs_f(BadFloat2()), 4.25)
365n/a self.assertEqual(getargs_f(BadFloat3(7.5)), 7.5)
366n/a
367n/a for x in (FLT_MIN, -FLT_MIN, FLT_MAX, -FLT_MAX, INF, -INF):
368n/a self.assertEqual(getargs_f(x), x)
369n/a if FLT_MAX < DBL_MAX:
370n/a self.assertEqual(getargs_f(DBL_MAX), INF)
371n/a self.assertEqual(getargs_f(-DBL_MAX), -INF)
372n/a if FLT_MIN > DBL_MIN:
373n/a self.assertEqualWithSign(getargs_f(DBL_MIN), 0.0)
374n/a self.assertEqualWithSign(getargs_f(-DBL_MIN), -0.0)
375n/a self.assertEqualWithSign(getargs_f(0.0), 0.0)
376n/a self.assertEqualWithSign(getargs_f(-0.0), -0.0)
377n/a r = getargs_f(NAN)
378n/a self.assertNotEqual(r, r)
379n/a
380n/a def test_d(self):
381n/a from _testcapi import getargs_d
382n/a self.assertEqual(getargs_d(4.25), 4.25)
383n/a self.assertEqual(getargs_d(4), 4.0)
384n/a self.assertRaises(TypeError, getargs_d, 4.25+0j)
385n/a self.assertEqual(getargs_d(Float()), 4.25)
386n/a self.assertEqual(getargs_d(FloatSubclass(7.5)), 7.5)
387n/a self.assertEqual(getargs_d(FloatSubclass2(7.5)), 7.5)
388n/a self.assertRaises(TypeError, getargs_d, BadFloat())
389n/a with self.assertWarns(DeprecationWarning):
390n/a self.assertEqual(getargs_d(BadFloat2()), 4.25)
391n/a self.assertEqual(getargs_d(BadFloat3(7.5)), 7.5)
392n/a
393n/a for x in (DBL_MIN, -DBL_MIN, DBL_MAX, -DBL_MAX, INF, -INF):
394n/a self.assertEqual(getargs_d(x), x)
395n/a self.assertRaises(OverflowError, getargs_d, 1<<DBL_MAX_EXP)
396n/a self.assertRaises(OverflowError, getargs_d, -1<<DBL_MAX_EXP)
397n/a self.assertEqualWithSign(getargs_d(0.0), 0.0)
398n/a self.assertEqualWithSign(getargs_d(-0.0), -0.0)
399n/a r = getargs_d(NAN)
400n/a self.assertNotEqual(r, r)
401n/a
402n/a def test_D(self):
403n/a from _testcapi import getargs_D
404n/a self.assertEqual(getargs_D(4.25+0.5j), 4.25+0.5j)
405n/a self.assertEqual(getargs_D(4.25), 4.25+0j)
406n/a self.assertEqual(getargs_D(4), 4.0+0j)
407n/a self.assertEqual(getargs_D(Complex()), 4.25+0.5j)
408n/a self.assertEqual(getargs_D(ComplexSubclass(7.5+0.25j)), 7.5+0.25j)
409n/a self.assertEqual(getargs_D(ComplexSubclass2(7.5+0.25j)), 7.5+0.25j)
410n/a self.assertRaises(TypeError, getargs_D, BadComplex())
411n/a self.assertEqual(getargs_D(BadComplex2()), 4.25+0.5j)
412n/a self.assertEqual(getargs_D(BadComplex3(7.5+0.25j)), 7.5+0.25j)
413n/a
414n/a for x in (DBL_MIN, -DBL_MIN, DBL_MAX, -DBL_MAX, INF, -INF):
415n/a c = complex(x, 1.0)
416n/a self.assertEqual(getargs_D(c), c)
417n/a c = complex(1.0, x)
418n/a self.assertEqual(getargs_D(c), c)
419n/a self.assertEqualWithSign(getargs_D(complex(0.0, 1.0)).real, 0.0)
420n/a self.assertEqualWithSign(getargs_D(complex(-0.0, 1.0)).real, -0.0)
421n/a self.assertEqualWithSign(getargs_D(complex(1.0, 0.0)).imag, 0.0)
422n/a self.assertEqualWithSign(getargs_D(complex(1.0, -0.0)).imag, -0.0)
423n/a
424n/a
425n/aclass Paradox:
426n/a "This statement is false."
427n/a def __bool__(self):
428n/a raise NotImplementedError
429n/a
430n/aclass Boolean_TestCase(unittest.TestCase):
431n/a def test_p(self):
432n/a from _testcapi import getargs_p
433n/a self.assertEqual(0, getargs_p(False))
434n/a self.assertEqual(0, getargs_p(None))
435n/a self.assertEqual(0, getargs_p(0))
436n/a self.assertEqual(0, getargs_p(0.0))
437n/a self.assertEqual(0, getargs_p(0j))
438n/a self.assertEqual(0, getargs_p(''))
439n/a self.assertEqual(0, getargs_p(()))
440n/a self.assertEqual(0, getargs_p([]))
441n/a self.assertEqual(0, getargs_p({}))
442n/a
443n/a self.assertEqual(1, getargs_p(True))
444n/a self.assertEqual(1, getargs_p(1))
445n/a self.assertEqual(1, getargs_p(1.0))
446n/a self.assertEqual(1, getargs_p(1j))
447n/a self.assertEqual(1, getargs_p('x'))
448n/a self.assertEqual(1, getargs_p((1,)))
449n/a self.assertEqual(1, getargs_p([1]))
450n/a self.assertEqual(1, getargs_p({1:2}))
451n/a self.assertEqual(1, getargs_p(unittest.TestCase))
452n/a
453n/a self.assertRaises(NotImplementedError, getargs_p, Paradox())
454n/a
455n/a
456n/aclass Tuple_TestCase(unittest.TestCase):
457n/a def test_args(self):
458n/a from _testcapi import get_args
459n/a
460n/a ret = get_args(1, 2)
461n/a self.assertEqual(ret, (1, 2))
462n/a self.assertIs(type(ret), tuple)
463n/a
464n/a ret = get_args(1, *(2, 3))
465n/a self.assertEqual(ret, (1, 2, 3))
466n/a self.assertIs(type(ret), tuple)
467n/a
468n/a ret = get_args(*[1, 2])
469n/a self.assertEqual(ret, (1, 2))
470n/a self.assertIs(type(ret), tuple)
471n/a
472n/a ret = get_args(*TupleSubclass([1, 2]))
473n/a self.assertEqual(ret, (1, 2))
474n/a self.assertIs(type(ret), tuple)
475n/a
476n/a ret = get_args()
477n/a self.assertIn(ret, ((), None))
478n/a self.assertIn(type(ret), (tuple, type(None)))
479n/a
480n/a ret = get_args(*())
481n/a self.assertIn(ret, ((), None))
482n/a self.assertIn(type(ret), (tuple, type(None)))
483n/a
484n/a def test_tuple(self):
485n/a from _testcapi import getargs_tuple
486n/a
487n/a ret = getargs_tuple(1, (2, 3))
488n/a self.assertEqual(ret, (1,2,3))
489n/a
490n/a # make sure invalid tuple arguments are handled correctly
491n/a class seq:
492n/a def __len__(self):
493n/a return 2
494n/a def __getitem__(self, n):
495n/a raise ValueError
496n/a self.assertRaises(TypeError, getargs_tuple, 1, seq())
497n/a
498n/aclass Keywords_TestCase(unittest.TestCase):
499n/a def test_kwargs(self):
500n/a from _testcapi import get_kwargs
501n/a
502n/a ret = get_kwargs(a=1, b=2)
503n/a self.assertEqual(ret, {'a': 1, 'b': 2})
504n/a self.assertIs(type(ret), dict)
505n/a
506n/a ret = get_kwargs(a=1, **{'b': 2, 'c': 3})
507n/a self.assertEqual(ret, {'a': 1, 'b': 2, 'c': 3})
508n/a self.assertIs(type(ret), dict)
509n/a
510n/a ret = get_kwargs(**DictSubclass({'a': 1, 'b': 2}))
511n/a self.assertEqual(ret, {'a': 1, 'b': 2})
512n/a self.assertIs(type(ret), dict)
513n/a
514n/a ret = get_kwargs()
515n/a self.assertIn(ret, ({}, None))
516n/a self.assertIn(type(ret), (dict, type(None)))
517n/a
518n/a ret = get_kwargs(**{})
519n/a self.assertIn(ret, ({}, None))
520n/a self.assertIn(type(ret), (dict, type(None)))
521n/a
522n/a def test_positional_args(self):
523n/a # using all positional args
524n/a self.assertEqual(
525n/a getargs_keywords((1,2), 3, (4,(5,6)), (7,8,9), 10),
526n/a (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
527n/a )
528n/a
529n/a def test_mixed_args(self):
530n/a # positional and keyword args
531n/a self.assertEqual(
532n/a getargs_keywords((1,2), 3, (4,(5,6)), arg4=(7,8,9), arg5=10),
533n/a (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
534n/a )
535n/a
536n/a def test_keyword_args(self):
537n/a # all keywords
538n/a self.assertEqual(
539n/a getargs_keywords(arg1=(1,2), arg2=3, arg3=(4,(5,6)), arg4=(7,8,9), arg5=10),
540n/a (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
541n/a )
542n/a
543n/a def test_optional_args(self):
544n/a # missing optional keyword args, skipping tuples
545n/a self.assertEqual(
546n/a getargs_keywords(arg1=(1,2), arg2=3, arg5=10),
547n/a (1, 2, 3, -1, -1, -1, -1, -1, -1, 10)
548n/a )
549n/a
550n/a def test_required_args(self):
551n/a # required arg missing
552n/a try:
553n/a getargs_keywords(arg1=(1,2))
554n/a except TypeError as err:
555n/a self.assertEqual(str(err), "Required argument 'arg2' (pos 2) not found")
556n/a else:
557n/a self.fail('TypeError should have been raised')
558n/a
559n/a def test_too_many_args(self):
560n/a try:
561n/a getargs_keywords((1,2),3,(4,(5,6)),(7,8,9),10,111)
562n/a except TypeError as err:
563n/a self.assertEqual(str(err), "function takes at most 5 arguments (6 given)")
564n/a else:
565n/a self.fail('TypeError should have been raised')
566n/a
567n/a def test_invalid_keyword(self):
568n/a # extraneous keyword arg
569n/a try:
570n/a getargs_keywords((1,2),3,arg5=10,arg666=666)
571n/a except TypeError as err:
572n/a self.assertEqual(str(err), "'arg666' is an invalid keyword argument for this function")
573n/a else:
574n/a self.fail('TypeError should have been raised')
575n/a
576n/a def test_surrogate_keyword(self):
577n/a try:
578n/a getargs_keywords((1,2), 3, (4,(5,6)), (7,8,9), **{'\uDC80': 10})
579n/a except TypeError as err:
580n/a self.assertEqual(str(err), "'\udc80' is an invalid keyword argument for this function")
581n/a else:
582n/a self.fail('TypeError should have been raised')
583n/a
584n/aclass KeywordOnly_TestCase(unittest.TestCase):
585n/a def test_positional_args(self):
586n/a # using all possible positional args
587n/a self.assertEqual(
588n/a getargs_keyword_only(1, 2),
589n/a (1, 2, -1)
590n/a )
591n/a
592n/a def test_mixed_args(self):
593n/a # positional and keyword args
594n/a self.assertEqual(
595n/a getargs_keyword_only(1, 2, keyword_only=3),
596n/a (1, 2, 3)
597n/a )
598n/a
599n/a def test_keyword_args(self):
600n/a # all keywords
601n/a self.assertEqual(
602n/a getargs_keyword_only(required=1, optional=2, keyword_only=3),
603n/a (1, 2, 3)
604n/a )
605n/a
606n/a def test_optional_args(self):
607n/a # missing optional keyword args, skipping tuples
608n/a self.assertEqual(
609n/a getargs_keyword_only(required=1, optional=2),
610n/a (1, 2, -1)
611n/a )
612n/a self.assertEqual(
613n/a getargs_keyword_only(required=1, keyword_only=3),
614n/a (1, -1, 3)
615n/a )
616n/a
617n/a def test_required_args(self):
618n/a self.assertEqual(
619n/a getargs_keyword_only(1),
620n/a (1, -1, -1)
621n/a )
622n/a self.assertEqual(
623n/a getargs_keyword_only(required=1),
624n/a (1, -1, -1)
625n/a )
626n/a # required arg missing
627n/a with self.assertRaisesRegex(TypeError,
628n/a r"Required argument 'required' \(pos 1\) not found"):
629n/a getargs_keyword_only(optional=2)
630n/a
631n/a with self.assertRaisesRegex(TypeError,
632n/a r"Required argument 'required' \(pos 1\) not found"):
633n/a getargs_keyword_only(keyword_only=3)
634n/a
635n/a def test_too_many_args(self):
636n/a with self.assertRaisesRegex(TypeError,
637n/a r"Function takes at most 2 positional arguments \(3 given\)"):
638n/a getargs_keyword_only(1, 2, 3)
639n/a
640n/a with self.assertRaisesRegex(TypeError,
641n/a r"function takes at most 3 arguments \(4 given\)"):
642n/a getargs_keyword_only(1, 2, 3, keyword_only=5)
643n/a
644n/a def test_invalid_keyword(self):
645n/a # extraneous keyword arg
646n/a with self.assertRaisesRegex(TypeError,
647n/a "'monster' is an invalid keyword argument for this function"):
648n/a getargs_keyword_only(1, 2, monster=666)
649n/a
650n/a def test_surrogate_keyword(self):
651n/a with self.assertRaisesRegex(TypeError,
652n/a "'\udc80' is an invalid keyword argument for this function"):
653n/a getargs_keyword_only(1, 2, **{'\uDC80': 10})
654n/a
655n/a
656n/aclass PositionalOnlyAndKeywords_TestCase(unittest.TestCase):
657n/a from _testcapi import getargs_positional_only_and_keywords as getargs
658n/a
659n/a def test_positional_args(self):
660n/a # using all possible positional args
661n/a self.assertEqual(self.getargs(1, 2, 3), (1, 2, 3))
662n/a
663n/a def test_mixed_args(self):
664n/a # positional and keyword args
665n/a self.assertEqual(self.getargs(1, 2, keyword=3), (1, 2, 3))
666n/a
667n/a def test_optional_args(self):
668n/a # missing optional args
669n/a self.assertEqual(self.getargs(1, 2), (1, 2, -1))
670n/a self.assertEqual(self.getargs(1, keyword=3), (1, -1, 3))
671n/a
672n/a def test_required_args(self):
673n/a self.assertEqual(self.getargs(1), (1, -1, -1))
674n/a # required positional arg missing
675n/a with self.assertRaisesRegex(TypeError,
676n/a r"Function takes at least 1 positional arguments \(0 given\)"):
677n/a self.getargs()
678n/a
679n/a with self.assertRaisesRegex(TypeError,
680n/a r"Function takes at least 1 positional arguments \(0 given\)"):
681n/a self.getargs(keyword=3)
682n/a
683n/a def test_empty_keyword(self):
684n/a with self.assertRaisesRegex(TypeError,
685n/a "'' is an invalid keyword argument for this function"):
686n/a self.getargs(1, 2, **{'': 666})
687n/a
688n/a
689n/aclass Bytes_TestCase(unittest.TestCase):
690n/a def test_c(self):
691n/a from _testcapi import getargs_c
692n/a self.assertRaises(TypeError, getargs_c, b'abc') # len > 1
693n/a self.assertEqual(getargs_c(b'a'), 97)
694n/a self.assertEqual(getargs_c(bytearray(b'a')), 97)
695n/a self.assertRaises(TypeError, getargs_c, memoryview(b'a'))
696n/a self.assertRaises(TypeError, getargs_c, 's')
697n/a self.assertRaises(TypeError, getargs_c, 97)
698n/a self.assertRaises(TypeError, getargs_c, None)
699n/a
700n/a def test_y(self):
701n/a from _testcapi import getargs_y
702n/a self.assertRaises(TypeError, getargs_y, 'abc\xe9')
703n/a self.assertEqual(getargs_y(b'bytes'), b'bytes')
704n/a self.assertRaises(ValueError, getargs_y, b'nul:\0')
705n/a self.assertRaises(TypeError, getargs_y, bytearray(b'bytearray'))
706n/a self.assertRaises(TypeError, getargs_y, memoryview(b'memoryview'))
707n/a self.assertRaises(TypeError, getargs_y, None)
708n/a
709n/a def test_y_star(self):
710n/a from _testcapi import getargs_y_star
711n/a self.assertRaises(TypeError, getargs_y_star, 'abc\xe9')
712n/a self.assertEqual(getargs_y_star(b'bytes'), b'bytes')
713n/a self.assertEqual(getargs_y_star(b'nul:\0'), b'nul:\0')
714n/a self.assertEqual(getargs_y_star(bytearray(b'bytearray')), b'bytearray')
715n/a self.assertEqual(getargs_y_star(memoryview(b'memoryview')), b'memoryview')
716n/a self.assertRaises(TypeError, getargs_y_star, None)
717n/a
718n/a def test_y_hash(self):
719n/a from _testcapi import getargs_y_hash
720n/a self.assertRaises(TypeError, getargs_y_hash, 'abc\xe9')
721n/a self.assertEqual(getargs_y_hash(b'bytes'), b'bytes')
722n/a self.assertEqual(getargs_y_hash(b'nul:\0'), b'nul:\0')
723n/a self.assertRaises(TypeError, getargs_y_hash, bytearray(b'bytearray'))
724n/a self.assertRaises(TypeError, getargs_y_hash, memoryview(b'memoryview'))
725n/a self.assertRaises(TypeError, getargs_y_hash, None)
726n/a
727n/a def test_w_star(self):
728n/a # getargs_w_star() modifies first and last byte
729n/a from _testcapi import getargs_w_star
730n/a self.assertRaises(TypeError, getargs_w_star, 'abc\xe9')
731n/a self.assertRaises(TypeError, getargs_w_star, b'bytes')
732n/a self.assertRaises(TypeError, getargs_w_star, b'nul:\0')
733n/a self.assertRaises(TypeError, getargs_w_star, memoryview(b'bytes'))
734n/a buf = bytearray(b'bytearray')
735n/a self.assertEqual(getargs_w_star(buf), b'[ytearra]')
736n/a self.assertEqual(buf, bytearray(b'[ytearra]'))
737n/a buf = bytearray(b'memoryview')
738n/a self.assertEqual(getargs_w_star(memoryview(buf)), b'[emoryvie]')
739n/a self.assertEqual(buf, bytearray(b'[emoryvie]'))
740n/a self.assertRaises(TypeError, getargs_w_star, None)
741n/a
742n/a
743n/aclass String_TestCase(unittest.TestCase):
744n/a def test_C(self):
745n/a from _testcapi import getargs_C
746n/a self.assertRaises(TypeError, getargs_C, 'abc') # len > 1
747n/a self.assertEqual(getargs_C('a'), 97)
748n/a self.assertEqual(getargs_C('\u20ac'), 0x20ac)
749n/a self.assertEqual(getargs_C('\U0001f40d'), 0x1f40d)
750n/a self.assertRaises(TypeError, getargs_C, b'a')
751n/a self.assertRaises(TypeError, getargs_C, bytearray(b'a'))
752n/a self.assertRaises(TypeError, getargs_C, memoryview(b'a'))
753n/a self.assertRaises(TypeError, getargs_C, 97)
754n/a self.assertRaises(TypeError, getargs_C, None)
755n/a
756n/a def test_s(self):
757n/a from _testcapi import getargs_s
758n/a self.assertEqual(getargs_s('abc\xe9'), b'abc\xc3\xa9')
759n/a self.assertRaises(ValueError, getargs_s, 'nul:\0')
760n/a self.assertRaises(TypeError, getargs_s, b'bytes')
761n/a self.assertRaises(TypeError, getargs_s, bytearray(b'bytearray'))
762n/a self.assertRaises(TypeError, getargs_s, memoryview(b'memoryview'))
763n/a self.assertRaises(TypeError, getargs_s, None)
764n/a
765n/a def test_s_star(self):
766n/a from _testcapi import getargs_s_star
767n/a self.assertEqual(getargs_s_star('abc\xe9'), b'abc\xc3\xa9')
768n/a self.assertEqual(getargs_s_star('nul:\0'), b'nul:\0')
769n/a self.assertEqual(getargs_s_star(b'bytes'), b'bytes')
770n/a self.assertEqual(getargs_s_star(bytearray(b'bytearray')), b'bytearray')
771n/a self.assertEqual(getargs_s_star(memoryview(b'memoryview')), b'memoryview')
772n/a self.assertRaises(TypeError, getargs_s_star, None)
773n/a
774n/a def test_s_hash(self):
775n/a from _testcapi import getargs_s_hash
776n/a self.assertEqual(getargs_s_hash('abc\xe9'), b'abc\xc3\xa9')
777n/a self.assertEqual(getargs_s_hash('nul:\0'), b'nul:\0')
778n/a self.assertEqual(getargs_s_hash(b'bytes'), b'bytes')
779n/a self.assertRaises(TypeError, getargs_s_hash, bytearray(b'bytearray'))
780n/a self.assertRaises(TypeError, getargs_s_hash, memoryview(b'memoryview'))
781n/a self.assertRaises(TypeError, getargs_s_hash, None)
782n/a
783n/a def test_z(self):
784n/a from _testcapi import getargs_z
785n/a self.assertEqual(getargs_z('abc\xe9'), b'abc\xc3\xa9')
786n/a self.assertRaises(ValueError, getargs_z, 'nul:\0')
787n/a self.assertRaises(TypeError, getargs_z, b'bytes')
788n/a self.assertRaises(TypeError, getargs_z, bytearray(b'bytearray'))
789n/a self.assertRaises(TypeError, getargs_z, memoryview(b'memoryview'))
790n/a self.assertIsNone(getargs_z(None))
791n/a
792n/a def test_z_star(self):
793n/a from _testcapi import getargs_z_star
794n/a self.assertEqual(getargs_z_star('abc\xe9'), b'abc\xc3\xa9')
795n/a self.assertEqual(getargs_z_star('nul:\0'), b'nul:\0')
796n/a self.assertEqual(getargs_z_star(b'bytes'), b'bytes')
797n/a self.assertEqual(getargs_z_star(bytearray(b'bytearray')), b'bytearray')
798n/a self.assertEqual(getargs_z_star(memoryview(b'memoryview')), b'memoryview')
799n/a self.assertIsNone(getargs_z_star(None))
800n/a
801n/a def test_z_hash(self):
802n/a from _testcapi import getargs_z_hash
803n/a self.assertEqual(getargs_z_hash('abc\xe9'), b'abc\xc3\xa9')
804n/a self.assertEqual(getargs_z_hash('nul:\0'), b'nul:\0')
805n/a self.assertEqual(getargs_z_hash(b'bytes'), b'bytes')
806n/a self.assertRaises(TypeError, getargs_z_hash, bytearray(b'bytearray'))
807n/a self.assertRaises(TypeError, getargs_z_hash, memoryview(b'memoryview'))
808n/a self.assertIsNone(getargs_z_hash(None))
809n/a
810n/a def test_es(self):
811n/a from _testcapi import getargs_es
812n/a self.assertEqual(getargs_es('abc\xe9'), b'abc\xc3\xa9')
813n/a self.assertEqual(getargs_es('abc\xe9', 'latin1'), b'abc\xe9')
814n/a self.assertRaises(UnicodeEncodeError, getargs_es, 'abc\xe9', 'ascii')
815n/a self.assertRaises(LookupError, getargs_es, 'abc\xe9', 'spam')
816n/a self.assertRaises(TypeError, getargs_es, b'bytes', 'latin1')
817n/a self.assertRaises(TypeError, getargs_es, bytearray(b'bytearray'), 'latin1')
818n/a self.assertRaises(TypeError, getargs_es, memoryview(b'memoryview'), 'latin1')
819n/a self.assertRaises(TypeError, getargs_es, None, 'latin1')
820n/a self.assertRaises(TypeError, getargs_es, 'nul:\0', 'latin1')
821n/a
822n/a def test_et(self):
823n/a from _testcapi import getargs_et
824n/a self.assertEqual(getargs_et('abc\xe9'), b'abc\xc3\xa9')
825n/a self.assertEqual(getargs_et('abc\xe9', 'latin1'), b'abc\xe9')
826n/a self.assertRaises(UnicodeEncodeError, getargs_et, 'abc\xe9', 'ascii')
827n/a self.assertRaises(LookupError, getargs_et, 'abc\xe9', 'spam')
828n/a self.assertEqual(getargs_et(b'bytes', 'latin1'), b'bytes')
829n/a self.assertEqual(getargs_et(bytearray(b'bytearray'), 'latin1'), b'bytearray')
830n/a self.assertRaises(TypeError, getargs_et, memoryview(b'memoryview'), 'latin1')
831n/a self.assertRaises(TypeError, getargs_et, None, 'latin1')
832n/a self.assertRaises(TypeError, getargs_et, 'nul:\0', 'latin1')
833n/a self.assertRaises(TypeError, getargs_et, b'nul:\0', 'latin1')
834n/a self.assertRaises(TypeError, getargs_et, bytearray(b'nul:\0'), 'latin1')
835n/a
836n/a def test_es_hash(self):
837n/a from _testcapi import getargs_es_hash
838n/a self.assertEqual(getargs_es_hash('abc\xe9'), b'abc\xc3\xa9')
839n/a self.assertEqual(getargs_es_hash('abc\xe9', 'latin1'), b'abc\xe9')
840n/a self.assertRaises(UnicodeEncodeError, getargs_es_hash, 'abc\xe9', 'ascii')
841n/a self.assertRaises(LookupError, getargs_es_hash, 'abc\xe9', 'spam')
842n/a self.assertRaises(TypeError, getargs_es_hash, b'bytes', 'latin1')
843n/a self.assertRaises(TypeError, getargs_es_hash, bytearray(b'bytearray'), 'latin1')
844n/a self.assertRaises(TypeError, getargs_es_hash, memoryview(b'memoryview'), 'latin1')
845n/a self.assertRaises(TypeError, getargs_es_hash, None, 'latin1')
846n/a self.assertEqual(getargs_es_hash('nul:\0', 'latin1'), b'nul:\0')
847n/a
848n/a buf = bytearray(b'x'*8)
849n/a self.assertEqual(getargs_es_hash('abc\xe9', 'latin1', buf), b'abc\xe9')
850n/a self.assertEqual(buf, bytearray(b'abc\xe9\x00xxx'))
851n/a buf = bytearray(b'x'*5)
852n/a self.assertEqual(getargs_es_hash('abc\xe9', 'latin1', buf), b'abc\xe9')
853n/a self.assertEqual(buf, bytearray(b'abc\xe9\x00'))
854n/a buf = bytearray(b'x'*4)
855n/a self.assertRaises(ValueError, getargs_es_hash, 'abc\xe9', 'latin1', buf)
856n/a self.assertEqual(buf, bytearray(b'x'*4))
857n/a buf = bytearray()
858n/a self.assertRaises(ValueError, getargs_es_hash, 'abc\xe9', 'latin1', buf)
859n/a
860n/a def test_et_hash(self):
861n/a from _testcapi import getargs_et_hash
862n/a self.assertEqual(getargs_et_hash('abc\xe9'), b'abc\xc3\xa9')
863n/a self.assertEqual(getargs_et_hash('abc\xe9', 'latin1'), b'abc\xe9')
864n/a self.assertRaises(UnicodeEncodeError, getargs_et_hash, 'abc\xe9', 'ascii')
865n/a self.assertRaises(LookupError, getargs_et_hash, 'abc\xe9', 'spam')
866n/a self.assertEqual(getargs_et_hash(b'bytes', 'latin1'), b'bytes')
867n/a self.assertEqual(getargs_et_hash(bytearray(b'bytearray'), 'latin1'), b'bytearray')
868n/a self.assertRaises(TypeError, getargs_et_hash, memoryview(b'memoryview'), 'latin1')
869n/a self.assertRaises(TypeError, getargs_et_hash, None, 'latin1')
870n/a self.assertEqual(getargs_et_hash('nul:\0', 'latin1'), b'nul:\0')
871n/a self.assertEqual(getargs_et_hash(b'nul:\0', 'latin1'), b'nul:\0')
872n/a self.assertEqual(getargs_et_hash(bytearray(b'nul:\0'), 'latin1'), b'nul:\0')
873n/a
874n/a buf = bytearray(b'x'*8)
875n/a self.assertEqual(getargs_et_hash('abc\xe9', 'latin1', buf), b'abc\xe9')
876n/a self.assertEqual(buf, bytearray(b'abc\xe9\x00xxx'))
877n/a buf = bytearray(b'x'*5)
878n/a self.assertEqual(getargs_et_hash('abc\xe9', 'latin1', buf), b'abc\xe9')
879n/a self.assertEqual(buf, bytearray(b'abc\xe9\x00'))
880n/a buf = bytearray(b'x'*4)
881n/a self.assertRaises(ValueError, getargs_et_hash, 'abc\xe9', 'latin1', buf)
882n/a self.assertEqual(buf, bytearray(b'x'*4))
883n/a buf = bytearray()
884n/a self.assertRaises(ValueError, getargs_et_hash, 'abc\xe9', 'latin1', buf)
885n/a
886n/a def test_u(self):
887n/a from _testcapi import getargs_u
888n/a self.assertEqual(getargs_u('abc\xe9'), 'abc\xe9')
889n/a self.assertRaises(ValueError, getargs_u, 'nul:\0')
890n/a self.assertRaises(TypeError, getargs_u, b'bytes')
891n/a self.assertRaises(TypeError, getargs_u, bytearray(b'bytearray'))
892n/a self.assertRaises(TypeError, getargs_u, memoryview(b'memoryview'))
893n/a self.assertRaises(TypeError, getargs_u, None)
894n/a
895n/a def test_u_hash(self):
896n/a from _testcapi import getargs_u_hash
897n/a self.assertEqual(getargs_u_hash('abc\xe9'), 'abc\xe9')
898n/a self.assertEqual(getargs_u_hash('nul:\0'), 'nul:\0')
899n/a self.assertRaises(TypeError, getargs_u_hash, b'bytes')
900n/a self.assertRaises(TypeError, getargs_u_hash, bytearray(b'bytearray'))
901n/a self.assertRaises(TypeError, getargs_u_hash, memoryview(b'memoryview'))
902n/a self.assertRaises(TypeError, getargs_u_hash, None)
903n/a
904n/a def test_Z(self):
905n/a from _testcapi import getargs_Z
906n/a self.assertEqual(getargs_Z('abc\xe9'), 'abc\xe9')
907n/a self.assertRaises(ValueError, getargs_Z, 'nul:\0')
908n/a self.assertRaises(TypeError, getargs_Z, b'bytes')
909n/a self.assertRaises(TypeError, getargs_Z, bytearray(b'bytearray'))
910n/a self.assertRaises(TypeError, getargs_Z, memoryview(b'memoryview'))
911n/a self.assertIsNone(getargs_Z(None))
912n/a
913n/a def test_Z_hash(self):
914n/a from _testcapi import getargs_Z_hash
915n/a self.assertEqual(getargs_Z_hash('abc\xe9'), 'abc\xe9')
916n/a self.assertEqual(getargs_Z_hash('nul:\0'), 'nul:\0')
917n/a self.assertRaises(TypeError, getargs_Z_hash, b'bytes')
918n/a self.assertRaises(TypeError, getargs_Z_hash, bytearray(b'bytearray'))
919n/a self.assertRaises(TypeError, getargs_Z_hash, memoryview(b'memoryview'))
920n/a self.assertIsNone(getargs_Z_hash(None))
921n/a
922n/a
923n/aclass Object_TestCase(unittest.TestCase):
924n/a def test_S(self):
925n/a from _testcapi import getargs_S
926n/a obj = b'bytes'
927n/a self.assertIs(getargs_S(obj), obj)
928n/a self.assertRaises(TypeError, getargs_S, bytearray(b'bytearray'))
929n/a self.assertRaises(TypeError, getargs_S, 'str')
930n/a self.assertRaises(TypeError, getargs_S, None)
931n/a self.assertRaises(TypeError, getargs_S, memoryview(obj))
932n/a
933n/a def test_Y(self):
934n/a from _testcapi import getargs_Y
935n/a obj = bytearray(b'bytearray')
936n/a self.assertIs(getargs_Y(obj), obj)
937n/a self.assertRaises(TypeError, getargs_Y, b'bytes')
938n/a self.assertRaises(TypeError, getargs_Y, 'str')
939n/a self.assertRaises(TypeError, getargs_Y, None)
940n/a self.assertRaises(TypeError, getargs_Y, memoryview(obj))
941n/a
942n/a def test_U(self):
943n/a from _testcapi import getargs_U
944n/a obj = 'str'
945n/a self.assertIs(getargs_U(obj), obj)
946n/a self.assertRaises(TypeError, getargs_U, b'bytes')
947n/a self.assertRaises(TypeError, getargs_U, bytearray(b'bytearray'))
948n/a self.assertRaises(TypeError, getargs_U, None)
949n/a
950n/a
951n/aif __name__ == "__main__":
952n/a unittest.main()