From 80b7fc53281a597e40dce6a193eaa95e03f4b425 Mon Sep 17 00:00:00 2001 From: Gertjan van den Burg Date: Sat, 15 Jun 2024 13:31:10 +0100 Subject: [PATCH] Fix module names of C module objects (fixes #128) (#131) --- src/abstraction.c | 2 +- src/cparser.c | 4 ++-- tests/test_unit/test_c_file_naming.py | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 tests/test_unit/test_c_file_naming.py diff --git a/src/abstraction.c b/src/abstraction.c index 1fee2fd4..fc5111cc 100644 --- a/src/abstraction.c +++ b/src/abstraction.c @@ -290,7 +290,7 @@ static struct PyMethodDef cabstraction_methods[] = { static struct PyModuleDef moduledef = { PyModuleDef_HEAD_INIT, - "ccsv.cabstraction", + "clevercsv.cabstraction", cabstraction_module_doc, -1, cabstraction_methods, diff --git a/src/cparser.c b/src/cparser.c index 6b31279e..b9786173 100644 --- a/src/cparser.c +++ b/src/cparser.c @@ -698,7 +698,7 @@ static struct PyMethodDef cparser_methods[] = { static struct PyModuleDef _cparsermodule = { PyModuleDef_HEAD_INIT, - "ccsv.cparser", + "clevercsv.cparser", cparser_module_doc, sizeof(_cparserstate), cparser_methods, @@ -727,7 +727,7 @@ PyMODINIT_FUNC PyInit_cparser(void) /* Add the CSV exception object to the module. */ - _cparserstate(module)->error_obj = PyErr_NewException("cparser.Error", NULL, NULL); + _cparserstate(module)->error_obj = PyErr_NewException("clevercsv.cparser.Error", NULL, NULL); if (_cparserstate(module)->error_obj == NULL) return NULL; Py_INCREF(_cparserstate(module)->error_obj); diff --git a/tests/test_unit/test_c_file_naming.py b/tests/test_unit/test_c_file_naming.py new file mode 100644 index 00000000..8e6620b4 --- /dev/null +++ b/tests/test_unit/test_c_file_naming.py @@ -0,0 +1,23 @@ +import unittest + +import clevercsv + + +class CNamingTestCase(unittest.TestCase): + def test_name_cabstraction_module(self) -> None: + self.assertEqual( + clevercsv.cabstraction.__name__, "clevercsv.cabstraction" + ) + + def test_name_cparser_module(self) -> None: + self.assertEqual(clevercsv.cparser.__name__, "clevercsv.cparser") + + def test_name_cparser_error(self) -> None: + self.assertEqual( + clevercsv.cparser.Error.__module__, "clevercsv.cparser" + ) + + def test_name_cparser_parser(self) -> None: + self.assertEqual( + clevercsv.cparser.Parser.__module__, "clevercsv.cparser" + )