3
3
#include "base.h"
4
4
#include "test_common.h"
5
5
6
- static PyObject * base_module ;
7
-
8
6
/* setUp and tearDown must be nonstatic void(void) */
9
7
void setUp (void ) {}
10
8
@@ -15,8 +13,22 @@ void tearDown(void) {}
15
13
*/
16
14
PG_CTEST (test__pg_is_int_tuple_nominal )(PyObject * self , PyObject * _null ) {
17
15
PyObject * arg1 = Py_BuildValue ("(iii)" , 1 , 2 , 3 );
16
+ if (!arg1 ) {
17
+ // exception already set by Py_BuildValue
18
+ return NULL ;
19
+ }
20
+
18
21
PyObject * arg2 = Py_BuildValue ("(iii)" , -1 , -2 , -3 );
22
+ if (!arg2 ) {
23
+ // exception already set by Py_BuildValue
24
+ return NULL ;
25
+ }
26
+
19
27
PyObject * arg3 = Py_BuildValue ("(iii)" , 1 , -2 , -3 );
28
+ if (!arg3 ) {
29
+ // exception already set by Py_BuildValue
30
+ return NULL ;
31
+ }
20
32
21
33
TEST_ASSERT_EQUAL (1 , _pg_is_int_tuple (arg1 ));
22
34
TEST_ASSERT_EQUAL (1 , _pg_is_int_tuple (arg2 ));
@@ -35,9 +47,22 @@ PG_CTEST(test__pg_is_int_tuple_nominal)(PyObject *self, PyObject *_null) {
35
47
PG_CTEST (test__pg_is_int_tuple_failureModes )(PyObject * self , PyObject * _null ) {
36
48
PyObject * arg1 =
37
49
Py_BuildValue ("(sss)" , (char * )"Larry" , (char * )"Moe" , (char * )"Curly" );
38
- PyObject * arg2 = Py_BuildValue ("(zzz)" , (char * )NULL , (char * )NULL ,
39
- (char * )NULL ); // tuple of None's
50
+ if (!arg1 ) {
51
+ // exception already set by Py_BuildValue
52
+ return NULL ;
53
+ }
54
+
55
+ PyObject * arg2 = Py_BuildValue ("(zzz)" , NULL , NULL , NULL ); // tuple of None's
56
+ if (!arg2 ) {
57
+ // exception already set by Py_BuildValue
58
+ return NULL ;
59
+ }
60
+
40
61
PyObject * arg3 = Py_BuildValue ("(OOO)" , arg1 , arg2 , arg1 );
62
+ if (!arg3 ) {
63
+ // exception already set by Py_BuildValue
64
+ return NULL ;
65
+ }
41
66
42
67
TEST_ASSERT_EQUAL (0 , _pg_is_int_tuple (arg1 ));
43
68
TEST_ASSERT_EQUAL (0 , _pg_is_int_tuple (arg2 ));
@@ -55,8 +80,22 @@ PG_CTEST(test__pg_is_int_tuple_failureModes)(PyObject *self, PyObject *_null) {
55
80
*/
56
81
PG_CTEST (test__pg_is_int_tuple_floats )(PyObject * self , PyObject * _null ) {
57
82
PyObject * arg1 = Py_BuildValue ("(ddd)" , 1.0 , 2.0 , 3.0 );
83
+ if (!arg1 ) {
84
+ // exception already set by Py_BuildValue
85
+ return NULL ;
86
+ }
87
+
58
88
PyObject * arg2 = Py_BuildValue ("(ddd)" , -1.1 , -2.2 , -3.3 );
89
+ if (!arg2 ) {
90
+ // exception already set by Py_BuildValue
91
+ return NULL ;
92
+ }
93
+
59
94
PyObject * arg3 = Py_BuildValue ("(ddd)" , 1.0 , -2.0 , -3.1 );
95
+ if (!arg3 ) {
96
+ // exception already set by Py_BuildValue
97
+ return NULL ;
98
+ }
60
99
61
100
TEST_ASSERT_EQUAL (0 , _pg_is_int_tuple (arg1 ));
62
101
TEST_ASSERT_EQUAL (0 , _pg_is_int_tuple (arg2 ));
@@ -86,6 +125,8 @@ static PyObject *reset_test(PyObject *self, PyObject *_null) {
86
125
/*=======Run The Tests=======*/
87
126
static PyObject * run_tests (PyObject * self , PyObject * _null ) {
88
127
UnityBegin ("base_ctest.c" );
128
+ // This macro has calls to setUp and tearDown already baked into it
129
+ // so there's no need to explicitly call resetTest between test cases
89
130
RUN_TEST_PG_INTERNAL (test__pg_is_int_tuple_nominal );
90
131
RUN_TEST_PG_INTERNAL (test__pg_is_int_tuple_failureModes );
91
132
RUN_TEST_PG_INTERNAL (test__pg_is_int_tuple_floats );
@@ -103,10 +144,11 @@ static PyMethodDef base_test_methods[] = {
103
144
{"test__pg_is_int_tuple_floats" , (PyCFunction )test__pg_is_int_tuple_floats ,
104
145
METH_NOARGS , "Tests _pg_is_int_tuple when passed a tuple of floats" },
105
146
{"reset_test" , (PyCFunction )reset_test , METH_NOARGS ,
106
- "Resets the test suite between tests, run_tests automatically calls this "
107
- "after each test case it calls" },
147
+ "Explicitly runs tearDown(); setUp(). Note: RUN_TEST_PG_INTERNAL calls "
148
+ "setUp/tearDown around each test; run_tests does not call reset_test "
149
+ "explicitly." },
108
150
{"run_tests" , (PyCFunction )run_tests , METH_NOARGS ,
109
- "Runs all the tests in this test wuite " },
151
+ "Runs all the tests in this test suite " },
110
152
{NULL , NULL , 0 , NULL }};
111
153
112
154
MODINIT_DEFINE (base_ctest ) {
0 commit comments