1 | import unittest
|
---|
2 | from test import test_support
|
---|
3 |
|
---|
4 | # The test cases here cover several paths through the function calling
|
---|
5 | # code. They depend on the METH_XXX flag that is used to define a C
|
---|
6 | # function, which can't be verified from Python. If the METH_XXX decl
|
---|
7 | # for a C function changes, these tests may not cover the right paths.
|
---|
8 |
|
---|
9 | class CFunctionCalls(unittest.TestCase):
|
---|
10 |
|
---|
11 | def test_varargs0(self):
|
---|
12 | self.assertRaises(TypeError, {}.has_key)
|
---|
13 |
|
---|
14 | def test_varargs1(self):
|
---|
15 | with test_support.check_py3k_warnings():
|
---|
16 | {}.has_key(0)
|
---|
17 |
|
---|
18 | def test_varargs2(self):
|
---|
19 | self.assertRaises(TypeError, {}.has_key, 0, 1)
|
---|
20 |
|
---|
21 | def test_varargs0_ext(self):
|
---|
22 | try:
|
---|
23 | {}.has_key(*())
|
---|
24 | except TypeError:
|
---|
25 | pass
|
---|
26 |
|
---|
27 | def test_varargs1_ext(self):
|
---|
28 | with test_support.check_py3k_warnings():
|
---|
29 | {}.has_key(*(0,))
|
---|
30 |
|
---|
31 | def test_varargs2_ext(self):
|
---|
32 | try:
|
---|
33 | with test_support.check_py3k_warnings():
|
---|
34 | {}.has_key(*(1, 2))
|
---|
35 | except TypeError:
|
---|
36 | pass
|
---|
37 | else:
|
---|
38 | raise RuntimeError
|
---|
39 |
|
---|
40 | def test_varargs0_kw(self):
|
---|
41 | self.assertRaises(TypeError, {}.has_key, x=2)
|
---|
42 |
|
---|
43 | def test_varargs1_kw(self):
|
---|
44 | self.assertRaises(TypeError, {}.has_key, x=2)
|
---|
45 |
|
---|
46 | def test_varargs2_kw(self):
|
---|
47 | self.assertRaises(TypeError, {}.has_key, x=2, y=2)
|
---|
48 |
|
---|
49 | def test_oldargs0_0(self):
|
---|
50 | {}.keys()
|
---|
51 |
|
---|
52 | def test_oldargs0_1(self):
|
---|
53 | self.assertRaises(TypeError, {}.keys, 0)
|
---|
54 |
|
---|
55 | def test_oldargs0_2(self):
|
---|
56 | self.assertRaises(TypeError, {}.keys, 0, 1)
|
---|
57 |
|
---|
58 | def test_oldargs0_0_ext(self):
|
---|
59 | {}.keys(*())
|
---|
60 |
|
---|
61 | def test_oldargs0_1_ext(self):
|
---|
62 | try:
|
---|
63 | {}.keys(*(0,))
|
---|
64 | except TypeError:
|
---|
65 | pass
|
---|
66 | else:
|
---|
67 | raise RuntimeError
|
---|
68 |
|
---|
69 | def test_oldargs0_2_ext(self):
|
---|
70 | try:
|
---|
71 | {}.keys(*(1, 2))
|
---|
72 | except TypeError:
|
---|
73 | pass
|
---|
74 | else:
|
---|
75 | raise RuntimeError
|
---|
76 |
|
---|
77 | def test_oldargs0_0_kw(self):
|
---|
78 | try:
|
---|
79 | {}.keys(x=2)
|
---|
80 | except TypeError:
|
---|
81 | pass
|
---|
82 | else:
|
---|
83 | raise RuntimeError
|
---|
84 |
|
---|
85 | def test_oldargs0_1_kw(self):
|
---|
86 | self.assertRaises(TypeError, {}.keys, x=2)
|
---|
87 |
|
---|
88 | def test_oldargs0_2_kw(self):
|
---|
89 | self.assertRaises(TypeError, {}.keys, x=2, y=2)
|
---|
90 |
|
---|
91 | def test_oldargs1_0(self):
|
---|
92 | self.assertRaises(TypeError, [].count)
|
---|
93 |
|
---|
94 | def test_oldargs1_1(self):
|
---|
95 | [].count(1)
|
---|
96 |
|
---|
97 | def test_oldargs1_2(self):
|
---|
98 | self.assertRaises(TypeError, [].count, 1, 2)
|
---|
99 |
|
---|
100 | def test_oldargs1_0_ext(self):
|
---|
101 | try:
|
---|
102 | [].count(*())
|
---|
103 | except TypeError:
|
---|
104 | pass
|
---|
105 | else:
|
---|
106 | raise RuntimeError
|
---|
107 |
|
---|
108 | def test_oldargs1_1_ext(self):
|
---|
109 | [].count(*(1,))
|
---|
110 |
|
---|
111 | def test_oldargs1_2_ext(self):
|
---|
112 | try:
|
---|
113 | [].count(*(1, 2))
|
---|
114 | except TypeError:
|
---|
115 | pass
|
---|
116 | else:
|
---|
117 | raise RuntimeError
|
---|
118 |
|
---|
119 | def test_oldargs1_0_kw(self):
|
---|
120 | self.assertRaises(TypeError, [].count, x=2)
|
---|
121 |
|
---|
122 | def test_oldargs1_1_kw(self):
|
---|
123 | self.assertRaises(TypeError, [].count, {}, x=2)
|
---|
124 |
|
---|
125 | def test_oldargs1_2_kw(self):
|
---|
126 | self.assertRaises(TypeError, [].count, x=2, y=2)
|
---|
127 |
|
---|
128 |
|
---|
129 | def test_main():
|
---|
130 | test_support.run_unittest(CFunctionCalls)
|
---|
131 |
|
---|
132 |
|
---|
133 | if __name__ == "__main__":
|
---|
134 | test_main()
|
---|