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