10a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoimport unittest 20a8c90248264a8b26970b4473770bcc3df8515fJosh Gaofrom test import test_support 30a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 40a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# The test cases here cover several paths through the function calling 50a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# code. They depend on the METH_XXX flag that is used to define a C 60a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# function, which can't be verified from Python. If the METH_XXX decl 70a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# for a C function changes, these tests may not cover the right paths. 80a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 90a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoclass CFunctionCalls(unittest.TestCase): 100a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_varargs0(self): 120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertRaises(TypeError, {}.has_key) 130a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 140a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_varargs1(self): 150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao with test_support.check_py3k_warnings(): 160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao {}.has_key(0) 170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_varargs2(self): 190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertRaises(TypeError, {}.has_key, 0, 1) 200a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_varargs0_ext(self): 220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao try: 230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao {}.has_key(*()) 240a8c90248264a8b26970b4473770bcc3df8515fJosh Gao except TypeError: 250a8c90248264a8b26970b4473770bcc3df8515fJosh Gao pass 260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 270a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_varargs1_ext(self): 280a8c90248264a8b26970b4473770bcc3df8515fJosh Gao with test_support.check_py3k_warnings(): 290a8c90248264a8b26970b4473770bcc3df8515fJosh Gao {}.has_key(*(0,)) 300a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 310a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_varargs2_ext(self): 320a8c90248264a8b26970b4473770bcc3df8515fJosh Gao try: 330a8c90248264a8b26970b4473770bcc3df8515fJosh Gao with test_support.check_py3k_warnings(): 340a8c90248264a8b26970b4473770bcc3df8515fJosh Gao {}.has_key(*(1, 2)) 350a8c90248264a8b26970b4473770bcc3df8515fJosh Gao except TypeError: 360a8c90248264a8b26970b4473770bcc3df8515fJosh Gao pass 370a8c90248264a8b26970b4473770bcc3df8515fJosh Gao else: 380a8c90248264a8b26970b4473770bcc3df8515fJosh Gao raise RuntimeError 390a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 400a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_varargs0_kw(self): 410a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertRaises(TypeError, {}.has_key, x=2) 420a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 430a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_varargs1_kw(self): 440a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertRaises(TypeError, {}.has_key, x=2) 450a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 460a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_varargs2_kw(self): 470a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertRaises(TypeError, {}.has_key, x=2, y=2) 480a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 490a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_oldargs0_0(self): 500a8c90248264a8b26970b4473770bcc3df8515fJosh Gao {}.keys() 510a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 520a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_oldargs0_1(self): 530a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertRaises(TypeError, {}.keys, 0) 540a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 550a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_oldargs0_2(self): 560a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertRaises(TypeError, {}.keys, 0, 1) 570a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 580a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_oldargs0_0_ext(self): 590a8c90248264a8b26970b4473770bcc3df8515fJosh Gao {}.keys(*()) 600a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 610a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_oldargs0_1_ext(self): 620a8c90248264a8b26970b4473770bcc3df8515fJosh Gao try: 630a8c90248264a8b26970b4473770bcc3df8515fJosh Gao {}.keys(*(0,)) 640a8c90248264a8b26970b4473770bcc3df8515fJosh Gao except TypeError: 650a8c90248264a8b26970b4473770bcc3df8515fJosh Gao pass 660a8c90248264a8b26970b4473770bcc3df8515fJosh Gao else: 670a8c90248264a8b26970b4473770bcc3df8515fJosh Gao raise RuntimeError 680a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 690a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_oldargs0_2_ext(self): 700a8c90248264a8b26970b4473770bcc3df8515fJosh Gao try: 710a8c90248264a8b26970b4473770bcc3df8515fJosh Gao {}.keys(*(1, 2)) 720a8c90248264a8b26970b4473770bcc3df8515fJosh Gao except TypeError: 730a8c90248264a8b26970b4473770bcc3df8515fJosh Gao pass 740a8c90248264a8b26970b4473770bcc3df8515fJosh Gao else: 750a8c90248264a8b26970b4473770bcc3df8515fJosh Gao raise RuntimeError 760a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 770a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_oldargs0_0_kw(self): 780a8c90248264a8b26970b4473770bcc3df8515fJosh Gao try: 790a8c90248264a8b26970b4473770bcc3df8515fJosh Gao {}.keys(x=2) 800a8c90248264a8b26970b4473770bcc3df8515fJosh Gao except TypeError: 810a8c90248264a8b26970b4473770bcc3df8515fJosh Gao pass 820a8c90248264a8b26970b4473770bcc3df8515fJosh Gao else: 830a8c90248264a8b26970b4473770bcc3df8515fJosh Gao raise RuntimeError 840a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 850a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_oldargs0_1_kw(self): 860a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertRaises(TypeError, {}.keys, x=2) 870a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 880a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_oldargs0_2_kw(self): 890a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertRaises(TypeError, {}.keys, x=2, y=2) 900a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 910a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_oldargs1_0(self): 920a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertRaises(TypeError, [].count) 930a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 940a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_oldargs1_1(self): 950a8c90248264a8b26970b4473770bcc3df8515fJosh Gao [].count(1) 960a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 970a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_oldargs1_2(self): 980a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertRaises(TypeError, [].count, 1, 2) 990a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1000a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_oldargs1_0_ext(self): 1010a8c90248264a8b26970b4473770bcc3df8515fJosh Gao try: 1020a8c90248264a8b26970b4473770bcc3df8515fJosh Gao [].count(*()) 1030a8c90248264a8b26970b4473770bcc3df8515fJosh Gao except TypeError: 1040a8c90248264a8b26970b4473770bcc3df8515fJosh Gao pass 1050a8c90248264a8b26970b4473770bcc3df8515fJosh Gao else: 1060a8c90248264a8b26970b4473770bcc3df8515fJosh Gao raise RuntimeError 1070a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1080a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_oldargs1_1_ext(self): 1090a8c90248264a8b26970b4473770bcc3df8515fJosh Gao [].count(*(1,)) 1100a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_oldargs1_2_ext(self): 1120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao try: 1130a8c90248264a8b26970b4473770bcc3df8515fJosh Gao [].count(*(1, 2)) 1140a8c90248264a8b26970b4473770bcc3df8515fJosh Gao except TypeError: 1150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao pass 1160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao else: 1170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao raise RuntimeError 1180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_oldargs1_0_kw(self): 1200a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertRaises(TypeError, [].count, x=2) 1210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_oldargs1_1_kw(self): 1230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertRaises(TypeError, [].count, {}, x=2) 1240a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1250a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_oldargs1_2_kw(self): 1260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.assertRaises(TypeError, [].count, x=2, y=2) 1270a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1280a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1290a8c90248264a8b26970b4473770bcc3df8515fJosh Gaodef test_main(): 1300a8c90248264a8b26970b4473770bcc3df8515fJosh Gao test_support.run_unittest(CFunctionCalls) 1310a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1320a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1330a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoif __name__ == "__main__": 1340a8c90248264a8b26970b4473770bcc3df8515fJosh Gao test_main() 135