33#include "base.h"
44#include "test_common.h"
55
6- static PyObject * base_module ;
7-
86/* setUp and tearDown must be nonstatic void(void) */
97void setUp (void ) {}
108
@@ -15,13 +13,31 @@ void tearDown(void) {}
1513 */
1614PG_CTEST (test__pg_is_int_tuple_nominal )(PyObject * self , PyObject * _null ) {
1715 PyObject * arg1 = Py_BuildValue ("(iii)" , 1 , 2 , 3 );
16+ if (!arg1 ) {
17+ // exception already set by Py_BuildValue
18+ return NULL ;
19+ }
20+
1821 PyObject * arg2 = Py_BuildValue ("(iii)" , -1 , -2 , -3 );
22+ if (!arg2 ) {
23+ // exception already set by Py_BuildValue
24+ return NULL ;
25+ }
26+
1927 PyObject * arg3 = Py_BuildValue ("(iii)" , 1 , -2 , -3 );
28+ if (!arg3 ) {
29+ // exception already set by Py_BuildValue
30+ return NULL ;
31+ }
2032
2133 TEST_ASSERT_EQUAL (1 , _pg_is_int_tuple (arg1 ));
2234 TEST_ASSERT_EQUAL (1 , _pg_is_int_tuple (arg2 ));
2335 TEST_ASSERT_EQUAL (1 , _pg_is_int_tuple (arg3 ));
2436
37+ Py_DECREF (arg1 );
38+ Py_DECREF (arg2 );
39+ Py_DECREF (arg3 );
40+
2541 Py_RETURN_NONE ;
2642}
2743
@@ -31,14 +47,31 @@ PG_CTEST(test__pg_is_int_tuple_nominal)(PyObject *self, PyObject *_null) {
3147PG_CTEST (test__pg_is_int_tuple_failureModes )(PyObject * self , PyObject * _null ) {
3248 PyObject * arg1 =
3349 Py_BuildValue ("(sss)" , (char * )"Larry" , (char * )"Moe" , (char * )"Curly" );
34- PyObject * arg2 = Py_BuildValue ("(sss)" , (char * )NULL , (char * )NULL ,
35- (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+
3661 PyObject * arg3 = Py_BuildValue ("(OOO)" , arg1 , arg2 , arg1 );
62+ if (!arg3 ) {
63+ // exception already set by Py_BuildValue
64+ return NULL ;
65+ }
3766
3867 TEST_ASSERT_EQUAL (0 , _pg_is_int_tuple (arg1 ));
3968 TEST_ASSERT_EQUAL (0 , _pg_is_int_tuple (arg2 ));
4069 TEST_ASSERT_EQUAL (0 , _pg_is_int_tuple (arg3 ));
4170
71+ Py_DECREF (arg1 );
72+ Py_DECREF (arg2 );
73+ Py_DECREF (arg3 );
74+
4275 Py_RETURN_NONE ;
4376}
4477
@@ -47,13 +80,31 @@ PG_CTEST(test__pg_is_int_tuple_failureModes)(PyObject *self, PyObject *_null) {
4780 */
4881PG_CTEST (test__pg_is_int_tuple_floats )(PyObject * self , PyObject * _null ) {
4982 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+
5088 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+
5194 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+ }
5299
53100 TEST_ASSERT_EQUAL (0 , _pg_is_int_tuple (arg1 ));
54101 TEST_ASSERT_EQUAL (0 , _pg_is_int_tuple (arg2 ));
55102 TEST_ASSERT_EQUAL (0 , _pg_is_int_tuple (arg3 ));
56103
104+ Py_DECREF (arg1 );
105+ Py_DECREF (arg2 );
106+ Py_DECREF (arg3 );
107+
57108 Py_RETURN_NONE ;
58109}
59110
@@ -74,6 +125,8 @@ static PyObject *reset_test(PyObject *self, PyObject *_null) {
74125/*=======Run The Tests=======*/
75126static PyObject * run_tests (PyObject * self , PyObject * _null ) {
76127 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
77130 RUN_TEST_PG_INTERNAL (test__pg_is_int_tuple_nominal );
78131 RUN_TEST_PG_INTERNAL (test__pg_is_int_tuple_failureModes );
79132 RUN_TEST_PG_INTERNAL (test__pg_is_int_tuple_floats );
@@ -91,10 +144,11 @@ static PyMethodDef base_test_methods[] = {
91144 {"test__pg_is_int_tuple_floats" , (PyCFunction )test__pg_is_int_tuple_floats ,
92145 METH_NOARGS , "Tests _pg_is_int_tuple when passed a tuple of floats" },
93146 {"reset_test" , (PyCFunction )reset_test , METH_NOARGS ,
94- "Resets the test suite between tests, run_tests automatically calls this "
95- "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." },
96150 {"run_tests" , (PyCFunction )run_tests , METH_NOARGS ,
97- "Runs all the tests in this test wuite " },
151+ "Runs all the tests in this test suite " },
98152 {NULL , NULL , 0 , NULL }};
99153
100154MODINIT_DEFINE (base_ctest ) {
0 commit comments