Skip to content

Commit aeea700

Browse files
committed
Code cleanup, reverted unnecessary changes
1 parent 0301aed commit aeea700

File tree

4 files changed

+113
-94
lines changed

4 files changed

+113
-94
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ dist
5252
__pycache__
5353
_headers/*
5454
buildconfig/win_dll_dirs.json
55-
*.log
5655

5756
# cython generated files
5857
src_c/_sdl2/*.c

ctest/base_ctest.c

Lines changed: 70 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -13,74 +13,78 @@ void tearDown(void) {}
1313
/**
1414
* @brief Tests _pg_is_int_tuple when passed a tuple of ints
1515
*/
16-
static PyObject *test__pg_is_int_tuple_nominal(PyObject *self,
17-
PyObject *_null) {
18-
PyObject *arg1 = Py_BuildValue("(iii)", 1, 2, 3);
19-
PyObject *arg2 = Py_BuildValue("(iii)", -1, -2, -3);
20-
PyObject *arg3 = Py_BuildValue("(iii)", 1, -2, -3);
16+
PG_CTEST(test__pg_is_int_tuple_nominal)
17+
{
18+
PyObject *arg1 = Py_BuildValue("(iii)", 1, 2, 3);
19+
PyObject *arg2 = Py_BuildValue("(iii)", -1, -2, -3);
20+
PyObject *arg3 = Py_BuildValue("(iii)", 1, -2, -3);
2121

22-
TEST_ASSERT_EQUAL(1, _pg_is_int_tuple(arg1));
23-
TEST_ASSERT_EQUAL(1, _pg_is_int_tuple(arg2));
24-
TEST_ASSERT_EQUAL(1, _pg_is_int_tuple(arg3));
22+
TEST_ASSERT_EQUAL(1, _pg_is_int_tuple(arg1));
23+
TEST_ASSERT_EQUAL(1, _pg_is_int_tuple(arg2));
24+
TEST_ASSERT_EQUAL(1, _pg_is_int_tuple(arg3));
2525

26-
Py_RETURN_NONE;
26+
Py_RETURN_NONE;
2727
}
2828

2929
/**
3030
* @brief Tests _pg_is_int_tuple when passed a tuple of non-numeric values
3131
*/
32-
static PyObject *test__pg_is_int_tuple_failureModes(PyObject *self,
33-
PyObject *_null) {
34-
PyObject *arg1 =
35-
Py_BuildValue("(sss)", (char *)"Larry", (char *)"Moe", (char *)"Curly");
36-
PyObject *arg2 = Py_BuildValue("(sss)", (char *)NULL, (char *)NULL,
37-
(char *)NULL); // tuple of None's
38-
PyObject *arg3 = Py_BuildValue("(OOO)", arg1, arg2, arg1);
39-
40-
TEST_ASSERT_EQUAL(0, _pg_is_int_tuple(arg1));
41-
TEST_ASSERT_EQUAL(0, _pg_is_int_tuple(arg2));
42-
TEST_ASSERT_EQUAL(0, _pg_is_int_tuple(arg3));
43-
44-
Py_RETURN_NONE;
32+
PG_CTEST(test__pg_is_int_tuple_failureModes)
33+
{
34+
PyObject *arg1 =
35+
Py_BuildValue("(sss)", (char *)"Larry", (char *)"Moe", (char *)"Curly");
36+
PyObject *arg2 = Py_BuildValue("(sss)", (char *)NULL, (char *)NULL,
37+
(char *)NULL); // tuple of None's
38+
PyObject *arg3 = Py_BuildValue("(OOO)", arg1, arg2, arg1);
39+
40+
TEST_ASSERT_EQUAL(0, _pg_is_int_tuple(arg1));
41+
TEST_ASSERT_EQUAL(0, _pg_is_int_tuple(arg2));
42+
TEST_ASSERT_EQUAL(0, _pg_is_int_tuple(arg3));
43+
44+
Py_RETURN_NONE;
4545
}
4646

4747
/**
4848
* @brief Tests _pg_is_int_tuple when passed a tuple of floats
4949
*/
50-
static PyObject *test__pg_is_int_tuple_floats(PyObject *self, PyObject *_null) {
51-
PyObject *arg1 = Py_BuildValue("(ddd)", 1.0, 2.0, 3.0);
52-
PyObject *arg2 = Py_BuildValue("(ddd)", -1.1, -2.2, -3.3);
53-
PyObject *arg3 = Py_BuildValue("(ddd)", 1.0, -2.0, -3.1);
50+
PG_CTEST(test__pg_is_int_tuple_floats)
51+
{
52+
PyObject *arg1 = Py_BuildValue("(ddd)", 1.0, 2.0, 3.0);
53+
PyObject *arg2 = Py_BuildValue("(ddd)", -1.1, -2.2, -3.3);
54+
PyObject *arg3 = Py_BuildValue("(ddd)", 1.0, -2.0, -3.1);
5455

55-
TEST_ASSERT_EQUAL(0, _pg_is_int_tuple(arg1));
56-
TEST_ASSERT_EQUAL(0, _pg_is_int_tuple(arg2));
57-
TEST_ASSERT_EQUAL(0, _pg_is_int_tuple(arg3));
56+
TEST_ASSERT_EQUAL(0, _pg_is_int_tuple(arg1));
57+
TEST_ASSERT_EQUAL(0, _pg_is_int_tuple(arg2));
58+
TEST_ASSERT_EQUAL(0, _pg_is_int_tuple(arg3));
5859

59-
Py_RETURN_NONE;
60+
Py_RETURN_NONE;
6061
}
6162

6263
/*=======Test Reset Option=====*/
6364
/* This must be void(void) */
64-
void resetTest(void) {
65-
tearDown();
66-
setUp();
65+
void resetTest(void)
66+
{
67+
tearDown();
68+
setUp();
6769
}
6870

6971
/*=======Exposed Test Reset Option=====*/
70-
static PyObject *reset_test(PyObject *self, PyObject *_null) {
71-
resetTest();
72+
static PyObject *reset_test(PyObject *self, PyObject *_null)
73+
{
74+
resetTest();
7275

73-
Py_RETURN_NONE;
76+
Py_RETURN_NONE;
7477
}
7578

7679
/*=======Run The Tests=======*/
77-
static PyObject *run_tests(PyObject *self, PyObject *_null) {
78-
UnityBegin("base_ctest.c");
79-
RUN_TEST_PG_INTERNAL(test__pg_is_int_tuple_nominal, 15, self, _null);
80-
RUN_TEST_PG_INTERNAL(test__pg_is_int_tuple_failureModes, 29, self, _null);
81-
RUN_TEST_PG_INTERNAL(test__pg_is_int_tuple_floats, 46, self, _null);
82-
83-
return PyLong_FromLong(UnityEnd());
80+
static PyObject *run_tests(PyObject *self, PyObject *_null)
81+
{
82+
UnityBegin("base_ctest.c");
83+
RUN_TEST_PG_INTERNAL(test__pg_is_int_tuple_nominal);
84+
RUN_TEST_PG_INTERNAL(test__pg_is_int_tuple_failureModes);
85+
RUN_TEST_PG_INTERNAL(test__pg_is_int_tuple_floats);
86+
87+
return PyLong_FromLong(UnityEnd());
8488
}
8589

8690
static PyMethodDef base_test_methods[] = {
@@ -99,37 +103,27 @@ static PyMethodDef base_test_methods[] = {
99103
"Runs all the tests in this test wuite"},
100104
{NULL, NULL, 0, NULL}};
101105

102-
MODINIT_DEFINE(base_ctest) {
103-
PyObject *module;
104-
105-
static struct PyModuleDef _module = {
106-
PyModuleDef_HEAD_INIT,
107-
"base_ctest",
108-
"C unit tests for the pygame.base internal implementation",
109-
-1,
110-
base_test_methods,
111-
NULL,
112-
NULL,
113-
NULL,
114-
NULL};
115-
116-
/* create the module */
117-
module = PyModule_Create(&_module);
118-
if (!module) {
119-
return NULL;
120-
}
121-
122-
return module;
106+
MODINIT_DEFINE(base_ctest)
107+
{
108+
PyObject *module;
109+
110+
static struct PyModuleDef _module = {
111+
PyModuleDef_HEAD_INIT,
112+
"base_ctest",
113+
"C unit tests for the pygame.base internal implementation",
114+
-1,
115+
base_test_methods,
116+
NULL,
117+
NULL,
118+
NULL,
119+
NULL};
120+
121+
/* create the module */
122+
module = PyModule_Create(&_module);
123+
if (!module)
124+
{
125+
return NULL;
126+
}
127+
128+
return module;
123129
}
124-
125-
// #undef main
126-
// /*=======MAIN=====*/
127-
// int main(void) {
128-
// Py_Initialize();
129-
// UnityBegin("test_base.c");
130-
// RUN_TEST(test__pg_is_int_tuple_nominal, 17);
131-
// RUN_TEST(test__pg_is_int_tuple_failureModes, 31);
132-
// RUN_TEST(test__pg_is_int_tuple_floats, 45);
133-
134-
// return (UnityEnd());
135-
// }

ctest/test_common.h

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,47 @@
1+
#include <Python.h>
2+
13
#include "unity.h"
24

35
#ifndef TEST_COMMON_H
46
#define TEST_COMMON_H
57

6-
#define RUN_TEST_PG_INTERNAL(TestFunc, TestLineNum, self_arg, null_arg) \
7-
{ \
8-
Unity.CurrentTestName = #TestFunc; \
9-
Unity.CurrentTestLineNumber = TestLineNum; \
10-
Unity.NumberOfTests++; \
11-
if (TEST_PROTECT()) { \
12-
setUp(); \
13-
TestFunc(self_arg, null_arg); \
14-
} \
15-
if (TEST_PROTECT()) { \
16-
tearDown(); \
17-
} \
18-
UnityConcludeTest(); \
19-
}
8+
struct TestCase
9+
{
10+
char *test_name;
11+
int line_num;
12+
};
13+
14+
/*
15+
This will take some explanation... the PG_CTEST macro defines two things
16+
for an individual test case. The test case itself, and a struct instance
17+
called meta_TEST_CASE_NAME. The struct has two pieces of important
18+
information that unity needs: the name in string format and the line
19+
number of the test. This would be an absolute nighmare to maintain by
20+
hand, so I defined a macro to do it automagically for us.
21+
22+
The RUN_TEST_PG_INTERNAL macro then references that struct for each test
23+
case that we tell it about and automatically populates the unity fields
24+
with the requisite data.
25+
*/
26+
#define PG_CTEST(TestFunc) \
27+
static struct TestCase meta_##TestFunc = {#TestFunc, __LINE__}; \
28+
static PyObject *TestFunc##(PyObject * self, PyObject * _null)
29+
30+
#define RUN_TEST_PG_INTERNAL(TestFunc) \
31+
{ \
32+
Unity.CurrentTestName = meta_##TestFunc.test_name; \
33+
Unity.CurrentTestLineNumber = meta_##TestFunc.line_num; \
34+
Unity.NumberOfTests++; \
35+
if (TEST_PROTECT()) \
36+
{ \
37+
setUp(); \
38+
TestFunc(self, _null); \
39+
} \
40+
if (TEST_PROTECT()) \
41+
{ \
42+
tearDown(); \
43+
} \
44+
UnityConcludeTest(); \
45+
}
2046

2147
#endif // #ifndef TEST_COMMON_H

dev.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,9 @@ def cmd_build(self):
216216
sanitize = self.args.get("sanitize")
217217
coverage = self.args.get("coverage", False)
218218
ctest = self.args.get("ctest", False)
219-
# if wheel_dir and coverage:
220-
# pprint("Cannot pass --wheel and --coverage together", Colors.RED)
221-
# sys.exit(1)
219+
if wheel_dir and coverage:
220+
pprint("Cannot pass --wheel and --coverage together", Colors.RED)
221+
sys.exit(1)
222222

223223
build_suffix = ""
224224
if debug:

0 commit comments

Comments
 (0)