Home | History | Annotate | Download | only in test
      1 import 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 
      8 class 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     def test_oldargs0_0_kw(self):
     74         try:
     75             {}.keys(x=2)
     76         except TypeError:
     77             pass
     78         else:
     79             raise RuntimeError
     80 
     81     def test_oldargs0_1_kw(self):
     82         self.assertRaises(TypeError, {}.keys, x=2)
     83 
     84     def test_oldargs0_2_kw(self):
     85         self.assertRaises(TypeError, {}.keys, x=2, y=2)
     86 
     87     def test_oldargs1_0(self):
     88         self.assertRaises(TypeError, [].count)
     89 
     90     def test_oldargs1_1(self):
     91         [].count(1)
     92 
     93     def test_oldargs1_2(self):
     94         self.assertRaises(TypeError, [].count, 1, 2)
     95 
     96     def test_oldargs1_0_ext(self):
     97         try:
     98             [].count(*())
     99         except TypeError:
    100             pass
    101         else:
    102             raise RuntimeError
    103 
    104     def test_oldargs1_1_ext(self):
    105         [].count(*(1,))
    106 
    107     def test_oldargs1_2_ext(self):
    108         try:
    109             [].count(*(1, 2))
    110         except TypeError:
    111             pass
    112         else:
    113             raise RuntimeError
    114 
    115     def test_oldargs1_0_kw(self):
    116         self.assertRaises(TypeError, [].count, x=2)
    117 
    118     def test_oldargs1_1_kw(self):
    119         self.assertRaises(TypeError, [].count, {}, x=2)
    120 
    121     def test_oldargs1_2_kw(self):
    122         self.assertRaises(TypeError, [].count, x=2, y=2)
    123 
    124 
    125 if __name__ == "__main__":
    126     unittest.main()
    127