Skip to content

Commit ac84921

Browse files
committed
Addressed more review comments
1 parent 5ddff7a commit ac84921

File tree

1 file changed

+49
-7
lines changed

1 file changed

+49
-7
lines changed

ctest/base_ctest.c

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
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) */
97
void setUp(void) {}
108

@@ -15,8 +13,22 @@ void tearDown(void) {}
1513
*/
1614
PG_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));
@@ -35,9 +47,22 @@ PG_CTEST(test__pg_is_int_tuple_nominal)(PyObject *self, PyObject *_null) {
3547
PG_CTEST(test__pg_is_int_tuple_failureModes)(PyObject *self, PyObject *_null) {
3648
PyObject *arg1 =
3749
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+
4061
PyObject *arg3 = Py_BuildValue("(OOO)", arg1, arg2, arg1);
62+
if (!arg3) {
63+
// exception already set by Py_BuildValue
64+
return NULL;
65+
}
4166

4267
TEST_ASSERT_EQUAL(0, _pg_is_int_tuple(arg1));
4368
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) {
5580
*/
5681
PG_CTEST(test__pg_is_int_tuple_floats)(PyObject *self, PyObject *_null) {
5782
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+
5888
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+
5994
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+
}
6099

61100
TEST_ASSERT_EQUAL(0, _pg_is_int_tuple(arg1));
62101
TEST_ASSERT_EQUAL(0, _pg_is_int_tuple(arg2));
@@ -86,6 +125,8 @@ static PyObject *reset_test(PyObject *self, PyObject *_null) {
86125
/*=======Run The Tests=======*/
87126
static PyObject *run_tests(PyObject *self, PyObject *_null) {
88127
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
89130
RUN_TEST_PG_INTERNAL(test__pg_is_int_tuple_nominal);
90131
RUN_TEST_PG_INTERNAL(test__pg_is_int_tuple_failureModes);
91132
RUN_TEST_PG_INTERNAL(test__pg_is_int_tuple_floats);
@@ -103,10 +144,11 @@ static PyMethodDef base_test_methods[] = {
103144
{"test__pg_is_int_tuple_floats", (PyCFunction)test__pg_is_int_tuple_floats,
104145
METH_NOARGS, "Tests _pg_is_int_tuple when passed a tuple of floats"},
105146
{"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."},
108150
{"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"},
110152
{NULL, NULL, 0, NULL}};
111153

112154
MODINIT_DEFINE(base_ctest) {

0 commit comments

Comments
 (0)