move sections
[python/dscho.git] / Lib / test / test_call.py
blobd06c2c94c53b0d9ee05e2457eff80c59db05b396
1 import unittest
2 from test import test_support
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.
9 class CFunctionCalls(unittest.TestCase):
11 def test_varargs0(self):
12 self.assertRaises(TypeError, {}.has_key)
14 def test_varargs1(self):
15 with test_support.check_py3k_warnings():
16 {}.has_key(0)
18 def test_varargs2(self):
19 self.assertRaises(TypeError, {}.has_key, 0, 1)
21 def test_varargs0_ext(self):
22 try:
23 {}.has_key(*())
24 except TypeError:
25 pass
27 def test_varargs1_ext(self):
28 with test_support.check_py3k_warnings():
29 {}.has_key(*(0,))
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
40 def test_varargs0_kw(self):
41 self.assertRaises(TypeError, {}.has_key, x=2)
43 def test_varargs1_kw(self):
44 self.assertRaises(TypeError, {}.has_key, x=2)
46 def test_varargs2_kw(self):
47 self.assertRaises(TypeError, {}.has_key, x=2, y=2)
49 def test_oldargs0_0(self):
50 {}.keys()
52 def test_oldargs0_1(self):
53 self.assertRaises(TypeError, {}.keys, 0)
55 def test_oldargs0_2(self):
56 self.assertRaises(TypeError, {}.keys, 0, 1)
58 def test_oldargs0_0_ext(self):
59 {}.keys(*())
61 def test_oldargs0_1_ext(self):
62 try:
63 {}.keys(*(0,))
64 except TypeError:
65 pass
66 else:
67 raise RuntimeError
69 def test_oldargs0_2_ext(self):
70 try:
71 {}.keys(*(1, 2))
72 except TypeError:
73 pass
74 else:
75 raise RuntimeError
77 def test_oldargs0_0_kw(self):
78 try:
79 {}.keys(x=2)
80 except TypeError:
81 pass
82 else:
83 raise RuntimeError
85 def test_oldargs0_1_kw(self):
86 self.assertRaises(TypeError, {}.keys, x=2)
88 def test_oldargs0_2_kw(self):
89 self.assertRaises(TypeError, {}.keys, x=2, y=2)
91 def test_oldargs1_0(self):
92 self.assertRaises(TypeError, [].count)
94 def test_oldargs1_1(self):
95 [].count(1)
97 def test_oldargs1_2(self):
98 self.assertRaises(TypeError, [].count, 1, 2)
100 def test_oldargs1_0_ext(self):
101 try:
102 [].count(*())
103 except TypeError:
104 pass
105 else:
106 raise RuntimeError
108 def test_oldargs1_1_ext(self):
109 [].count(*(1,))
111 def test_oldargs1_2_ext(self):
112 try:
113 [].count(*(1, 2))
114 except TypeError:
115 pass
116 else:
117 raise RuntimeError
119 def test_oldargs1_0_kw(self):
120 self.assertRaises(TypeError, [].count, x=2)
122 def test_oldargs1_1_kw(self):
123 self.assertRaises(TypeError, [].count, {}, x=2)
125 def test_oldargs1_2_kw(self):
126 self.assertRaises(TypeError, [].count, x=2, y=2)
129 def test_main():
130 test_support.run_unittest(CFunctionCalls)
133 if __name__ == "__main__":
134 test_main()