|
6 | 6 |
|
7 | 7 |
|
8 | 8 | class Constant(enum.IntEnum):
|
9 |
| - Py_NONE_IDX = 0 |
10 |
| - Py_FALSE_IDX = 1 |
11 |
| - Py_TRUE_IDX = 2 |
12 |
| - Py_ELLIPSIS_IDX = 3 |
13 |
| - Py_NOT_IMPLEMENTED_IDX = 4 |
14 |
| - Py_ZERO_IDX = 5 |
15 |
| - Py_ONE_IDX = 6 |
16 |
| - Py_EMPTY_STR_IDX = 7 |
17 |
| - Py_EMPTY_BYTES_IDX = 8 |
18 |
| - Py_EMPTY_TUPLE_IDX = 9 |
| 9 | + Py_CONSTANT_NONE = 0 |
| 10 | + Py_CONSTANT_FALSE = 1 |
| 11 | + Py_CONSTANT_TRUE = 2 |
| 12 | + Py_CONSTANT_ELLIPSIS = 3 |
| 13 | + Py_CONSTANT_NOT_IMPLEMENTED = 4 |
| 14 | + Py_CONSTANT_ZERO = 5 |
| 15 | + Py_CONSTANT_ONE = 6 |
| 16 | + Py_CONSTANT_EMPTY_STR = 7 |
| 17 | + Py_CONSTANT_EMPTY_BYTES = 8 |
| 18 | + Py_CONSTANT_EMPTY_TUPLE = 9 |
19 | 19 |
|
20 |
| - INVALID_IDX = Py_EMPTY_TUPLE_IDX + 1 |
| 20 | + INVALID_CONSTANT = Py_CONSTANT_EMPTY_TUPLE + 1 |
21 | 21 |
|
22 | 22 |
|
23 | 23 | class CAPITest(unittest.TestCase):
|
24 | 24 | def check_get_constant(self, get_constant):
|
25 |
| - self.assertIs(get_constant(Constant.Py_NONE_IDX), None) |
26 |
| - self.assertIs(get_constant(Constant.Py_FALSE_IDX), False) |
27 |
| - self.assertIs(get_constant(Constant.Py_TRUE_IDX), True) |
28 |
| - self.assertIs(get_constant(Constant.Py_ELLIPSIS_IDX), Ellipsis) |
29 |
| - self.assertIs(get_constant(Constant.Py_NOT_IMPLEMENTED_IDX), NotImplemented) |
| 25 | + self.assertIs(get_constant(Constant.Py_CONSTANT_NONE), None) |
| 26 | + self.assertIs(get_constant(Constant.Py_CONSTANT_FALSE), False) |
| 27 | + self.assertIs(get_constant(Constant.Py_CONSTANT_TRUE), True) |
| 28 | + self.assertIs(get_constant(Constant.Py_CONSTANT_ELLIPSIS), Ellipsis) |
| 29 | + self.assertIs(get_constant(Constant.Py_CONSTANT_NOT_IMPLEMENTED), NotImplemented) |
30 | 30 |
|
31 | 31 | for constant_id, constant_type, value in (
|
32 |
| - (Constant.Py_ZERO_IDX, int, 0), |
33 |
| - (Constant.Py_ONE_IDX, int, 1), |
34 |
| - (Constant.Py_EMPTY_STR_IDX, str, ""), |
35 |
| - (Constant.Py_EMPTY_BYTES_IDX, bytes, b""), |
36 |
| - (Constant.Py_EMPTY_TUPLE_IDX, tuple, ()), |
| 32 | + (Constant.Py_CONSTANT_ZERO, int, 0), |
| 33 | + (Constant.Py_CONSTANT_ONE, int, 1), |
| 34 | + (Constant.Py_CONSTANT_EMPTY_STR, str, ""), |
| 35 | + (Constant.Py_CONSTANT_EMPTY_BYTES, bytes, b""), |
| 36 | + (Constant.Py_CONSTANT_EMPTY_TUPLE, tuple, ()), |
37 | 37 | ):
|
38 | 38 | with self.subTest(constant_id=constant_id):
|
39 | 39 | obj = get_constant(constant_id)
|
40 | 40 | self.assertEqual(type(obj), constant_type, obj)
|
41 | 41 | self.assertEqual(obj, value)
|
42 | 42 |
|
43 | 43 | with self.assertRaises(ValueError):
|
44 |
| - get_constant(Constant.INVALID_IDX) |
| 44 | + get_constant(Constant.INVALID_CONSTANT) |
45 | 45 |
|
46 | 46 | def test_get_constant(self):
|
47 | 47 | self.check_get_constant(_testlimitedcapi.get_constant)
|
|
0 commit comments