From d9945c2a11dd9d75e46955f32426ff269a94e24e Mon Sep 17 00:00:00 2001 From: SimiCode Date: Sun, 5 May 2019 00:19:52 +0300 Subject: [PATCH 01/43] created a c API wrapper for pyDate_FromDate and added the test --- Lib/test/datetimetester.py | 11 ++ Modules/_testcapimodule.c | 327 ++++++++++++++++++++----------------- 2 files changed, 187 insertions(+), 151 deletions(-) diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index 9fe32ebc5b395fa..29e8d34b324703d 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -6018,6 +6018,17 @@ class TZInfoSubclass(tzinfo): with self.subTest(arg=arg, exact=exact): self.assertFalse(is_tzinfo(arg, exact)) + def test_date_from_date(self): + year = 1993 + month = 8 + day = 26 + + for macro in [0, 1]: + with self.subTest(macro=macro): + d = _testcapi.get_date_fromdate(year, month, day, macro) + + self.assertEqual(d, date(1993, 8, 26)) + def test_date_from_timestamp(self): ts = datetime(1995, 4, 12).timestamp() diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index c52e34996385ded..eb6ec12f41f483b 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2340,6 +2340,31 @@ get_timezone_utc_capi(PyObject* self, PyObject *args) { } } +static PyObject * +get_date_fromdate(PyObject *self, PyObject *args) +{ + PyObject *rv = NULL; + int year = 0, month = 0, day = 0; + int macro = 0; + + if (!PyArg_ParseTuple(args, "iii|p", &year, &month, &day, ¯o)) + { + return NULL; + } + + // Pass along to the API function + if (macro) + { + rv = PyDate_FromDate(year, month, day); + } + else + { + rv = PyDateTimeAPI->Date_FromDate(year, month, day, PyDateTimeAPI->DateType); + } + + return rv; +} + static PyObject * get_date_fromtimestamp(PyObject* self, PyObject *args) { @@ -4819,49 +4844,49 @@ negative_refcount(PyObject *self, PyObject *Py_UNUSED(args)) } #endif - static PyMethodDef TestMethods[] = { - {"raise_exception", raise_exception, METH_VARARGS}, - {"raise_memoryerror", raise_memoryerror, METH_NOARGS}, - {"set_errno", set_errno, METH_VARARGS}, - {"test_config", test_config, METH_NOARGS}, - {"test_sizeof_c_types", test_sizeof_c_types, METH_NOARGS}, - {"test_datetime_capi", test_datetime_capi, METH_NOARGS}, - {"datetime_check_date", datetime_check_date, METH_VARARGS}, - {"datetime_check_time", datetime_check_time, METH_VARARGS}, - {"datetime_check_datetime", datetime_check_datetime, METH_VARARGS}, - {"datetime_check_delta", datetime_check_delta, METH_VARARGS}, - {"datetime_check_tzinfo", datetime_check_tzinfo, METH_VARARGS}, - {"make_timezones_capi", make_timezones_capi, METH_NOARGS}, - {"get_timezones_offset_zero", get_timezones_offset_zero, METH_NOARGS}, - {"get_timezone_utc_capi", get_timezone_utc_capi, METH_VARARGS}, - {"get_date_fromtimestamp", get_date_fromtimestamp, METH_VARARGS}, - {"get_datetime_fromtimestamp", get_datetime_fromtimestamp, METH_VARARGS}, - {"test_list_api", test_list_api, METH_NOARGS}, - {"test_dict_iteration", test_dict_iteration, METH_NOARGS}, - {"dict_getitem_knownhash", dict_getitem_knownhash, METH_VARARGS}, - {"dict_hassplittable", dict_hassplittable, METH_O}, - {"test_lazy_hash_inheritance", test_lazy_hash_inheritance,METH_NOARGS}, - {"test_long_api", test_long_api, METH_NOARGS}, - {"test_xincref_doesnt_leak",test_xincref_doesnt_leak, METH_NOARGS}, - {"test_incref_doesnt_leak", test_incref_doesnt_leak, METH_NOARGS}, - {"test_xdecref_doesnt_leak",test_xdecref_doesnt_leak, METH_NOARGS}, - {"test_decref_doesnt_leak", test_decref_doesnt_leak, METH_NOARGS}, + {"raise_exception", raise_exception, METH_VARARGS}, + {"raise_memoryerror", raise_memoryerror, METH_NOARGS}, + {"set_errno", set_errno, METH_VARARGS}, + {"test_config", test_config, METH_NOARGS}, + {"test_sizeof_c_types", test_sizeof_c_types, METH_NOARGS}, + {"test_datetime_capi", test_datetime_capi, METH_NOARGS}, + {"datetime_check_date", datetime_check_date, METH_VARARGS}, + {"datetime_check_time", datetime_check_time, METH_VARARGS}, + {"datetime_check_datetime", datetime_check_datetime, METH_VARARGS}, + {"datetime_check_delta", datetime_check_delta, METH_VARARGS}, + {"datetime_check_tzinfo", datetime_check_tzinfo, METH_VARARGS}, + {"make_timezones_capi", make_timezones_capi, METH_NOARGS}, + {"get_timezones_offset_zero", get_timezones_offset_zero, METH_NOARGS}, + {"get_timezone_utc_capi", get_timezone_utc_capi, METH_VARARGS}, + {"get_date_fromdate", get_date_fromdate, METH_VARARGS}, + {"get_date_fromtimestamp", get_date_fromtimestamp, METH_VARARGS}, + {"get_datetime_fromtimestamp", get_datetime_fromtimestamp, METH_VARARGS}, + {"test_list_api", test_list_api, METH_NOARGS}, + {"test_dict_iteration", test_dict_iteration, METH_NOARGS}, + {"dict_getitem_knownhash", dict_getitem_knownhash, METH_VARARGS}, + {"dict_hassplittable", dict_hassplittable, METH_O}, + {"test_lazy_hash_inheritance", test_lazy_hash_inheritance, METH_NOARGS}, + {"test_long_api", test_long_api, METH_NOARGS}, + {"test_xincref_doesnt_leak", test_xincref_doesnt_leak, METH_NOARGS}, + {"test_incref_doesnt_leak", test_incref_doesnt_leak, METH_NOARGS}, + {"test_xdecref_doesnt_leak", test_xdecref_doesnt_leak, METH_NOARGS}, + {"test_decref_doesnt_leak", test_decref_doesnt_leak, METH_NOARGS}, {"test_structseq_newtype_doesnt_leak", - test_structseq_newtype_doesnt_leak, METH_NOARGS}, - {"test_incref_decref_API", test_incref_decref_API, METH_NOARGS}, - {"test_long_and_overflow", test_long_and_overflow, METH_NOARGS}, - {"test_long_as_double", test_long_as_double, METH_NOARGS}, - {"test_long_as_size_t", test_long_as_size_t, METH_NOARGS}, - {"test_long_numbits", test_long_numbits, METH_NOARGS}, - {"test_k_code", test_k_code, METH_NOARGS}, - {"test_empty_argparse", test_empty_argparse, METH_NOARGS}, + test_structseq_newtype_doesnt_leak, METH_NOARGS}, + {"test_incref_decref_API", test_incref_decref_API, METH_NOARGS}, + {"test_long_and_overflow", test_long_and_overflow, METH_NOARGS}, + {"test_long_as_double", test_long_as_double, METH_NOARGS}, + {"test_long_as_size_t", test_long_as_size_t, METH_NOARGS}, + {"test_long_numbits", test_long_numbits, METH_NOARGS}, + {"test_k_code", test_k_code, METH_NOARGS}, + {"test_empty_argparse", test_empty_argparse, METH_NOARGS}, {"parse_tuple_and_keywords", parse_tuple_and_keywords, METH_VARARGS}, - {"test_null_strings", test_null_strings, METH_NOARGS}, + {"test_null_strings", test_null_strings, METH_NOARGS}, {"test_string_from_format", (PyCFunction)test_string_from_format, METH_NOARGS}, - {"test_with_docstring", test_with_docstring, METH_NOARGS, + {"test_with_docstring", test_with_docstring, METH_NOARGS, PyDoc_STR("This is a pretty normal docstring.")}, - {"test_string_to_double", test_string_to_double, METH_NOARGS}, + {"test_string_to_double", test_string_to_double, METH_NOARGS}, {"test_unicode_compare_with_ascii", test_unicode_compare_with_ascii, METH_NOARGS}, {"test_capsule", (PyCFunction)test_capsule, METH_NOARGS}, @@ -4870,149 +4895,149 @@ static PyMethodDef TestMethods[] = { {"test_pep3118_obsolete_write_locks", (PyCFunction)test_pep3118_obsolete_write_locks, METH_NOARGS}, #endif {"getbuffer_with_null_view", getbuffer_with_null_view, METH_O}, - {"test_buildvalue_N", test_buildvalue_N, METH_NOARGS}, + {"test_buildvalue_N", test_buildvalue_N, METH_NOARGS}, {"get_args", get_args, METH_VARARGS}, - {"get_kwargs", (PyCFunction)(void(*)(void))get_kwargs, METH_VARARGS|METH_KEYWORDS}, - {"getargs_tuple", getargs_tuple, METH_VARARGS}, - {"getargs_keywords", (PyCFunction)(void(*)(void))getargs_keywords, - METH_VARARGS|METH_KEYWORDS}, - {"getargs_keyword_only", (PyCFunction)(void(*)(void))getargs_keyword_only, - METH_VARARGS|METH_KEYWORDS}, + {"get_kwargs", (PyCFunction)(void (*)(void))get_kwargs, METH_VARARGS | METH_KEYWORDS}, + {"getargs_tuple", getargs_tuple, METH_VARARGS}, + {"getargs_keywords", (PyCFunction)(void (*)(void))getargs_keywords, + METH_VARARGS | METH_KEYWORDS}, + {"getargs_keyword_only", (PyCFunction)(void (*)(void))getargs_keyword_only, + METH_VARARGS | METH_KEYWORDS}, {"getargs_positional_only_and_keywords", - (PyCFunction)(void(*)(void))getargs_positional_only_and_keywords, - METH_VARARGS|METH_KEYWORDS}, - {"getargs_b", getargs_b, METH_VARARGS}, - {"getargs_B", getargs_B, METH_VARARGS}, - {"getargs_h", getargs_h, METH_VARARGS}, - {"getargs_H", getargs_H, METH_VARARGS}, - {"getargs_I", getargs_I, METH_VARARGS}, - {"getargs_k", getargs_k, METH_VARARGS}, - {"getargs_i", getargs_i, METH_VARARGS}, - {"getargs_l", getargs_l, METH_VARARGS}, - {"getargs_n", getargs_n, METH_VARARGS}, - {"getargs_p", getargs_p, METH_VARARGS}, - {"getargs_L", getargs_L, METH_VARARGS}, - {"getargs_K", getargs_K, METH_VARARGS}, - {"test_longlong_api", test_longlong_api, METH_NOARGS}, - {"test_long_long_and_overflow",test_long_long_and_overflow, METH_NOARGS}, - {"test_L_code", test_L_code, METH_NOARGS}, - {"getargs_f", getargs_f, METH_VARARGS}, - {"getargs_d", getargs_d, METH_VARARGS}, - {"getargs_D", getargs_D, METH_VARARGS}, - {"getargs_S", getargs_S, METH_VARARGS}, - {"getargs_Y", getargs_Y, METH_VARARGS}, - {"getargs_U", getargs_U, METH_VARARGS}, - {"getargs_c", getargs_c, METH_VARARGS}, - {"getargs_C", getargs_C, METH_VARARGS}, - {"getargs_s", getargs_s, METH_VARARGS}, - {"getargs_s_star", getargs_s_star, METH_VARARGS}, - {"getargs_s_hash", getargs_s_hash, METH_VARARGS}, - {"getargs_z", getargs_z, METH_VARARGS}, - {"getargs_z_star", getargs_z_star, METH_VARARGS}, - {"getargs_z_hash", getargs_z_hash, METH_VARARGS}, - {"getargs_y", getargs_y, METH_VARARGS}, - {"getargs_y_star", getargs_y_star, METH_VARARGS}, - {"getargs_y_hash", getargs_y_hash, METH_VARARGS}, - {"getargs_u", getargs_u, METH_VARARGS}, - {"getargs_u_hash", getargs_u_hash, METH_VARARGS}, - {"getargs_Z", getargs_Z, METH_VARARGS}, - {"getargs_Z_hash", getargs_Z_hash, METH_VARARGS}, - {"getargs_w_star", getargs_w_star, METH_VARARGS}, - {"getargs_es", getargs_es, METH_VARARGS}, - {"getargs_et", getargs_et, METH_VARARGS}, - {"getargs_es_hash", getargs_es_hash, METH_VARARGS}, - {"getargs_et_hash", getargs_et_hash, METH_VARARGS}, + (PyCFunction)(void (*)(void))getargs_positional_only_and_keywords, + METH_VARARGS | METH_KEYWORDS}, + {"getargs_b", getargs_b, METH_VARARGS}, + {"getargs_B", getargs_B, METH_VARARGS}, + {"getargs_h", getargs_h, METH_VARARGS}, + {"getargs_H", getargs_H, METH_VARARGS}, + {"getargs_I", getargs_I, METH_VARARGS}, + {"getargs_k", getargs_k, METH_VARARGS}, + {"getargs_i", getargs_i, METH_VARARGS}, + {"getargs_l", getargs_l, METH_VARARGS}, + {"getargs_n", getargs_n, METH_VARARGS}, + {"getargs_p", getargs_p, METH_VARARGS}, + {"getargs_L", getargs_L, METH_VARARGS}, + {"getargs_K", getargs_K, METH_VARARGS}, + {"test_longlong_api", test_longlong_api, METH_NOARGS}, + {"test_long_long_and_overflow", test_long_long_and_overflow, METH_NOARGS}, + {"test_L_code", test_L_code, METH_NOARGS}, + {"getargs_f", getargs_f, METH_VARARGS}, + {"getargs_d", getargs_d, METH_VARARGS}, + {"getargs_D", getargs_D, METH_VARARGS}, + {"getargs_S", getargs_S, METH_VARARGS}, + {"getargs_Y", getargs_Y, METH_VARARGS}, + {"getargs_U", getargs_U, METH_VARARGS}, + {"getargs_c", getargs_c, METH_VARARGS}, + {"getargs_C", getargs_C, METH_VARARGS}, + {"getargs_s", getargs_s, METH_VARARGS}, + {"getargs_s_star", getargs_s_star, METH_VARARGS}, + {"getargs_s_hash", getargs_s_hash, METH_VARARGS}, + {"getargs_z", getargs_z, METH_VARARGS}, + {"getargs_z_star", getargs_z_star, METH_VARARGS}, + {"getargs_z_hash", getargs_z_hash, METH_VARARGS}, + {"getargs_y", getargs_y, METH_VARARGS}, + {"getargs_y_star", getargs_y_star, METH_VARARGS}, + {"getargs_y_hash", getargs_y_hash, METH_VARARGS}, + {"getargs_u", getargs_u, METH_VARARGS}, + {"getargs_u_hash", getargs_u_hash, METH_VARARGS}, + {"getargs_Z", getargs_Z, METH_VARARGS}, + {"getargs_Z_hash", getargs_Z_hash, METH_VARARGS}, + {"getargs_w_star", getargs_w_star, METH_VARARGS}, + {"getargs_es", getargs_es, METH_VARARGS}, + {"getargs_et", getargs_et, METH_VARARGS}, + {"getargs_es_hash", getargs_es_hash, METH_VARARGS}, + {"getargs_et_hash", getargs_et_hash, METH_VARARGS}, {"codec_incrementalencoder", - (PyCFunction)codec_incrementalencoder, METH_VARARGS}, + (PyCFunction)codec_incrementalencoder, METH_VARARGS}, {"codec_incrementaldecoder", - (PyCFunction)codec_incrementaldecoder, METH_VARARGS}, - {"test_s_code", test_s_code, METH_NOARGS}, - {"test_u_code", test_u_code, METH_NOARGS}, - {"test_Z_code", test_Z_code, METH_NOARGS}, - {"test_widechar", test_widechar, METH_NOARGS}, - {"unicode_aswidechar", unicode_aswidechar, METH_VARARGS}, - {"unicode_aswidecharstring",unicode_aswidecharstring, METH_VARARGS}, - {"unicode_asucs4", unicode_asucs4, METH_VARARGS}, - {"unicode_findchar", unicode_findchar, METH_VARARGS}, - {"unicode_copycharacters", unicode_copycharacters, METH_VARARGS}, - {"unicode_encodedecimal", unicode_encodedecimal, METH_VARARGS}, + (PyCFunction)codec_incrementaldecoder, METH_VARARGS}, + {"test_s_code", test_s_code, METH_NOARGS}, + {"test_u_code", test_u_code, METH_NOARGS}, + {"test_Z_code", test_Z_code, METH_NOARGS}, + {"test_widechar", test_widechar, METH_NOARGS}, + {"unicode_aswidechar", unicode_aswidechar, METH_VARARGS}, + {"unicode_aswidecharstring", unicode_aswidecharstring, METH_VARARGS}, + {"unicode_asucs4", unicode_asucs4, METH_VARARGS}, + {"unicode_findchar", unicode_findchar, METH_VARARGS}, + {"unicode_copycharacters", unicode_copycharacters, METH_VARARGS}, + {"unicode_encodedecimal", unicode_encodedecimal, METH_VARARGS}, {"unicode_transformdecimaltoascii", unicode_transformdecimaltoascii, METH_VARARGS}, - {"unicode_legacy_string", unicode_legacy_string, METH_VARARGS}, - {"_test_thread_state", test_thread_state, METH_VARARGS}, - {"_pending_threadfunc", pending_threadfunc, METH_VARARGS}, + {"unicode_legacy_string", unicode_legacy_string, METH_VARARGS}, + {"_test_thread_state", test_thread_state, METH_VARARGS}, + {"_pending_threadfunc", pending_threadfunc, METH_VARARGS}, #ifdef HAVE_GETTIMEOFDAY - {"profile_int", profile_int, METH_NOARGS}, + {"profile_int", profile_int, METH_NOARGS}, #endif - {"traceback_print", traceback_print, METH_VARARGS}, - {"exception_print", exception_print, METH_VARARGS}, - {"set_exc_info", test_set_exc_info, METH_VARARGS}, - {"argparsing", argparsing, METH_VARARGS}, - {"code_newempty", code_newempty, METH_VARARGS}, - {"make_exception_with_doc", (PyCFunction)(void(*)(void))make_exception_with_doc, + {"traceback_print", traceback_print, METH_VARARGS}, + {"exception_print", exception_print, METH_VARARGS}, + {"set_exc_info", test_set_exc_info, METH_VARARGS}, + {"argparsing", argparsing, METH_VARARGS}, + {"code_newempty", code_newempty, METH_VARARGS}, + {"make_exception_with_doc", (PyCFunction)(void (*)(void))make_exception_with_doc, METH_VARARGS | METH_KEYWORDS}, {"make_memoryview_from_NULL_pointer", make_memoryview_from_NULL_pointer, METH_NOARGS}, - {"crash_no_current_thread", crash_no_current_thread, METH_NOARGS}, - {"run_in_subinterp", run_in_subinterp, METH_VARARGS}, - {"pytime_object_to_time_t", test_pytime_object_to_time_t, METH_VARARGS}, - {"pytime_object_to_timeval", test_pytime_object_to_timeval, METH_VARARGS}, - {"pytime_object_to_timespec", test_pytime_object_to_timespec, METH_VARARGS}, - {"with_tp_del", with_tp_del, METH_VARARGS}, - {"create_cfunction", create_cfunction, METH_NOARGS}, - {"test_pymem_alloc0", test_pymem_alloc0, METH_NOARGS}, - {"test_pymem_setrawallocators",test_pymem_setrawallocators, METH_NOARGS}, - {"test_pymem_setallocators",test_pymem_setallocators, METH_NOARGS}, - {"test_pyobject_setallocators",test_pyobject_setallocators, METH_NOARGS}, + {"crash_no_current_thread", crash_no_current_thread, METH_NOARGS}, + {"run_in_subinterp", run_in_subinterp, METH_VARARGS}, + {"pytime_object_to_time_t", test_pytime_object_to_time_t, METH_VARARGS}, + {"pytime_object_to_timeval", test_pytime_object_to_timeval, METH_VARARGS}, + {"pytime_object_to_timespec", test_pytime_object_to_timespec, METH_VARARGS}, + {"with_tp_del", with_tp_del, METH_VARARGS}, + {"create_cfunction", create_cfunction, METH_NOARGS}, + {"test_pymem_alloc0", test_pymem_alloc0, METH_NOARGS}, + {"test_pymem_setrawallocators", test_pymem_setrawallocators, METH_NOARGS}, + {"test_pymem_setallocators", test_pymem_setallocators, METH_NOARGS}, + {"test_pyobject_setallocators", test_pyobject_setallocators, METH_NOARGS}, {"set_nomemory", (PyCFunction)set_nomemory, METH_VARARGS, PyDoc_STR("set_nomemory(start:int, stop:int = 0)")}, - {"remove_mem_hooks", remove_mem_hooks, METH_NOARGS, + {"remove_mem_hooks", remove_mem_hooks, METH_NOARGS, PyDoc_STR("Remove memory hooks.")}, {"no_docstring", - (PyCFunction)test_with_docstring, METH_NOARGS}, + (PyCFunction)test_with_docstring, METH_NOARGS}, {"docstring_empty", - (PyCFunction)test_with_docstring, METH_NOARGS, - docstring_empty}, + (PyCFunction)test_with_docstring, METH_NOARGS, + docstring_empty}, {"docstring_no_signature", - (PyCFunction)test_with_docstring, METH_NOARGS, - docstring_no_signature}, + (PyCFunction)test_with_docstring, METH_NOARGS, + docstring_no_signature}, {"docstring_with_invalid_signature", - (PyCFunction)test_with_docstring, METH_NOARGS, - docstring_with_invalid_signature}, + (PyCFunction)test_with_docstring, METH_NOARGS, + docstring_with_invalid_signature}, {"docstring_with_invalid_signature2", - (PyCFunction)test_with_docstring, METH_NOARGS, - docstring_with_invalid_signature2}, + (PyCFunction)test_with_docstring, METH_NOARGS, + docstring_with_invalid_signature2}, {"docstring_with_signature", - (PyCFunction)test_with_docstring, METH_NOARGS, - docstring_with_signature}, + (PyCFunction)test_with_docstring, METH_NOARGS, + docstring_with_signature}, {"docstring_with_signature_but_no_doc", - (PyCFunction)test_with_docstring, METH_NOARGS, - docstring_with_signature_but_no_doc}, + (PyCFunction)test_with_docstring, METH_NOARGS, + docstring_with_signature_but_no_doc}, {"docstring_with_signature_and_extra_newlines", - (PyCFunction)test_with_docstring, METH_NOARGS, - docstring_with_signature_and_extra_newlines}, + (PyCFunction)test_with_docstring, METH_NOARGS, + docstring_with_signature_and_extra_newlines}, {"docstring_with_signature_with_defaults", - (PyCFunction)test_with_docstring, METH_NOARGS, - docstring_with_signature_with_defaults}, + (PyCFunction)test_with_docstring, METH_NOARGS, + docstring_with_signature_with_defaults}, {"call_in_temporary_c_thread", call_in_temporary_c_thread, METH_O, PyDoc_STR("set_error_class(error_class) -> None")}, {"pymarshal_write_long_to_file", - pymarshal_write_long_to_file, METH_VARARGS}, + pymarshal_write_long_to_file, METH_VARARGS}, {"pymarshal_write_object_to_file", - pymarshal_write_object_to_file, METH_VARARGS}, + pymarshal_write_object_to_file, METH_VARARGS}, {"pymarshal_read_short_from_file", - pymarshal_read_short_from_file, METH_VARARGS}, + pymarshal_read_short_from_file, METH_VARARGS}, {"pymarshal_read_long_from_file", - pymarshal_read_long_from_file, METH_VARARGS}, + pymarshal_read_long_from_file, METH_VARARGS}, {"pymarshal_read_last_object_from_file", - pymarshal_read_last_object_from_file, METH_VARARGS}, + pymarshal_read_last_object_from_file, METH_VARARGS}, {"pymarshal_read_object_from_file", - pymarshal_read_object_from_file, METH_VARARGS}, + pymarshal_read_object_from_file, METH_VARARGS}, {"return_null_without_error", - return_null_without_error, METH_NOARGS}, + return_null_without_error, METH_NOARGS}, {"return_result_with_error", - return_result_with_error, METH_NOARGS}, - {"PyTime_FromSeconds", test_pytime_fromseconds, METH_VARARGS}, - {"PyTime_FromSecondsObject", test_pytime_fromsecondsobject, METH_VARARGS}, + return_result_with_error, METH_NOARGS}, + {"PyTime_FromSeconds", test_pytime_fromseconds, METH_VARARGS}, + {"PyTime_FromSecondsObject", test_pytime_fromsecondsobject, METH_VARARGS}, {"PyTime_AsSecondsDouble", test_pytime_assecondsdouble, METH_VARARGS}, {"PyTime_AsTimeval", test_PyTime_AsTimeval, METH_VARARGS}, #ifdef HAVE_CLOCK_GETTIME @@ -5025,7 +5050,7 @@ static PyMethodDef TestMethods[] = { {"pymem_api_misuse", pymem_api_misuse, METH_NOARGS}, {"pymem_malloc_without_gil", pymem_malloc_without_gil, METH_NOARGS}, {"pymem_getallocatorsname", test_pymem_getallocatorsname, METH_NOARGS}, - {"pyobject_is_freed", (PyCFunction)(void(*)(void))pyobject_is_freed, METH_O}, + {"pyobject_is_freed", (PyCFunction)(void (*)(void))pyobject_is_freed, METH_O}, {"pyobject_uninitialized", pyobject_uninitialized, METH_NOARGS}, {"pyobject_forbidden_bytes", pyobject_forbidden_bytes, METH_NOARGS}, {"pyobject_freed", pyobject_freed, METH_NOARGS}, @@ -5047,7 +5072,7 @@ static PyMethodDef TestMethods[] = { {"get_mapping_items", get_mapping_items, METH_O}, {"test_pythread_tss_key_state", test_pythread_tss_key_state, METH_VARARGS}, {"hamt", new_hamt, METH_NOARGS}, - {"bad_get", (PyCFunction)(void(*)(void))bad_get, METH_FASTCALL}, + {"bad_get", (PyCFunction)(void (*)(void))bad_get, METH_FASTCALL}, {"EncodeLocaleEx", encode_locale_ex, METH_VARARGS}, {"DecodeLocaleEx", decode_locale_ex, METH_VARARGS}, #ifdef Py_REF_DEBUG From f1573d64ee2f7d80dabd4d26362ee56564da968e Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" Date: Sat, 4 May 2019 21:25:20 +0000 Subject: [PATCH 02/43] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20b?= =?UTF-8?q?lurb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst diff --git a/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst b/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst new file mode 100644 index 000000000000000..67965d920033e19 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst @@ -0,0 +1 @@ +Created a test C API wrapper for PyDate_FromDate and added a test for PyDate_FromDate. \ No newline at end of file From 0284ced9b5f789be81703a0481845854c341a429 Mon Sep 17 00:00:00 2001 From: SimiCode Date: Sun, 5 May 2019 00:35:42 +0300 Subject: [PATCH 03/43] fixed auto-alignment by vscode --- Modules/_testcapimodule.c | 304 +++++++++++++++++++------------------- 1 file changed, 153 insertions(+), 151 deletions(-) diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index eb6ec12f41f483b..d94d75dd32d7cf6 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -4844,49 +4844,50 @@ negative_refcount(PyObject *self, PyObject *Py_UNUSED(args)) } #endif + static PyMethodDef TestMethods[] = { - {"raise_exception", raise_exception, METH_VARARGS}, - {"raise_memoryerror", raise_memoryerror, METH_NOARGS}, - {"set_errno", set_errno, METH_VARARGS}, - {"test_config", test_config, METH_NOARGS}, - {"test_sizeof_c_types", test_sizeof_c_types, METH_NOARGS}, - {"test_datetime_capi", test_datetime_capi, METH_NOARGS}, - {"datetime_check_date", datetime_check_date, METH_VARARGS}, - {"datetime_check_time", datetime_check_time, METH_VARARGS}, - {"datetime_check_datetime", datetime_check_datetime, METH_VARARGS}, - {"datetime_check_delta", datetime_check_delta, METH_VARARGS}, - {"datetime_check_tzinfo", datetime_check_tzinfo, METH_VARARGS}, - {"make_timezones_capi", make_timezones_capi, METH_NOARGS}, - {"get_timezones_offset_zero", get_timezones_offset_zero, METH_NOARGS}, - {"get_timezone_utc_capi", get_timezone_utc_capi, METH_VARARGS}, - {"get_date_fromdate", get_date_fromdate, METH_VARARGS}, - {"get_date_fromtimestamp", get_date_fromtimestamp, METH_VARARGS}, - {"get_datetime_fromtimestamp", get_datetime_fromtimestamp, METH_VARARGS}, - {"test_list_api", test_list_api, METH_NOARGS}, - {"test_dict_iteration", test_dict_iteration, METH_NOARGS}, - {"dict_getitem_knownhash", dict_getitem_knownhash, METH_VARARGS}, - {"dict_hassplittable", dict_hassplittable, METH_O}, - {"test_lazy_hash_inheritance", test_lazy_hash_inheritance, METH_NOARGS}, - {"test_long_api", test_long_api, METH_NOARGS}, - {"test_xincref_doesnt_leak", test_xincref_doesnt_leak, METH_NOARGS}, - {"test_incref_doesnt_leak", test_incref_doesnt_leak, METH_NOARGS}, - {"test_xdecref_doesnt_leak", test_xdecref_doesnt_leak, METH_NOARGS}, - {"test_decref_doesnt_leak", test_decref_doesnt_leak, METH_NOARGS}, + {"raise_exception", raise_exception, METH_VARARGS}, + {"raise_memoryerror", raise_memoryerror, METH_NOARGS}, + {"set_errno", set_errno, METH_VARARGS}, + {"test_config", test_config, METH_NOARGS}, + {"test_sizeof_c_types", test_sizeof_c_types, METH_NOARGS}, + {"test_datetime_capi", test_datetime_capi, METH_NOARGS}, + {"datetime_check_date", datetime_check_date, METH_VARARGS}, + {"datetime_check_time", datetime_check_time, METH_VARARGS}, + {"datetime_check_datetime", datetime_check_datetime, METH_VARARGS}, + {"datetime_check_delta", datetime_check_delta, METH_VARARGS}, + {"datetime_check_tzinfo", datetime_check_tzinfo, METH_VARARGS}, + {"make_timezones_capi", make_timezones_capi, METH_NOARGS}, + {"get_timezones_offset_zero", get_timezones_offset_zero, METH_NOARGS}, + {"get_timezone_utc_capi", get_timezone_utc_capi, METH_VARARGS}, + {"get_date_fromdate", get_date_fromdate, METH_VARARGS}, + {"get_date_fromtimestamp", get_date_fromtimestamp, METH_VARARGS}, + {"get_datetime_fromtimestamp", get_datetime_fromtimestamp, METH_VARARGS}, + {"test_list_api", test_list_api, METH_NOARGS}, + {"test_dict_iteration", test_dict_iteration, METH_NOARGS}, + {"dict_getitem_knownhash", dict_getitem_knownhash, METH_VARARGS}, + {"dict_hassplittable", dict_hassplittable, METH_O}, + {"test_lazy_hash_inheritance", test_lazy_hash_inheritance,METH_NOARGS}, + {"test_long_api", test_long_api, METH_NOARGS}, + {"test_xincref_doesnt_leak",test_xincref_doesnt_leak, METH_NOARGS}, + {"test_incref_doesnt_leak", test_incref_doesnt_leak, METH_NOARGS}, + {"test_xdecref_doesnt_leak",test_xdecref_doesnt_leak, METH_NOARGS}, + {"test_decref_doesnt_leak", test_decref_doesnt_leak, METH_NOARGS}, {"test_structseq_newtype_doesnt_leak", - test_structseq_newtype_doesnt_leak, METH_NOARGS}, - {"test_incref_decref_API", test_incref_decref_API, METH_NOARGS}, - {"test_long_and_overflow", test_long_and_overflow, METH_NOARGS}, - {"test_long_as_double", test_long_as_double, METH_NOARGS}, - {"test_long_as_size_t", test_long_as_size_t, METH_NOARGS}, - {"test_long_numbits", test_long_numbits, METH_NOARGS}, - {"test_k_code", test_k_code, METH_NOARGS}, - {"test_empty_argparse", test_empty_argparse, METH_NOARGS}, + test_structseq_newtype_doesnt_leak, METH_NOARGS}, + {"test_incref_decref_API", test_incref_decref_API, METH_NOARGS}, + {"test_long_and_overflow", test_long_and_overflow, METH_NOARGS}, + {"test_long_as_double", test_long_as_double, METH_NOARGS}, + {"test_long_as_size_t", test_long_as_size_t, METH_NOARGS}, + {"test_long_numbits", test_long_numbits, METH_NOARGS}, + {"test_k_code", test_k_code, METH_NOARGS}, + {"test_empty_argparse", test_empty_argparse, METH_NOARGS}, {"parse_tuple_and_keywords", parse_tuple_and_keywords, METH_VARARGS}, - {"test_null_strings", test_null_strings, METH_NOARGS}, + {"test_null_strings", test_null_strings, METH_NOARGS}, {"test_string_from_format", (PyCFunction)test_string_from_format, METH_NOARGS}, - {"test_with_docstring", test_with_docstring, METH_NOARGS, + {"test_with_docstring", test_with_docstring, METH_NOARGS, PyDoc_STR("This is a pretty normal docstring.")}, - {"test_string_to_double", test_string_to_double, METH_NOARGS}, + {"test_string_to_double", test_string_to_double, METH_NOARGS}, {"test_unicode_compare_with_ascii", test_unicode_compare_with_ascii, METH_NOARGS}, {"test_capsule", (PyCFunction)test_capsule, METH_NOARGS}, @@ -4895,149 +4896,149 @@ static PyMethodDef TestMethods[] = { {"test_pep3118_obsolete_write_locks", (PyCFunction)test_pep3118_obsolete_write_locks, METH_NOARGS}, #endif {"getbuffer_with_null_view", getbuffer_with_null_view, METH_O}, - {"test_buildvalue_N", test_buildvalue_N, METH_NOARGS}, + {"test_buildvalue_N", test_buildvalue_N, METH_NOARGS}, {"get_args", get_args, METH_VARARGS}, - {"get_kwargs", (PyCFunction)(void (*)(void))get_kwargs, METH_VARARGS | METH_KEYWORDS}, - {"getargs_tuple", getargs_tuple, METH_VARARGS}, - {"getargs_keywords", (PyCFunction)(void (*)(void))getargs_keywords, - METH_VARARGS | METH_KEYWORDS}, - {"getargs_keyword_only", (PyCFunction)(void (*)(void))getargs_keyword_only, - METH_VARARGS | METH_KEYWORDS}, + {"get_kwargs", (PyCFunction)(void(*)(void))get_kwargs, METH_VARARGS|METH_KEYWORDS}, + {"getargs_tuple", getargs_tuple, METH_VARARGS}, + {"getargs_keywords", (PyCFunction)(void(*)(void))getargs_keywords, + METH_VARARGS|METH_KEYWORDS}, + {"getargs_keyword_only", (PyCFunction)(void(*)(void))getargs_keyword_only, + METH_VARARGS|METH_KEYWORDS}, {"getargs_positional_only_and_keywords", - (PyCFunction)(void (*)(void))getargs_positional_only_and_keywords, - METH_VARARGS | METH_KEYWORDS}, - {"getargs_b", getargs_b, METH_VARARGS}, - {"getargs_B", getargs_B, METH_VARARGS}, - {"getargs_h", getargs_h, METH_VARARGS}, - {"getargs_H", getargs_H, METH_VARARGS}, - {"getargs_I", getargs_I, METH_VARARGS}, - {"getargs_k", getargs_k, METH_VARARGS}, - {"getargs_i", getargs_i, METH_VARARGS}, - {"getargs_l", getargs_l, METH_VARARGS}, - {"getargs_n", getargs_n, METH_VARARGS}, - {"getargs_p", getargs_p, METH_VARARGS}, - {"getargs_L", getargs_L, METH_VARARGS}, - {"getargs_K", getargs_K, METH_VARARGS}, - {"test_longlong_api", test_longlong_api, METH_NOARGS}, - {"test_long_long_and_overflow", test_long_long_and_overflow, METH_NOARGS}, - {"test_L_code", test_L_code, METH_NOARGS}, - {"getargs_f", getargs_f, METH_VARARGS}, - {"getargs_d", getargs_d, METH_VARARGS}, - {"getargs_D", getargs_D, METH_VARARGS}, - {"getargs_S", getargs_S, METH_VARARGS}, - {"getargs_Y", getargs_Y, METH_VARARGS}, - {"getargs_U", getargs_U, METH_VARARGS}, - {"getargs_c", getargs_c, METH_VARARGS}, - {"getargs_C", getargs_C, METH_VARARGS}, - {"getargs_s", getargs_s, METH_VARARGS}, - {"getargs_s_star", getargs_s_star, METH_VARARGS}, - {"getargs_s_hash", getargs_s_hash, METH_VARARGS}, - {"getargs_z", getargs_z, METH_VARARGS}, - {"getargs_z_star", getargs_z_star, METH_VARARGS}, - {"getargs_z_hash", getargs_z_hash, METH_VARARGS}, - {"getargs_y", getargs_y, METH_VARARGS}, - {"getargs_y_star", getargs_y_star, METH_VARARGS}, - {"getargs_y_hash", getargs_y_hash, METH_VARARGS}, - {"getargs_u", getargs_u, METH_VARARGS}, - {"getargs_u_hash", getargs_u_hash, METH_VARARGS}, - {"getargs_Z", getargs_Z, METH_VARARGS}, - {"getargs_Z_hash", getargs_Z_hash, METH_VARARGS}, - {"getargs_w_star", getargs_w_star, METH_VARARGS}, - {"getargs_es", getargs_es, METH_VARARGS}, - {"getargs_et", getargs_et, METH_VARARGS}, - {"getargs_es_hash", getargs_es_hash, METH_VARARGS}, - {"getargs_et_hash", getargs_et_hash, METH_VARARGS}, + (PyCFunction)(void(*)(void))getargs_positional_only_and_keywords, + METH_VARARGS|METH_KEYWORDS}, + {"getargs_b", getargs_b, METH_VARARGS}, + {"getargs_B", getargs_B, METH_VARARGS}, + {"getargs_h", getargs_h, METH_VARARGS}, + {"getargs_H", getargs_H, METH_VARARGS}, + {"getargs_I", getargs_I, METH_VARARGS}, + {"getargs_k", getargs_k, METH_VARARGS}, + {"getargs_i", getargs_i, METH_VARARGS}, + {"getargs_l", getargs_l, METH_VARARGS}, + {"getargs_n", getargs_n, METH_VARARGS}, + {"getargs_p", getargs_p, METH_VARARGS}, + {"getargs_L", getargs_L, METH_VARARGS}, + {"getargs_K", getargs_K, METH_VARARGS}, + {"test_longlong_api", test_longlong_api, METH_NOARGS}, + {"test_long_long_and_overflow",test_long_long_and_overflow, METH_NOARGS}, + {"test_L_code", test_L_code, METH_NOARGS}, + {"getargs_f", getargs_f, METH_VARARGS}, + {"getargs_d", getargs_d, METH_VARARGS}, + {"getargs_D", getargs_D, METH_VARARGS}, + {"getargs_S", getargs_S, METH_VARARGS}, + {"getargs_Y", getargs_Y, METH_VARARGS}, + {"getargs_U", getargs_U, METH_VARARGS}, + {"getargs_c", getargs_c, METH_VARARGS}, + {"getargs_C", getargs_C, METH_VARARGS}, + {"getargs_s", getargs_s, METH_VARARGS}, + {"getargs_s_star", getargs_s_star, METH_VARARGS}, + {"getargs_s_hash", getargs_s_hash, METH_VARARGS}, + {"getargs_z", getargs_z, METH_VARARGS}, + {"getargs_z_star", getargs_z_star, METH_VARARGS}, + {"getargs_z_hash", getargs_z_hash, METH_VARARGS}, + {"getargs_y", getargs_y, METH_VARARGS}, + {"getargs_y_star", getargs_y_star, METH_VARARGS}, + {"getargs_y_hash", getargs_y_hash, METH_VARARGS}, + {"getargs_u", getargs_u, METH_VARARGS}, + {"getargs_u_hash", getargs_u_hash, METH_VARARGS}, + {"getargs_Z", getargs_Z, METH_VARARGS}, + {"getargs_Z_hash", getargs_Z_hash, METH_VARARGS}, + {"getargs_w_star", getargs_w_star, METH_VARARGS}, + {"getargs_es", getargs_es, METH_VARARGS}, + {"getargs_et", getargs_et, METH_VARARGS}, + {"getargs_es_hash", getargs_es_hash, METH_VARARGS}, + {"getargs_et_hash", getargs_et_hash, METH_VARARGS}, {"codec_incrementalencoder", - (PyCFunction)codec_incrementalencoder, METH_VARARGS}, + (PyCFunction)codec_incrementalencoder, METH_VARARGS}, {"codec_incrementaldecoder", - (PyCFunction)codec_incrementaldecoder, METH_VARARGS}, - {"test_s_code", test_s_code, METH_NOARGS}, - {"test_u_code", test_u_code, METH_NOARGS}, - {"test_Z_code", test_Z_code, METH_NOARGS}, - {"test_widechar", test_widechar, METH_NOARGS}, - {"unicode_aswidechar", unicode_aswidechar, METH_VARARGS}, - {"unicode_aswidecharstring", unicode_aswidecharstring, METH_VARARGS}, - {"unicode_asucs4", unicode_asucs4, METH_VARARGS}, - {"unicode_findchar", unicode_findchar, METH_VARARGS}, - {"unicode_copycharacters", unicode_copycharacters, METH_VARARGS}, - {"unicode_encodedecimal", unicode_encodedecimal, METH_VARARGS}, + (PyCFunction)codec_incrementaldecoder, METH_VARARGS}, + {"test_s_code", test_s_code, METH_NOARGS}, + {"test_u_code", test_u_code, METH_NOARGS}, + {"test_Z_code", test_Z_code, METH_NOARGS}, + {"test_widechar", test_widechar, METH_NOARGS}, + {"unicode_aswidechar", unicode_aswidechar, METH_VARARGS}, + {"unicode_aswidecharstring",unicode_aswidecharstring, METH_VARARGS}, + {"unicode_asucs4", unicode_asucs4, METH_VARARGS}, + {"unicode_findchar", unicode_findchar, METH_VARARGS}, + {"unicode_copycharacters", unicode_copycharacters, METH_VARARGS}, + {"unicode_encodedecimal", unicode_encodedecimal, METH_VARARGS}, {"unicode_transformdecimaltoascii", unicode_transformdecimaltoascii, METH_VARARGS}, - {"unicode_legacy_string", unicode_legacy_string, METH_VARARGS}, - {"_test_thread_state", test_thread_state, METH_VARARGS}, - {"_pending_threadfunc", pending_threadfunc, METH_VARARGS}, + {"unicode_legacy_string", unicode_legacy_string, METH_VARARGS}, + {"_test_thread_state", test_thread_state, METH_VARARGS}, + {"_pending_threadfunc", pending_threadfunc, METH_VARARGS}, #ifdef HAVE_GETTIMEOFDAY - {"profile_int", profile_int, METH_NOARGS}, + {"profile_int", profile_int, METH_NOARGS}, #endif - {"traceback_print", traceback_print, METH_VARARGS}, - {"exception_print", exception_print, METH_VARARGS}, - {"set_exc_info", test_set_exc_info, METH_VARARGS}, - {"argparsing", argparsing, METH_VARARGS}, - {"code_newempty", code_newempty, METH_VARARGS}, - {"make_exception_with_doc", (PyCFunction)(void (*)(void))make_exception_with_doc, + {"traceback_print", traceback_print, METH_VARARGS}, + {"exception_print", exception_print, METH_VARARGS}, + {"set_exc_info", test_set_exc_info, METH_VARARGS}, + {"argparsing", argparsing, METH_VARARGS}, + {"code_newempty", code_newempty, METH_VARARGS}, + {"make_exception_with_doc", (PyCFunction)(void(*)(void))make_exception_with_doc, METH_VARARGS | METH_KEYWORDS}, {"make_memoryview_from_NULL_pointer", make_memoryview_from_NULL_pointer, METH_NOARGS}, - {"crash_no_current_thread", crash_no_current_thread, METH_NOARGS}, - {"run_in_subinterp", run_in_subinterp, METH_VARARGS}, - {"pytime_object_to_time_t", test_pytime_object_to_time_t, METH_VARARGS}, - {"pytime_object_to_timeval", test_pytime_object_to_timeval, METH_VARARGS}, - {"pytime_object_to_timespec", test_pytime_object_to_timespec, METH_VARARGS}, - {"with_tp_del", with_tp_del, METH_VARARGS}, - {"create_cfunction", create_cfunction, METH_NOARGS}, - {"test_pymem_alloc0", test_pymem_alloc0, METH_NOARGS}, - {"test_pymem_setrawallocators", test_pymem_setrawallocators, METH_NOARGS}, - {"test_pymem_setallocators", test_pymem_setallocators, METH_NOARGS}, - {"test_pyobject_setallocators", test_pyobject_setallocators, METH_NOARGS}, + {"crash_no_current_thread", crash_no_current_thread, METH_NOARGS}, + {"run_in_subinterp", run_in_subinterp, METH_VARARGS}, + {"pytime_object_to_time_t", test_pytime_object_to_time_t, METH_VARARGS}, + {"pytime_object_to_timeval", test_pytime_object_to_timeval, METH_VARARGS}, + {"pytime_object_to_timespec", test_pytime_object_to_timespec, METH_VARARGS}, + {"with_tp_del", with_tp_del, METH_VARARGS}, + {"create_cfunction", create_cfunction, METH_NOARGS}, + {"test_pymem_alloc0", test_pymem_alloc0, METH_NOARGS}, + {"test_pymem_setrawallocators",test_pymem_setrawallocators, METH_NOARGS}, + {"test_pymem_setallocators",test_pymem_setallocators, METH_NOARGS}, + {"test_pyobject_setallocators",test_pyobject_setallocators, METH_NOARGS}, {"set_nomemory", (PyCFunction)set_nomemory, METH_VARARGS, PyDoc_STR("set_nomemory(start:int, stop:int = 0)")}, - {"remove_mem_hooks", remove_mem_hooks, METH_NOARGS, + {"remove_mem_hooks", remove_mem_hooks, METH_NOARGS, PyDoc_STR("Remove memory hooks.")}, {"no_docstring", - (PyCFunction)test_with_docstring, METH_NOARGS}, + (PyCFunction)test_with_docstring, METH_NOARGS}, {"docstring_empty", - (PyCFunction)test_with_docstring, METH_NOARGS, - docstring_empty}, + (PyCFunction)test_with_docstring, METH_NOARGS, + docstring_empty}, {"docstring_no_signature", - (PyCFunction)test_with_docstring, METH_NOARGS, - docstring_no_signature}, + (PyCFunction)test_with_docstring, METH_NOARGS, + docstring_no_signature}, {"docstring_with_invalid_signature", - (PyCFunction)test_with_docstring, METH_NOARGS, - docstring_with_invalid_signature}, + (PyCFunction)test_with_docstring, METH_NOARGS, + docstring_with_invalid_signature}, {"docstring_with_invalid_signature2", - (PyCFunction)test_with_docstring, METH_NOARGS, - docstring_with_invalid_signature2}, + (PyCFunction)test_with_docstring, METH_NOARGS, + docstring_with_invalid_signature2}, {"docstring_with_signature", - (PyCFunction)test_with_docstring, METH_NOARGS, - docstring_with_signature}, + (PyCFunction)test_with_docstring, METH_NOARGS, + docstring_with_signature}, {"docstring_with_signature_but_no_doc", - (PyCFunction)test_with_docstring, METH_NOARGS, - docstring_with_signature_but_no_doc}, + (PyCFunction)test_with_docstring, METH_NOARGS, + docstring_with_signature_but_no_doc}, {"docstring_with_signature_and_extra_newlines", - (PyCFunction)test_with_docstring, METH_NOARGS, - docstring_with_signature_and_extra_newlines}, + (PyCFunction)test_with_docstring, METH_NOARGS, + docstring_with_signature_and_extra_newlines}, {"docstring_with_signature_with_defaults", - (PyCFunction)test_with_docstring, METH_NOARGS, - docstring_with_signature_with_defaults}, + (PyCFunction)test_with_docstring, METH_NOARGS, + docstring_with_signature_with_defaults}, {"call_in_temporary_c_thread", call_in_temporary_c_thread, METH_O, PyDoc_STR("set_error_class(error_class) -> None")}, {"pymarshal_write_long_to_file", - pymarshal_write_long_to_file, METH_VARARGS}, + pymarshal_write_long_to_file, METH_VARARGS}, {"pymarshal_write_object_to_file", - pymarshal_write_object_to_file, METH_VARARGS}, + pymarshal_write_object_to_file, METH_VARARGS}, {"pymarshal_read_short_from_file", - pymarshal_read_short_from_file, METH_VARARGS}, + pymarshal_read_short_from_file, METH_VARARGS}, {"pymarshal_read_long_from_file", - pymarshal_read_long_from_file, METH_VARARGS}, + pymarshal_read_long_from_file, METH_VARARGS}, {"pymarshal_read_last_object_from_file", - pymarshal_read_last_object_from_file, METH_VARARGS}, + pymarshal_read_last_object_from_file, METH_VARARGS}, {"pymarshal_read_object_from_file", - pymarshal_read_object_from_file, METH_VARARGS}, + pymarshal_read_object_from_file, METH_VARARGS}, {"return_null_without_error", - return_null_without_error, METH_NOARGS}, + return_null_without_error, METH_NOARGS}, {"return_result_with_error", - return_result_with_error, METH_NOARGS}, - {"PyTime_FromSeconds", test_pytime_fromseconds, METH_VARARGS}, - {"PyTime_FromSecondsObject", test_pytime_fromsecondsobject, METH_VARARGS}, + return_result_with_error, METH_NOARGS}, + {"PyTime_FromSeconds", test_pytime_fromseconds, METH_VARARGS}, + {"PyTime_FromSecondsObject", test_pytime_fromsecondsobject, METH_VARARGS}, {"PyTime_AsSecondsDouble", test_pytime_assecondsdouble, METH_VARARGS}, {"PyTime_AsTimeval", test_PyTime_AsTimeval, METH_VARARGS}, #ifdef HAVE_CLOCK_GETTIME @@ -5050,7 +5051,7 @@ static PyMethodDef TestMethods[] = { {"pymem_api_misuse", pymem_api_misuse, METH_NOARGS}, {"pymem_malloc_without_gil", pymem_malloc_without_gil, METH_NOARGS}, {"pymem_getallocatorsname", test_pymem_getallocatorsname, METH_NOARGS}, - {"pyobject_is_freed", (PyCFunction)(void (*)(void))pyobject_is_freed, METH_O}, + {"pyobject_is_freed", (PyCFunction)(void(*)(void))pyobject_is_freed, METH_O}, {"pyobject_uninitialized", pyobject_uninitialized, METH_NOARGS}, {"pyobject_forbidden_bytes", pyobject_forbidden_bytes, METH_NOARGS}, {"pyobject_freed", pyobject_freed, METH_NOARGS}, @@ -5072,7 +5073,7 @@ static PyMethodDef TestMethods[] = { {"get_mapping_items", get_mapping_items, METH_O}, {"test_pythread_tss_key_state", test_pythread_tss_key_state, METH_VARARGS}, {"hamt", new_hamt, METH_NOARGS}, - {"bad_get", (PyCFunction)(void (*)(void))bad_get, METH_FASTCALL}, + {"bad_get", (PyCFunction)(void(*)(void))bad_get, METH_FASTCALL}, {"EncodeLocaleEx", encode_locale_ex, METH_VARARGS}, {"DecodeLocaleEx", decode_locale_ex, METH_VARARGS}, #ifdef Py_REF_DEBUG @@ -5081,6 +5082,7 @@ static PyMethodDef TestMethods[] = { {NULL, NULL} /* sentinel */ }; + #define AddSym(d, n, f, v) {PyObject *o = f(v); PyDict_SetItemString(d, n, o); Py_DECREF(o);} typedef struct { From d9ecbf55f9b27e684f981a189d392da961c3a903 Mon Sep 17 00:00:00 2001 From: SimiCode Date: Sun, 5 May 2019 00:40:26 +0300 Subject: [PATCH 04/43] made changes as per PEP7 --- Modules/_testcapimodule.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index d94d75dd32d7cf6..02e1520137042ef 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2347,18 +2347,15 @@ get_date_fromdate(PyObject *self, PyObject *args) int year = 0, month = 0, day = 0; int macro = 0; - if (!PyArg_ParseTuple(args, "iii|p", &year, &month, &day, ¯o)) - { + if (!PyArg_ParseTuple(args, "iii|p", &year, &month, &day, ¯o)) { return NULL; } // Pass along to the API function - if (macro) - { + if (macro) { rv = PyDate_FromDate(year, month, day); } - else - { + else { rv = PyDateTimeAPI->Date_FromDate(year, month, day, PyDateTimeAPI->DateType); } @@ -5082,7 +5079,6 @@ static PyMethodDef TestMethods[] = { {NULL, NULL} /* sentinel */ }; - #define AddSym(d, n, f, v) {PyObject *o = f(v); PyDict_SetItemString(d, n, o); Py_DECREF(o);} typedef struct { From 796711452a6041276babf3a12de6b722cc67103f Mon Sep 17 00:00:00 2001 From: Edison A <20975616+SimiCode@users.noreply.github.com> Date: Sun, 5 May 2019 00:42:16 +0300 Subject: [PATCH 05/43] Update 2019-05-04-21-25-19.bpo-36782.h3oPIb.rst --- .../NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst b/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst index 67965d920033e19..0b66c5841d85283 100644 --- a/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst +++ b/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst @@ -1 +1,2 @@ -Created a test C API wrapper for PyDate_FromDate and added a test for PyDate_FromDate. \ No newline at end of file +Created a test C API wrapper for PyDate_FromDate and added a test for PyDate_FromDate. +Patch by Edison Abahurire. From f6b3ab8474855ea9f9e7d79676977fa133807f14 Mon Sep 17 00:00:00 2001 From: SimiCode Date: Mon, 6 May 2019 18:10:14 +0300 Subject: [PATCH 06/43] Refactored code as per requested changes --- Lib/test/datetimetester.py | 14 ++++++++------ Misc/ACKS | 1 + 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index 29e8d34b324703d..130800b2ae26e7d 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -6019,15 +6019,17 @@ class TZInfoSubclass(tzinfo): self.assertFalse(is_tzinfo(arg, exact)) def test_date_from_date(self): - year = 1993 - month = 8 - day = 26 + exp_date = date(1993, 8, 26) for macro in [0, 1]: with self.subTest(macro=macro): - d = _testcapi.get_date_fromdate(year, month, day, macro) - - self.assertEqual(d, date(1993, 8, 26)) + c_api_date = _testcapi.get_date_fromdate( + exp_date.year, + exp_date.month, + exp_date.day, + macro) + + self.assertEqual(c_api_date, exp_date) def test_date_from_timestamp(self): ts = datetime(1995, 4, 12).timestamp() diff --git a/Misc/ACKS b/Misc/ACKS index 300e788940787e6..25158aea124bc3a 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1853,3 +1853,4 @@ Peter Åstrand Zheao Li Carsten Klein Diego Rojas +Edison Abahurire \ No newline at end of file From 3b2095df16225194bb23c40a0d748285bd34e390 Mon Sep 17 00:00:00 2001 From: SimiCode Date: Mon, 6 May 2019 19:37:06 +0300 Subject: [PATCH 07/43] Remove Whitespace to Fix failed travis build --- Lib/test/datetimetester.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index 130800b2ae26e7d..974fc587aa920d7 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -6024,11 +6024,11 @@ def test_date_from_date(self): for macro in [0, 1]: with self.subTest(macro=macro): c_api_date = _testcapi.get_date_fromdate( - exp_date.year, + exp_date.year, exp_date.month, exp_date.day, macro) - + self.assertEqual(c_api_date, exp_date) def test_date_from_timestamp(self): From f6d590fc5d0206b5955fa57402a3d388d9b92534 Mon Sep 17 00:00:00 2001 From: Edison A <20975616+SimiCode@users.noreply.github.com> Date: Mon, 6 May 2019 22:33:42 +0300 Subject: [PATCH 08/43] Update 2019-05-04-21-25-19.bpo-36782.h3oPIb.rst --- .../NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst b/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst index 0b66c5841d85283..7b41b73c7823f91 100644 --- a/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst +++ b/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst @@ -1,2 +1 @@ -Created a test C API wrapper for PyDate_FromDate and added a test for PyDate_FromDate. -Patch by Edison Abahurire. +Created a test for the C API function :c:func:`PyDate_FromDate`. Patch by Edison Abahurire. From 7598e26e268c213a6c55cb20bf11a73cd1f9d5a7 Mon Sep 17 00:00:00 2001 From: Edison A <20975616+SimiCode@users.noreply.github.com> Date: Mon, 6 May 2019 22:40:52 +0300 Subject: [PATCH 09/43] Add a new line at end of ACKS --- Misc/ACKS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/ACKS b/Misc/ACKS index 25158aea124bc3a..7b7482be38639c8 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1853,4 +1853,4 @@ Peter Åstrand Zheao Li Carsten Klein Diego Rojas -Edison Abahurire \ No newline at end of file +Edison Abahurire From f9e6213cb2a9ca5014f281a6d2b371c93c219d0c Mon Sep 17 00:00:00 2001 From: SimiCode Date: Mon, 6 May 2019 22:56:51 +0300 Subject: [PATCH 10/43] Added C API function for PyDateTime_FromDateAndTime --- Modules/_testcapimodule.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 02e1520137042ef..2df925bb70465d0 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2362,6 +2362,28 @@ get_date_fromdate(PyObject *self, PyObject *args) return rv; } +static PyObject * +get_datetime_fromdateandtime(PyObject *self, PyObject *args) +{ + PyObject *rv = NULL; + int year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0, microsecond = 0; + int macro = 0; + + if (!PyArg_ParseTuple(args, "iiiiiii|p", &year, &month, &day, &hour, &minute, &second, µsecond, ¯o)) { + return NULL; + } + + // Pass along to the API function + if (macro) { + rv = PyDateTime_FromDateAndTime(year, month, day, hour, minute, second, microsecond); + } + else { + rv = PyDateTimeAPI->DateTime_FromDateAndTime(year, month, day, hour, minute, second, microsecond, Py_None, PyDateTimeAPI->DateTimeType); + } + + return rv; +} + static PyObject * get_date_fromtimestamp(PyObject* self, PyObject *args) { @@ -4858,6 +4880,7 @@ static PyMethodDef TestMethods[] = { {"get_timezones_offset_zero", get_timezones_offset_zero, METH_NOARGS}, {"get_timezone_utc_capi", get_timezone_utc_capi, METH_VARARGS}, {"get_date_fromdate", get_date_fromdate, METH_VARARGS}, + {"get_datetime_fromdateandtime", get_datetime_fromdateandtime, METH_VARARGS}, {"get_date_fromtimestamp", get_date_fromtimestamp, METH_VARARGS}, {"get_datetime_fromtimestamp", get_datetime_fromtimestamp, METH_VARARGS}, {"test_list_api", test_list_api, METH_NOARGS}, From 948b2ce3a74854ecabc1ef844ad5002c80ca3543 Mon Sep 17 00:00:00 2001 From: SimiCode Date: Mon, 6 May 2019 23:00:05 +0300 Subject: [PATCH 11/43] Added a test for the C API wrapper of PyDateTime_FromDateAndTime --- Lib/test/datetimetester.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index 974fc587aa920d7..6850bad39d460d5 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -6031,6 +6031,23 @@ def test_date_from_date(self): self.assertEqual(c_api_date, exp_date) + def test_datetime_from_dateandtime(self): + exp_date = datetime(1993, 8, 26, 22, 12, 55, 99999) + + for macro in [0, 1]: + with self.subTest(macro=macro): + c_api_date = _testcapi.get_datetime_fromdateandtime( + exp_date.year, + exp_date.month, + exp_date.day, + exp_date.hour, + exp_date.minute, + exp_date.second, + exp_date.microsecond, + macro) + + self.assertEqual(c_api_date, exp_date) + def test_date_from_timestamp(self): ts = datetime(1995, 4, 12).timestamp() From 64b4ae2bbb03d118b8b4323b47e555174a39193f Mon Sep 17 00:00:00 2001 From: SimiCode Date: Mon, 6 May 2019 23:15:45 +0300 Subject: [PATCH 12/43] Added C API function for PyDateTime_FromDateAndTime --- Modules/_testcapimodule.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 2df925bb70465d0..920fe29cb8c3887 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2384,6 +2384,28 @@ get_datetime_fromdateandtime(PyObject *self, PyObject *args) return rv; } +static PyObject * +get_datetime_fromdateandtimeandfold(PyObject *self, PyObject *args) +{ + PyObject *rv = NULL; + int year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0, microsecond = 0, fold = 0; + int macro = 0; + + if (!PyArg_ParseTuple(args, "iiiiiiii|p", &year, &month, &day, &hour, &minute, &second, µsecond, &fold, ¯o)) { + return NULL; + } + + // Pass along to the API function + if (macro) { + rv = PyDateTime_FromDateAndTimeAndFold(year, month, day, hour, minute, second, microsecond, fold); + } + else { + rv = PyDateTimeAPI->DateTime_FromDateAndTimeAndFold(year, month, day, hour, minute, second, microsecond, Py_None, fold, PyDateTimeAPI->DateTimeType); + } + + return rv; +} + static PyObject * get_date_fromtimestamp(PyObject* self, PyObject *args) { @@ -4881,6 +4903,7 @@ static PyMethodDef TestMethods[] = { {"get_timezone_utc_capi", get_timezone_utc_capi, METH_VARARGS}, {"get_date_fromdate", get_date_fromdate, METH_VARARGS}, {"get_datetime_fromdateandtime", get_datetime_fromdateandtime, METH_VARARGS}, + {"get_datetime_fromdateandtimeandfold", get_datetime_fromdateandtimeandfold, METH_VARARGS}, {"get_date_fromtimestamp", get_date_fromtimestamp, METH_VARARGS}, {"get_datetime_fromtimestamp", get_datetime_fromtimestamp, METH_VARARGS}, {"test_list_api", test_list_api, METH_NOARGS}, From 2e8188c76515f58908baa91336e6afa69dd756e8 Mon Sep 17 00:00:00 2001 From: SimiCode Date: Mon, 6 May 2019 23:16:44 +0300 Subject: [PATCH 13/43] Added a test for the C API wrapper of PyDateTime_FromDateAndTimeAndFold --- Lib/test/datetimetester.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index 6850bad39d460d5..4e1ed875e8ebbb2 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -6048,6 +6048,16 @@ def test_datetime_from_dateandtime(self): self.assertEqual(c_api_date, exp_date) + def test_datetime_from_dateandtimeandfold(self): + for fold in [0, 1]: + exp_date = datetime(1993, 8, 26, 22, 12, 55, 99999, fold=fold) + + for macro in [0, 1]: + with self.subTest(macro=macro): + c_api_date = _testcapi.get_datetime_fromdateandtimeandfold(exp_date.year, exp_date.month, exp_date.day, exp_date.hour, exp_date.minute, exp_date.second, exp_date.microsecond, exp_date.fold, macro) + + self.assertEqual(c_api_date, exp_date) + def test_date_from_timestamp(self): ts = datetime(1995, 4, 12).timestamp() From 642e802e86c45136e1ac5a4e46e9c99bd88f2e37 Mon Sep 17 00:00:00 2001 From: SimiCode Date: Mon, 6 May 2019 23:19:06 +0300 Subject: [PATCH 14/43] Remove Whitespace using patchcheck --- Lib/test/datetimetester.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index 4e1ed875e8ebbb2..38b9b0f892df0e0 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -6037,13 +6037,13 @@ def test_datetime_from_dateandtime(self): for macro in [0, 1]: with self.subTest(macro=macro): c_api_date = _testcapi.get_datetime_fromdateandtime( - exp_date.year, - exp_date.month, - exp_date.day, - exp_date.hour, - exp_date.minute, - exp_date.second, - exp_date.microsecond, + exp_date.year, + exp_date.month, + exp_date.day, + exp_date.hour, + exp_date.minute, + exp_date.second, + exp_date.microsecond, macro) self.assertEqual(c_api_date, exp_date) From a9ada008dcc3f2d624425213fa426832cff11610 Mon Sep 17 00:00:00 2001 From: SimiCode Date: Mon, 6 May 2019 23:30:11 +0300 Subject: [PATCH 15/43] Added a C API function for PyTime_FromTime --- Modules/_testcapimodule.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 920fe29cb8c3887..c2e36171ce9897b 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2406,6 +2406,28 @@ get_datetime_fromdateandtimeandfold(PyObject *self, PyObject *args) return rv; } +static PyObject * +get_time_fromtime(PyObject *self, PyObject *args) +{ + PyObject *rv = NULL; + int hour = 0, minute = 0, second = 0, microsecond = 0; + int macro = 0; + + if (!PyArg_ParseTuple(args, "iiii|p", &hour, &minute, &second, µsecond, ¯o)) { + return NULL; + } + + // Pass along to the API function + if (macro) { + rv = PyTime_FromTime(hour, minute, second, microsecond); + } + else { + rv = PyDateTimeAPI->Time_FromTime(hour, minute, second, microsecond, Py_None, PyDateTimeAPI->TimeType); + } + + return rv; +} + static PyObject * get_date_fromtimestamp(PyObject* self, PyObject *args) { @@ -4904,6 +4926,7 @@ static PyMethodDef TestMethods[] = { {"get_date_fromdate", get_date_fromdate, METH_VARARGS}, {"get_datetime_fromdateandtime", get_datetime_fromdateandtime, METH_VARARGS}, {"get_datetime_fromdateandtimeandfold", get_datetime_fromdateandtimeandfold, METH_VARARGS}, + {"get_time_fromtime", get_time_fromtime, METH_VARARGS}, {"get_date_fromtimestamp", get_date_fromtimestamp, METH_VARARGS}, {"get_datetime_fromtimestamp", get_datetime_fromtimestamp, METH_VARARGS}, {"test_list_api", test_list_api, METH_NOARGS}, From f3b692e4bfc3bbf798536538efc08f020778fd4a Mon Sep 17 00:00:00 2001 From: SimiCode Date: Mon, 6 May 2019 23:31:28 +0300 Subject: [PATCH 16/43] Added a test for the C API wrapper of PyTime_FromTime --- Lib/test/datetimetester.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index 38b9b0f892df0e0..cbcdd2ca820d8f9 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -6058,6 +6058,15 @@ def test_datetime_from_dateandtimeandfold(self): self.assertEqual(c_api_date, exp_date) + def test_time_from_time(self): + exp_time = time(22, 12, 55, 99999) + + for macro in [0, 1]: + with self.subTest(macro=macro): + c_api_time = _testcapi.get_time_fromtime(exp_time.hour, exp_time.minute, exp_time.second, exp_time.microsecond, macro) + + self.assertEqual(c_api_time, exp_time) + def test_date_from_timestamp(self): ts = datetime(1995, 4, 12).timestamp() From ddba9786da58491fe6791e97b3b4e553e9432f4c Mon Sep 17 00:00:00 2001 From: SimiCode Date: Mon, 6 May 2019 23:40:20 +0300 Subject: [PATCH 17/43] Added a C API function for PyTime_FromTimeAndFold --- Modules/_testcapimodule.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index c2e36171ce9897b..660bd0732babb44 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2428,6 +2428,28 @@ get_time_fromtime(PyObject *self, PyObject *args) return rv; } +static PyObject * +get_time_fromtimeandfold(PyObject *self, PyObject *args) +{ + PyObject *rv = NULL; + int hour = 0, minute = 0, second = 0, microsecond = 0, fold = 0; + int macro = 0; + + if (!PyArg_ParseTuple(args, "iiiii|p", &hour, &minute, &second, µsecond, &fold, ¯o)) { + return NULL; + } + + // Pass along to the API function + if (macro) { + rv = PyTime_FromTimeAndFold(hour, minute, second, microsecond, fold); + } + else { + rv = PyDateTimeAPI->Time_FromTimeAndFold(hour, minute, second, microsecond, Py_None, fold, PyDateTimeAPI->TimeType); + } + + return rv; +} + static PyObject * get_date_fromtimestamp(PyObject* self, PyObject *args) { @@ -4927,6 +4949,7 @@ static PyMethodDef TestMethods[] = { {"get_datetime_fromdateandtime", get_datetime_fromdateandtime, METH_VARARGS}, {"get_datetime_fromdateandtimeandfold", get_datetime_fromdateandtimeandfold, METH_VARARGS}, {"get_time_fromtime", get_time_fromtime, METH_VARARGS}, + {"get_time_fromtimeandfold", get_time_fromtimeandfold, METH_VARARGS}, {"get_date_fromtimestamp", get_date_fromtimestamp, METH_VARARGS}, {"get_datetime_fromtimestamp", get_datetime_fromtimestamp, METH_VARARGS}, {"test_list_api", test_list_api, METH_NOARGS}, From 64632de1669bced5573d387bbf938bf36897a7b8 Mon Sep 17 00:00:00 2001 From: SimiCode Date: Mon, 6 May 2019 23:43:56 +0300 Subject: [PATCH 18/43] Added a test for the C API wrapper of PyTime_FromTimeAndFold --- Lib/test/datetimetester.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index cbcdd2ca820d8f9..a26dfc5cfada3fa 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -6067,6 +6067,16 @@ def test_time_from_time(self): self.assertEqual(c_api_time, exp_time) + def test_time_from_timeandfold(self): + for fold in [0, 1]: + exp_time = time(22, 12, 55, 99999, fold=fold) + + for macro in [0, 1]: + with self.subTest(macro=macro): + c_api_time = _testcapi.get_time_fromtimeandfold(exp_time.hour, exp_time.minute, exp_time.second, exp_time.microsecond, exp_time.fold, macro) + + self.assertEqual(c_api_time, exp_time) + def test_date_from_timestamp(self): ts = datetime(1995, 4, 12).timestamp() From 501d26bdc15a5e77dc3c584282ee3b3d4b66c46f Mon Sep 17 00:00:00 2001 From: SimiCode Date: Mon, 6 May 2019 23:57:42 +0300 Subject: [PATCH 19/43] Added a C API function for PyDelta_FromDSU --- Modules/_testcapimodule.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 660bd0732babb44..d53118164ef2d48 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2450,6 +2450,28 @@ get_time_fromtimeandfold(PyObject *self, PyObject *args) return rv; } +static PyObject * +get_delta_fromdsu(PyObject *self, PyObject *args) +{ + PyObject *rv = NULL; + int days = 0, seconds = 0, microseconds = 0; + int macro = 0; + + if (!PyArg_ParseTuple(args, "iii|p", &days, &seconds, µseconds, ¯o)) { + return NULL; + } + + // Pass along to the API function + if (macro) { + rv = PyDelta_FromDSU(days, seconds, microseconds); + } + else { + rv = PyDateTimeAPI->Delta_FromDelta(days, seconds, microseconds, 1, PyDateTimeAPI->DeltaType); + } + + return rv; +} + static PyObject * get_date_fromtimestamp(PyObject* self, PyObject *args) { @@ -4950,6 +4972,7 @@ static PyMethodDef TestMethods[] = { {"get_datetime_fromdateandtimeandfold", get_datetime_fromdateandtimeandfold, METH_VARARGS}, {"get_time_fromtime", get_time_fromtime, METH_VARARGS}, {"get_time_fromtimeandfold", get_time_fromtimeandfold, METH_VARARGS}, + {"get_delta_fromdsu", get_delta_fromdsu, METH_VARARGS}, {"get_date_fromtimestamp", get_date_fromtimestamp, METH_VARARGS}, {"get_datetime_fromtimestamp", get_datetime_fromtimestamp, METH_VARARGS}, {"test_list_api", test_list_api, METH_NOARGS}, From 9adbc3d20d16195983339a175c962b3b7780c3c3 Mon Sep 17 00:00:00 2001 From: SimiCode Date: Tue, 7 May 2019 00:08:26 +0300 Subject: [PATCH 20/43] Added a test for the C API wrapper of PyDelta_FromDSU --- Lib/test/datetimetester.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index a26dfc5cfada3fa..cfa3eb592007e96 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -6077,6 +6077,15 @@ def test_time_from_timeandfold(self): self.assertEqual(c_api_time, exp_time) + def test_delta_from_dsu(self): + exp_delta = timedelta(26, 55, 99999) + + for macro in [0, 1]: + with self.subTest(macro=macro): + c_api_delta = _testcapi.get_delta_fromdsu(exp_delta.days, exp_delta.seconds, exp_delta.microseconds, macro) + + self.assertEqual(c_api_delta, exp_delta) + def test_date_from_timestamp(self): ts = datetime(1995, 4, 12).timestamp() From 237413a11e54f5e027de80122aece63b08e96850 Mon Sep 17 00:00:00 2001 From: SimiCode Date: Tue, 7 May 2019 04:52:57 +0300 Subject: [PATCH 21/43] Refactor code, re-edit lines longer than 80 chars --- Lib/test/datetimetester.py | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index cfa3eb592007e96..2ea8208b9e9d38f 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -6054,7 +6054,16 @@ def test_datetime_from_dateandtimeandfold(self): for macro in [0, 1]: with self.subTest(macro=macro): - c_api_date = _testcapi.get_datetime_fromdateandtimeandfold(exp_date.year, exp_date.month, exp_date.day, exp_date.hour, exp_date.minute, exp_date.second, exp_date.microsecond, exp_date.fold, macro) + c_api_date = _testcapi.get_datetime_fromdateandtimeandfold( + exp_date.year, + exp_date.month, + exp_date.day, + exp_date.hour, + exp_date.minute, + exp_date.second, + exp_date.microsecond, + exp_date.fold, + macro) self.assertEqual(c_api_date, exp_date) @@ -6063,7 +6072,12 @@ def test_time_from_time(self): for macro in [0, 1]: with self.subTest(macro=macro): - c_api_time = _testcapi.get_time_fromtime(exp_time.hour, exp_time.minute, exp_time.second, exp_time.microsecond, macro) + c_api_time = _testcapi.get_time_fromtime( + exp_time.hour, + exp_time.minute, + exp_time.second, + exp_time.microsecond, + macro) self.assertEqual(c_api_time, exp_time) @@ -6073,7 +6087,13 @@ def test_time_from_timeandfold(self): for macro in [0, 1]: with self.subTest(macro=macro): - c_api_time = _testcapi.get_time_fromtimeandfold(exp_time.hour, exp_time.minute, exp_time.second, exp_time.microsecond, exp_time.fold, macro) + c_api_time = _testcapi.get_time_fromtimeandfold( + exp_time.hour, + exp_time.minute, + exp_time.second, + exp_time.microsecond, + exp_time.fold, + macro) self.assertEqual(c_api_time, exp_time) @@ -6082,7 +6102,11 @@ def test_delta_from_dsu(self): for macro in [0, 1]: with self.subTest(macro=macro): - c_api_delta = _testcapi.get_delta_fromdsu(exp_delta.days, exp_delta.seconds, exp_delta.microseconds, macro) + c_api_delta = _testcapi.get_delta_fromdsu( + exp_delta.days, + exp_delta.seconds, + exp_delta.microseconds, + macro) self.assertEqual(c_api_delta, exp_delta) From dc6ac8e473f81eb38d86153f1e412d3a546963d0 Mon Sep 17 00:00:00 2001 From: SimiCode Date: Tue, 7 May 2019 04:55:34 +0300 Subject: [PATCH 22/43] Fix Whitespace issues in DatetimeTester --- Lib/test/datetimetester.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index 2ea8208b9e9d38f..ffd6ebb83d7fa9f 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -6055,14 +6055,14 @@ def test_datetime_from_dateandtimeandfold(self): for macro in [0, 1]: with self.subTest(macro=macro): c_api_date = _testcapi.get_datetime_fromdateandtimeandfold( - exp_date.year, - exp_date.month, - exp_date.day, - exp_date.hour, - exp_date.minute, - exp_date.second, - exp_date.microsecond, - exp_date.fold, + exp_date.year, + exp_date.month, + exp_date.day, + exp_date.hour, + exp_date.minute, + exp_date.second, + exp_date.microsecond, + exp_date.fold, macro) self.assertEqual(c_api_date, exp_date) @@ -6073,10 +6073,10 @@ def test_time_from_time(self): for macro in [0, 1]: with self.subTest(macro=macro): c_api_time = _testcapi.get_time_fromtime( - exp_time.hour, - exp_time.minute, - exp_time.second, - exp_time.microsecond, + exp_time.hour, + exp_time.minute, + exp_time.second, + exp_time.microsecond, macro) self.assertEqual(c_api_time, exp_time) @@ -6088,11 +6088,11 @@ def test_time_from_timeandfold(self): for macro in [0, 1]: with self.subTest(macro=macro): c_api_time = _testcapi.get_time_fromtimeandfold( - exp_time.hour, - exp_time.minute, - exp_time.second, - exp_time.microsecond, - exp_time.fold, + exp_time.hour, + exp_time.minute, + exp_time.second, + exp_time.microsecond, + exp_time.fold, macro) self.assertEqual(c_api_time, exp_time) @@ -6104,8 +6104,8 @@ def test_delta_from_dsu(self): with self.subTest(macro=macro): c_api_delta = _testcapi.get_delta_fromdsu( exp_delta.days, - exp_delta.seconds, - exp_delta.microseconds, + exp_delta.seconds, + exp_delta.microseconds, macro) self.assertEqual(c_api_delta, exp_delta) From d7b8a5ec45c18baa31434fc5e96b3c2dce6aec46 Mon Sep 17 00:00:00 2001 From: SimiCode Date: Tue, 7 May 2019 05:38:02 +0300 Subject: [PATCH 23/43] List all tests that were added in this PR --- .../Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst b/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst index 7b41b73c7823f91..5881c0cd371e967 100644 --- a/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst +++ b/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst @@ -1 +1,9 @@ -Created a test for the C API function :c:func:`PyDate_FromDate`. Patch by Edison Abahurire. +Created tests for these C API functions +- :c:func:`PyDate_FromDate`. +- :c:func:`PyDateTime_FromDateAndTime`. +- :c:func:`PyDateTime_FromDateAndTimeAndFold`. +- :c:func:`PyTime_FromTime`. +- :c:func:`PyTime_FromTimeAndFold`. +- :c:func:`PyDelta_FromDSU`. + +Patch by Edison Abahurire. \ No newline at end of file From ce9e56d3a3097f87e6b752c45c40949999b6ca39 Mon Sep 17 00:00:00 2001 From: Edison A <20975616+SimiCode@users.noreply.github.com> Date: Tue, 7 May 2019 18:34:43 +0300 Subject: [PATCH 24/43] Update 2019-05-04-21-25-19.bpo-36782.h3oPIb.rst --- .../Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst b/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst index 5881c0cd371e967..ec479cfad7509bb 100644 --- a/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst +++ b/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst @@ -1,9 +1 @@ -Created tests for these C API functions -- :c:func:`PyDate_FromDate`. -- :c:func:`PyDateTime_FromDateAndTime`. -- :c:func:`PyDateTime_FromDateAndTimeAndFold`. -- :c:func:`PyTime_FromTime`. -- :c:func:`PyTime_FromTimeAndFold`. -- :c:func:`PyDelta_FromDSU`. - -Patch by Edison Abahurire. \ No newline at end of file +Created tests for C API functions. Patch by Edison Abahurire. From 2f3f64e08318479bad1328bd5dbf433a2fc62a02 Mon Sep 17 00:00:00 2001 From: SimiCode Date: Tue, 7 May 2019 20:35:19 +0300 Subject: [PATCH 25/43] Reformat code as per PEP7 guidelines --- Lib/test/datetimetester.py | 12 ++--- Modules/_testcapimodule.c | 93 ++++++++++++++++++++++++++++++-------- 2 files changed, 81 insertions(+), 24 deletions(-) diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index ffd6ebb83d7fa9f..142306328e0463a 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -6049,11 +6049,11 @@ def test_datetime_from_dateandtime(self): self.assertEqual(c_api_date, exp_date) def test_datetime_from_dateandtimeandfold(self): - for fold in [0, 1]: - exp_date = datetime(1993, 8, 26, 22, 12, 55, 99999, fold=fold) + exp_date = datetime(1993, 8, 26, 22, 12, 55, 99999) + for fold in [0, 1]: for macro in [0, 1]: - with self.subTest(macro=macro): + with self.subTest(macro=macro, fold=fold): c_api_date = _testcapi.get_datetime_fromdateandtimeandfold( exp_date.year, exp_date.month, @@ -6082,11 +6082,11 @@ def test_time_from_time(self): self.assertEqual(c_api_time, exp_time) def test_time_from_timeandfold(self): - for fold in [0, 1]: - exp_time = time(22, 12, 55, 99999, fold=fold) + exp_time = time(22, 12, 55, 99999) + for fold in [0, 1]: for macro in [0, 1]: - with self.subTest(macro=macro): + with self.subTest(macro=macro, fold=fold): c_api_time = _testcapi.get_time_fromtimeandfold( exp_time.hour, exp_time.minute, diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index d53118164ef2d48..3c3b070b10d6be4 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2355,8 +2355,11 @@ get_date_fromdate(PyObject *self, PyObject *args) if (macro) { rv = PyDate_FromDate(year, month, day); } + else { - rv = PyDateTimeAPI->Date_FromDate(year, month, day, PyDateTimeAPI->DateType); + rv = PyDateTimeAPI->Date_FromDate( + year, month, day, + PyDateTimeAPI->DateType); } return rv; @@ -2366,21 +2369,35 @@ static PyObject * get_datetime_fromdateandtime(PyObject *self, PyObject *args) { PyObject *rv = NULL; - int year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0, microsecond = 0; + int year = 0, month = 0, day = 0; + int hour = 0, minute = 0, second = 0, microsecond = 0; int macro = 0; - if (!PyArg_ParseTuple(args, "iiiiiii|p", &year, &month, &day, &hour, &minute, &second, µsecond, ¯o)) { + if (!PyArg_ParseTuple( + args, + "iiiiiii|p", + &year, &month, &day, + &hour, &minute, &second, µsecond, + ¯o)) + { + return NULL; } // Pass along to the API function if (macro) { - rv = PyDateTime_FromDateAndTime(year, month, day, hour, minute, second, microsecond); + rv = PyDateTime_FromDateAndTime( + year, month, day, + hour, minute, second, microsecond); } + else { - rv = PyDateTimeAPI->DateTime_FromDateAndTime(year, month, day, hour, minute, second, microsecond, Py_None, PyDateTimeAPI->DateTimeType); + rv = PyDateTimeAPI->DateTime_FromDateAndTime( + year, month, day, + hour, minute, second, microsecond, + Py_None, + PyDateTimeAPI->DateTimeType); } - return rv; } @@ -2388,23 +2405,39 @@ static PyObject * get_datetime_fromdateandtimeandfold(PyObject *self, PyObject *args) { PyObject *rv = NULL; - int year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0, microsecond = 0, fold = 0; + int year = 0, month = 0, day = 0; + int hour = 0, minute = 0, second = 0, microsecond = 0, fold = 0; int macro = 0; - if (!PyArg_ParseTuple(args, "iiiiiiii|p", &year, &month, &day, &hour, &minute, &second, µsecond, &fold, ¯o)) { + if (!PyArg_ParseTuple( + args, "iiiiiiii|p", + &year, &month, &day, + &hour, &minute, &second, µsecond, + &fold, + ¯o)) { + return NULL; } // Pass along to the API function if (macro) { - rv = PyDateTime_FromDateAndTimeAndFold(year, month, day, hour, minute, second, microsecond, fold); + rv = PyDateTime_FromDateAndTimeAndFold( + year, month, day, + hour, minute, second, microsecond, + fold); } + else { - rv = PyDateTimeAPI->DateTime_FromDateAndTimeAndFold(year, month, day, hour, minute, second, microsecond, Py_None, fold, PyDateTimeAPI->DateTimeType); + rv = PyDateTimeAPI->DateTime_FromDateAndTimeAndFold( + year, month, day, + hour, minute, second, microsecond, + Py_None, + fold, + PyDateTimeAPI->DateTimeType); } - return rv; -} + return rv; + } static PyObject * get_time_fromtime(PyObject *self, PyObject *args) @@ -2413,7 +2446,12 @@ get_time_fromtime(PyObject *self, PyObject *args) int hour = 0, minute = 0, second = 0, microsecond = 0; int macro = 0; - if (!PyArg_ParseTuple(args, "iiii|p", &hour, &minute, &second, µsecond, ¯o)) { + if (!PyArg_ParseTuple( + args, + "iiii|p", + &hour, &minute, &second, µsecond, + ¯o)) { + return NULL; } @@ -2422,7 +2460,10 @@ get_time_fromtime(PyObject *self, PyObject *args) rv = PyTime_FromTime(hour, minute, second, microsecond); } else { - rv = PyDateTimeAPI->Time_FromTime(hour, minute, second, microsecond, Py_None, PyDateTimeAPI->TimeType); + rv = PyDateTimeAPI->Time_FromTime( + hour, minute, second, microsecond, + Py_None, + PyDateTimeAPI->TimeType); } return rv; @@ -2435,7 +2476,12 @@ get_time_fromtimeandfold(PyObject *self, PyObject *args) int hour = 0, minute = 0, second = 0, microsecond = 0, fold = 0; int macro = 0; - if (!PyArg_ParseTuple(args, "iiiii|p", &hour, &minute, &second, µsecond, &fold, ¯o)) { + if (!PyArg_ParseTuple( + args, + "iiiii|p", + &hour, &minute, &second, µsecond, &fold, + ¯o)) { + return NULL; } @@ -2444,7 +2490,11 @@ get_time_fromtimeandfold(PyObject *self, PyObject *args) rv = PyTime_FromTimeAndFold(hour, minute, second, microsecond, fold); } else { - rv = PyDateTimeAPI->Time_FromTimeAndFold(hour, minute, second, microsecond, Py_None, fold, PyDateTimeAPI->TimeType); + rv = PyDateTimeAPI->Time_FromTimeAndFold( + hour, minute, second, microsecond, + Py_None, + fold, + PyDateTimeAPI->TimeType); } return rv; @@ -2457,7 +2507,12 @@ get_delta_fromdsu(PyObject *self, PyObject *args) int days = 0, seconds = 0, microseconds = 0; int macro = 0; - if (!PyArg_ParseTuple(args, "iii|p", &days, &seconds, µseconds, ¯o)) { + if (!PyArg_ParseTuple( + args, + "iii|p", + &days, &seconds, µseconds, + ¯o)) { + return NULL; } @@ -2466,7 +2521,9 @@ get_delta_fromdsu(PyObject *self, PyObject *args) rv = PyDelta_FromDSU(days, seconds, microseconds); } else { - rv = PyDateTimeAPI->Delta_FromDelta(days, seconds, microseconds, 1, PyDateTimeAPI->DeltaType); + rv = PyDateTimeAPI->Delta_FromDelta( + days, seconds, microseconds, 1, + PyDateTimeAPI->DeltaType); } return rv; From a8817d3bcbb886229b9dafd201d619e3c4a817e9 Mon Sep 17 00:00:00 2001 From: SimiCode Date: Tue, 7 May 2019 20:36:27 +0300 Subject: [PATCH 26/43] Remove unused varibles from another function --- Lib/test/datetimetester.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index 142306328e0463a..c4fa800d2fd7e10 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -6120,9 +6120,6 @@ def test_date_from_timestamp(self): self.assertEqual(d, date(1995, 4, 12)) def test_datetime_from_timestamp(self): - ts0 = datetime(1995, 4, 12).timestamp() - ts1 = datetime(1995, 4, 12, 12, 30).timestamp() - cases = [ ((1995, 4, 12), None, False), ((1995, 4, 12), None, True), From 2781d2ed9b50293f6b0d52e460df7f62dd2ed52d Mon Sep 17 00:00:00 2001 From: SimiCode Date: Tue, 7 May 2019 20:51:28 +0300 Subject: [PATCH 27/43] Added specific tests for the Fold Attribute --- Lib/test/datetimetester.py | 2 ++ Modules/_testcapimodule.c | 66 +++++++++++++++++++------------------- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index c4fa800d2fd7e10..171db8399d5d51d 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -6066,6 +6066,7 @@ def test_datetime_from_dateandtimeandfold(self): macro) self.assertEqual(c_api_date, exp_date) + self.assertEqual(c_api_date.fold, exp_date.fold) def test_time_from_time(self): exp_time = time(22, 12, 55, 99999) @@ -6096,6 +6097,7 @@ def test_time_from_timeandfold(self): macro) self.assertEqual(c_api_time, exp_time) + self.assertEqual(c_api_time.fold, exp_time.fold) def test_delta_from_dsu(self): exp_delta = timedelta(26, 55, 99999) diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 3c3b070b10d6be4..7548089bbb0ab96 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2369,16 +2369,16 @@ static PyObject * get_datetime_fromdateandtime(PyObject *self, PyObject *args) { PyObject *rv = NULL; - int year = 0, month = 0, day = 0; + int year = 0, month = 0, day = 0; int hour = 0, minute = 0, second = 0, microsecond = 0; int macro = 0; if (!PyArg_ParseTuple( - args, - "iiiiiii|p", - &year, &month, &day, - &hour, &minute, &second, µsecond, - ¯o)) + args, + "iiiiiii|p", + &year, &month, &day, + &hour, &minute, &second, µsecond, + ¯o)) { return NULL; @@ -2387,14 +2387,14 @@ get_datetime_fromdateandtime(PyObject *self, PyObject *args) // Pass along to the API function if (macro) { rv = PyDateTime_FromDateAndTime( - year, month, day, + year, month, day, hour, minute, second, microsecond); } else { rv = PyDateTimeAPI->DateTime_FromDateAndTime( - year, month, day, - hour, minute, second, microsecond, + year, month, day, + hour, minute, second, microsecond, Py_None, PyDateTimeAPI->DateTimeType); } @@ -2410,10 +2410,10 @@ get_datetime_fromdateandtimeandfold(PyObject *self, PyObject *args) int macro = 0; if (!PyArg_ParseTuple( - args, "iiiiiiii|p", - &year, &month, &day, - &hour, &minute, &second, µsecond, - &fold, + args, "iiiiiiii|p", + &year, &month, &day, + &hour, &minute, &second, µsecond, + &fold, ¯o)) { return NULL; @@ -2422,17 +2422,17 @@ get_datetime_fromdateandtimeandfold(PyObject *self, PyObject *args) // Pass along to the API function if (macro) { rv = PyDateTime_FromDateAndTimeAndFold( - year, month, day, - hour, minute, second, microsecond, + year, month, day, + hour, minute, second, microsecond, fold); } else { rv = PyDateTimeAPI->DateTime_FromDateAndTimeAndFold( - year, month, day, - hour, minute, second, microsecond, - Py_None, - fold, + year, month, day, + hour, minute, second, microsecond, + Py_None, + fold, PyDateTimeAPI->DateTimeType); } @@ -2447,9 +2447,9 @@ get_time_fromtime(PyObject *self, PyObject *args) int macro = 0; if (!PyArg_ParseTuple( - args, - "iiii|p", - &hour, &minute, &second, µsecond, + args, + "iiii|p", + &hour, &minute, &second, µsecond, ¯o)) { return NULL; @@ -2461,8 +2461,8 @@ get_time_fromtime(PyObject *self, PyObject *args) } else { rv = PyDateTimeAPI->Time_FromTime( - hour, minute, second, microsecond, - Py_None, + hour, minute, second, microsecond, + Py_None, PyDateTimeAPI->TimeType); } @@ -2479,7 +2479,7 @@ get_time_fromtimeandfold(PyObject *self, PyObject *args) if (!PyArg_ParseTuple( args, "iiiii|p", - &hour, &minute, &second, µsecond, &fold, + &hour, &minute, &second, µsecond, &fold, ¯o)) { return NULL; @@ -2491,9 +2491,9 @@ get_time_fromtimeandfold(PyObject *self, PyObject *args) } else { rv = PyDateTimeAPI->Time_FromTimeAndFold( - hour, minute, second, microsecond, - Py_None, - fold, + hour, minute, second, microsecond, + Py_None, + fold, PyDateTimeAPI->TimeType); } @@ -2504,13 +2504,13 @@ static PyObject * get_delta_fromdsu(PyObject *self, PyObject *args) { PyObject *rv = NULL; - int days = 0, seconds = 0, microseconds = 0; + int days = 0, seconds = 0, microseconds = 0; int macro = 0; if (!PyArg_ParseTuple( - args, - "iii|p", - &days, &seconds, µseconds, + args, + "iii|p", + &days, &seconds, µseconds, ¯o)) { return NULL; @@ -2522,7 +2522,7 @@ get_delta_fromdsu(PyObject *self, PyObject *args) } else { rv = PyDateTimeAPI->Delta_FromDelta( - days, seconds, microseconds, 1, + days, seconds, microseconds, 1, PyDateTimeAPI->DeltaType); } From 91fce0284accd3498ffef569c285cdf07142a488 Mon Sep 17 00:00:00 2001 From: Edison A <20975616+SimiCode@users.noreply.github.com> Date: Tue, 7 May 2019 21:00:52 +0300 Subject: [PATCH 28/43] Update 2019-05-04-21-25-19.bpo-36782.h3oPIb.rst --- Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst b/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst index ec479cfad7509bb..cd969f96e7f342a 100644 --- a/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst +++ b/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst @@ -1 +1 @@ -Created tests for C API functions. Patch by Edison Abahurire. +Created tests for several C API functions in the datetime module, specifically:: From 5cb05e10817d81fe93a4526ae2b8a076f2f6781c Mon Sep 17 00:00:00 2001 From: SimiCode Date: Tue, 7 May 2019 22:44:33 +0300 Subject: [PATCH 29/43] Reformat code according to requested changes --- Modules/_testcapimodule.c | 58 ++++++++++++++------------------------- 1 file changed, 20 insertions(+), 38 deletions(-) diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 7548089bbb0ab96..abbc6143ff974bc 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2355,7 +2355,6 @@ get_date_fromdate(PyObject *self, PyObject *args) if (macro) { rv = PyDate_FromDate(year, month, day); } - else { rv = PyDateTimeAPI->Date_FromDate( year, month, day, @@ -2373,14 +2372,10 @@ get_datetime_fromdateandtime(PyObject *self, PyObject *args) int hour = 0, minute = 0, second = 0, microsecond = 0; int macro = 0; - if (!PyArg_ParseTuple( - args, - "iiiiiii|p", - &year, &month, &day, - &hour, &minute, &second, µsecond, - ¯o)) - { - + if (!PyArg_ParseTuple(args, "iiiiiii|p", + &year, &month, &day, + &hour, &minute, &second, µsecond, + ¯o)) { return NULL; } @@ -2390,7 +2385,6 @@ get_datetime_fromdateandtime(PyObject *self, PyObject *args) year, month, day, hour, minute, second, microsecond); } - else { rv = PyDateTimeAPI->DateTime_FromDateAndTime( year, month, day, @@ -2398,6 +2392,7 @@ get_datetime_fromdateandtime(PyObject *self, PyObject *args) Py_None, PyDateTimeAPI->DateTimeType); } + return rv; } @@ -2409,13 +2404,10 @@ get_datetime_fromdateandtimeandfold(PyObject *self, PyObject *args) int hour = 0, minute = 0, second = 0, microsecond = 0, fold = 0; int macro = 0; - if (!PyArg_ParseTuple( - args, "iiiiiiii|p", - &year, &month, &day, - &hour, &minute, &second, µsecond, - &fold, - ¯o)) { - + if (!PyArg_ParseTuple(args, "iiiiiiii|p", + &year, &month, &day, + &hour, &minute, &second, µsecond, + &fold, ¯o)) { return NULL; } @@ -2426,7 +2418,6 @@ get_datetime_fromdateandtimeandfold(PyObject *self, PyObject *args) hour, minute, second, microsecond, fold); } - else { rv = PyDateTimeAPI->DateTime_FromDateAndTimeAndFold( year, month, day, @@ -2436,8 +2427,8 @@ get_datetime_fromdateandtimeandfold(PyObject *self, PyObject *args) PyDateTimeAPI->DateTimeType); } - return rv; - } + return rv; +} static PyObject * get_time_fromtime(PyObject *self, PyObject *args) @@ -2446,12 +2437,9 @@ get_time_fromtime(PyObject *self, PyObject *args) int hour = 0, minute = 0, second = 0, microsecond = 0; int macro = 0; - if (!PyArg_ParseTuple( - args, - "iiii|p", - &hour, &minute, &second, µsecond, - ¯o)) { - + if (!PyArg_ParseTuple(args, "iiii|p", + &hour, &minute, &second, µsecond, + ¯o)) { return NULL; } @@ -2476,12 +2464,9 @@ get_time_fromtimeandfold(PyObject *self, PyObject *args) int hour = 0, minute = 0, second = 0, microsecond = 0, fold = 0; int macro = 0; - if (!PyArg_ParseTuple( - args, - "iiiii|p", - &hour, &minute, &second, µsecond, &fold, - ¯o)) { - + if (!PyArg_ParseTuple(args, "iiiii|p", + &hour, &minute, &second, µsecond, + &fold, ¯o)) { return NULL; } @@ -2507,12 +2492,9 @@ get_delta_fromdsu(PyObject *self, PyObject *args) int days = 0, seconds = 0, microseconds = 0; int macro = 0; - if (!PyArg_ParseTuple( - args, - "iii|p", - &days, &seconds, µseconds, - ¯o)) { - + if (!PyArg_ParseTuple(args, "iii|p", + &days, &seconds, µseconds, + ¯o)) { return NULL; } From 603953155916e63630db482f513a26a14d4a2e75 Mon Sep 17 00:00:00 2001 From: SimiCode Date: Tue, 7 May 2019 22:45:25 +0300 Subject: [PATCH 30/43] Reformat code to PEP7 Guidelines --- Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst b/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst index cd969f96e7f342a..d6f933453a02d32 100644 --- a/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst +++ b/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst @@ -1 +1 @@ -Created tests for several C API functions in the datetime module, specifically:: +Add tests for several C API functions in the :mod:datetime module. Patch by Edison Abahurire From 07924e64dec58e2713e739328175ca5a561ff000 Mon Sep 17 00:00:00 2001 From: SimiCode Date: Tue, 7 May 2019 22:59:33 +0300 Subject: [PATCH 31/43] Reformat code to PEP7 Guidelines --- Modules/_testcapimodule.c | 58 ++++++++++++++------------------------- 1 file changed, 20 insertions(+), 38 deletions(-) diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 7548089bbb0ab96..abbc6143ff974bc 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2355,7 +2355,6 @@ get_date_fromdate(PyObject *self, PyObject *args) if (macro) { rv = PyDate_FromDate(year, month, day); } - else { rv = PyDateTimeAPI->Date_FromDate( year, month, day, @@ -2373,14 +2372,10 @@ get_datetime_fromdateandtime(PyObject *self, PyObject *args) int hour = 0, minute = 0, second = 0, microsecond = 0; int macro = 0; - if (!PyArg_ParseTuple( - args, - "iiiiiii|p", - &year, &month, &day, - &hour, &minute, &second, µsecond, - ¯o)) - { - + if (!PyArg_ParseTuple(args, "iiiiiii|p", + &year, &month, &day, + &hour, &minute, &second, µsecond, + ¯o)) { return NULL; } @@ -2390,7 +2385,6 @@ get_datetime_fromdateandtime(PyObject *self, PyObject *args) year, month, day, hour, minute, second, microsecond); } - else { rv = PyDateTimeAPI->DateTime_FromDateAndTime( year, month, day, @@ -2398,6 +2392,7 @@ get_datetime_fromdateandtime(PyObject *self, PyObject *args) Py_None, PyDateTimeAPI->DateTimeType); } + return rv; } @@ -2409,13 +2404,10 @@ get_datetime_fromdateandtimeandfold(PyObject *self, PyObject *args) int hour = 0, minute = 0, second = 0, microsecond = 0, fold = 0; int macro = 0; - if (!PyArg_ParseTuple( - args, "iiiiiiii|p", - &year, &month, &day, - &hour, &minute, &second, µsecond, - &fold, - ¯o)) { - + if (!PyArg_ParseTuple(args, "iiiiiiii|p", + &year, &month, &day, + &hour, &minute, &second, µsecond, + &fold, ¯o)) { return NULL; } @@ -2426,7 +2418,6 @@ get_datetime_fromdateandtimeandfold(PyObject *self, PyObject *args) hour, minute, second, microsecond, fold); } - else { rv = PyDateTimeAPI->DateTime_FromDateAndTimeAndFold( year, month, day, @@ -2436,8 +2427,8 @@ get_datetime_fromdateandtimeandfold(PyObject *self, PyObject *args) PyDateTimeAPI->DateTimeType); } - return rv; - } + return rv; +} static PyObject * get_time_fromtime(PyObject *self, PyObject *args) @@ -2446,12 +2437,9 @@ get_time_fromtime(PyObject *self, PyObject *args) int hour = 0, minute = 0, second = 0, microsecond = 0; int macro = 0; - if (!PyArg_ParseTuple( - args, - "iiii|p", - &hour, &minute, &second, µsecond, - ¯o)) { - + if (!PyArg_ParseTuple(args, "iiii|p", + &hour, &minute, &second, µsecond, + ¯o)) { return NULL; } @@ -2476,12 +2464,9 @@ get_time_fromtimeandfold(PyObject *self, PyObject *args) int hour = 0, minute = 0, second = 0, microsecond = 0, fold = 0; int macro = 0; - if (!PyArg_ParseTuple( - args, - "iiiii|p", - &hour, &minute, &second, µsecond, &fold, - ¯o)) { - + if (!PyArg_ParseTuple(args, "iiiii|p", + &hour, &minute, &second, µsecond, + &fold, ¯o)) { return NULL; } @@ -2507,12 +2492,9 @@ get_delta_fromdsu(PyObject *self, PyObject *args) int days = 0, seconds = 0, microseconds = 0; int macro = 0; - if (!PyArg_ParseTuple( - args, - "iii|p", - &days, &seconds, µseconds, - ¯o)) { - + if (!PyArg_ParseTuple(args, "iii|p", + &days, &seconds, µseconds, + ¯o)) { return NULL; } From 59d4ba09da540cd82b36c5a651de3ff13217efab Mon Sep 17 00:00:00 2001 From: SimiCode Date: Tue, 7 May 2019 23:02:34 +0300 Subject: [PATCH 32/43] Re-add name to blurb --- Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst b/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst index cd969f96e7f342a..adbe694a9a49245 100644 --- a/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst +++ b/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst @@ -1 +1 @@ -Created tests for several C API functions in the datetime module, specifically:: +Add tests for several C API functions in the :mod:datetime module. Patch by Edison Abahurire. From 0c0046852443987857f250ec4d4a00a78b43c131 Mon Sep 17 00:00:00 2001 From: SimiCode Date: Tue, 7 May 2019 23:12:35 +0300 Subject: [PATCH 33/43] Added a backtick to blurb file --- Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst b/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst index adbe694a9a49245..e9f291bef8a4e6f 100644 --- a/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst +++ b/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst @@ -1 +1 @@ -Add tests for several C API functions in the :mod:datetime module. Patch by Edison Abahurire. +Add tests for several C API functions in the `:mod:datetime module`. Patch by Edison Abahurire. From 1d4ebfcd4a47ea2ed9eb5c1f2195e85ef2690a82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Wirtel?= Date: Tue, 7 May 2019 16:53:44 -0400 Subject: [PATCH 34/43] Update 2019-05-04-21-25-19.bpo-36782.h3oPIb.rst --- Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst b/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst index e9f291bef8a4e6f..222fb386ca7bca5 100644 --- a/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst +++ b/Misc/NEWS.d/next/Tests/2019-05-04-21-25-19.bpo-36782.h3oPIb.rst @@ -1 +1 @@ -Add tests for several C API functions in the `:mod:datetime module`. Patch by Edison Abahurire. +Add tests for several C API functions in the :mod:`datetime` module. Patch by Edison Abahurire. From 75cc9c0c34f53c80d2ece17ff0b4b7d5c9f03354 Mon Sep 17 00:00:00 2001 From: SimiCode Date: Wed, 8 May 2019 17:44:16 +0300 Subject: [PATCH 35/43] Remove the need to initialize mandatory parameters --- Modules/_testcapimodule.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index ea2dd98587fb34e..06b8ca7a146f41e 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2344,7 +2344,7 @@ static PyObject * get_date_fromdate(PyObject *self, PyObject *args) { PyObject *rv = NULL; - int year = 0, month = 0, day = 0; + int year, month, day; int macro = 0; if (!PyArg_ParseTuple(args, "iii|p", &year, &month, &day, ¯o)) { @@ -2366,8 +2366,8 @@ static PyObject * get_datetime_fromdateandtime(PyObject *self, PyObject *args) { PyObject *rv = NULL; - int year = 0, month = 0, day = 0; - int hour = 0, minute = 0, second = 0, microsecond = 0; + int year, month, day; + int hour, minute, second, microsecond; int macro = 0; if (!PyArg_ParseTuple(args, "iiiiiii|p", @@ -2396,8 +2396,8 @@ static PyObject * get_datetime_fromdateandtimeandfold(PyObject *self, PyObject *args) { PyObject *rv = NULL; - int year = 0, month = 0, day = 0; - int hour = 0, minute = 0, second = 0, microsecond = 0, fold = 0; + int year, month, day; + int hour, minute, second, microsecond, fold; int macro = 0; if (!PyArg_ParseTuple(args, "iiiiiiii|p", @@ -2428,7 +2428,7 @@ static PyObject * get_time_fromtime(PyObject *self, PyObject *args) { PyObject *rv = NULL; - int hour = 0, minute = 0, second = 0, microsecond = 0; + int hour, minute, second, microsecond; int macro = 0; if (!PyArg_ParseTuple(args, "iiii|p", @@ -2453,7 +2453,7 @@ static PyObject * get_time_fromtimeandfold(PyObject *self, PyObject *args) { PyObject *rv = NULL; - int hour = 0, minute = 0, second = 0, microsecond = 0, fold = 0; + int hour, minute, second, microsecond, fold; int macro = 0; if (!PyArg_ParseTuple(args, "iiiii|p", @@ -2479,7 +2479,7 @@ static PyObject * get_delta_fromdsu(PyObject *self, PyObject *args) { PyObject *rv = NULL; - int days = 0, seconds = 0, microseconds = 0; + int days, seconds, microseconds; int macro = 0; if (!PyArg_ParseTuple(args, "iii|p", From a9422a0d6cb34fd13febe731099745284ef71720 Mon Sep 17 00:00:00 2001 From: SimiCode Date: Wed, 8 May 2019 19:06:54 +0300 Subject: [PATCH 36/43] Make the macro parameter mandatory --- Modules/_testcapimodule.c | 42 ++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 06b8ca7a146f41e..03525ba6671cc14 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2344,10 +2344,10 @@ static PyObject * get_date_fromdate(PyObject *self, PyObject *args) { PyObject *rv = NULL; - int year, month, day; int macro = 0; + int year, month, day; - if (!PyArg_ParseTuple(args, "iii|p", &year, &month, &day, ¯o)) { + if (!PyArg_ParseTuple(args, "piii", ¯o, &year, &month, &day)) { return NULL; } @@ -2366,14 +2366,14 @@ static PyObject * get_datetime_fromdateandtime(PyObject *self, PyObject *args) { PyObject *rv = NULL; + int macro = 0; int year, month, day; int hour, minute, second, microsecond; - int macro = 0; - if (!PyArg_ParseTuple(args, "iiiiiii|p", + if (!PyArg_ParseTuple(args, "piiiiiii", + ¯o, &year, &month, &day, - &hour, &minute, &second, µsecond, - ¯o)) { + &hour, &minute, &second, µsecond)) { return NULL; } @@ -2396,14 +2396,15 @@ static PyObject * get_datetime_fromdateandtimeandfold(PyObject *self, PyObject *args) { PyObject *rv = NULL; + int macro = 0; int year, month, day; int hour, minute, second, microsecond, fold; - int macro = 0; - if (!PyArg_ParseTuple(args, "iiiiiiii|p", + if (!PyArg_ParseTuple(args, "piiiiiiii", + ¯o, &year, &month, &day, &hour, &minute, &second, µsecond, - &fold, ¯o)) { + &fold)) { return NULL; } @@ -2428,12 +2429,12 @@ static PyObject * get_time_fromtime(PyObject *self, PyObject *args) { PyObject *rv = NULL; - int hour, minute, second, microsecond; int macro = 0; + int hour, minute, second, microsecond; - if (!PyArg_ParseTuple(args, "iiii|p", - &hour, &minute, &second, µsecond, - ¯o)) { + if (!PyArg_ParseTuple(args, "piiii", + ¯o, + &hour, &minute, &second, µsecond)) { return NULL; } @@ -2453,12 +2454,13 @@ static PyObject * get_time_fromtimeandfold(PyObject *self, PyObject *args) { PyObject *rv = NULL; - int hour, minute, second, microsecond, fold; int macro = 0; + int hour, minute, second, microsecond, fold; - if (!PyArg_ParseTuple(args, "iiiii|p", + if (!PyArg_ParseTuple(args, "piiiii", + ¯o, &hour, &minute, &second, µsecond, - &fold, ¯o)) { + &fold)) { return NULL; } @@ -2479,12 +2481,12 @@ static PyObject * get_delta_fromdsu(PyObject *self, PyObject *args) { PyObject *rv = NULL; - int days, seconds, microseconds; int macro = 0; + int days, seconds, microseconds; - if (!PyArg_ParseTuple(args, "iii|p", - &days, &seconds, µseconds, - ¯o)) { + if (!PyArg_ParseTuple(args, "piii", + ¯o, + &days, &seconds, µseconds)) { return NULL; } From 6df027ec193420655f811809a06bd5412728ca95 Mon Sep 17 00:00:00 2001 From: SimiCode Date: Wed, 8 May 2019 20:26:26 +0300 Subject: [PATCH 37/43] Re-arrange the order of unit-test args --- Lib/test/datetimetester.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index 171db8399d5d51d..3593a1045f65af3 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -6024,10 +6024,10 @@ def test_date_from_date(self): for macro in [0, 1]: with self.subTest(macro=macro): c_api_date = _testcapi.get_date_fromdate( + macro, exp_date.year, exp_date.month, - exp_date.day, - macro) + exp_date.day) self.assertEqual(c_api_date, exp_date) @@ -6037,14 +6037,14 @@ def test_datetime_from_dateandtime(self): for macro in [0, 1]: with self.subTest(macro=macro): c_api_date = _testcapi.get_datetime_fromdateandtime( + macro, exp_date.year, exp_date.month, exp_date.day, exp_date.hour, exp_date.minute, exp_date.second, - exp_date.microsecond, - macro) + exp_date.microsecond) self.assertEqual(c_api_date, exp_date) @@ -6055,6 +6055,7 @@ def test_datetime_from_dateandtimeandfold(self): for macro in [0, 1]: with self.subTest(macro=macro, fold=fold): c_api_date = _testcapi.get_datetime_fromdateandtimeandfold( + macro, exp_date.year, exp_date.month, exp_date.day, @@ -6062,8 +6063,7 @@ def test_datetime_from_dateandtimeandfold(self): exp_date.minute, exp_date.second, exp_date.microsecond, - exp_date.fold, - macro) + exp_date.fold) self.assertEqual(c_api_date, exp_date) self.assertEqual(c_api_date.fold, exp_date.fold) @@ -6074,11 +6074,11 @@ def test_time_from_time(self): for macro in [0, 1]: with self.subTest(macro=macro): c_api_time = _testcapi.get_time_fromtime( + macro, exp_time.hour, exp_time.minute, exp_time.second, - exp_time.microsecond, - macro) + exp_time.microsecond) self.assertEqual(c_api_time, exp_time) @@ -6089,12 +6089,12 @@ def test_time_from_timeandfold(self): for macro in [0, 1]: with self.subTest(macro=macro, fold=fold): c_api_time = _testcapi.get_time_fromtimeandfold( + macro, exp_time.hour, exp_time.minute, exp_time.second, exp_time.microsecond, - exp_time.fold, - macro) + exp_time.fold) self.assertEqual(c_api_time, exp_time) self.assertEqual(c_api_time.fold, exp_time.fold) @@ -6105,10 +6105,10 @@ def test_delta_from_dsu(self): for macro in [0, 1]: with self.subTest(macro=macro): c_api_delta = _testcapi.get_delta_fromdsu( + macro, exp_delta.days, exp_delta.seconds, - exp_delta.microseconds, - macro) + exp_delta.microseconds) self.assertEqual(c_api_delta, exp_delta) From 48f7e03ede26bc17123b077bb6b6eb1d49bb9f04 Mon Sep 17 00:00:00 2001 From: Edison A <20975616+SimiCode@users.noreply.github.com> Date: Sat, 11 May 2019 16:53:14 -0700 Subject: [PATCH 38/43] Removed the need to initialize macro change all the int macro = 0 to int macro; now that macro is required Co-Authored-By: Paul Ganssle --- Modules/_testcapimodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 03525ba6671cc14..7c41ca3908b0361 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2366,7 +2366,7 @@ static PyObject * get_datetime_fromdateandtime(PyObject *self, PyObject *args) { PyObject *rv = NULL; - int macro = 0; + int macro; int year, month, day; int hour, minute, second, microsecond; From 7e917535077f96744a811528bc030ea853c267a8 Mon Sep 17 00:00:00 2001 From: Edison A <20975616+SimiCode@users.noreply.github.com> Date: Sat, 11 May 2019 16:53:59 -0700 Subject: [PATCH 39/43] Removed the need to initialize macro change all the `int macro = 0` to `int macro`; now that macro is required Co-Authored-By: Paul Ganssle --- Modules/_testcapimodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 7c41ca3908b0361..273d05f4ddad37f 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2396,7 +2396,7 @@ static PyObject * get_datetime_fromdateandtimeandfold(PyObject *self, PyObject *args) { PyObject *rv = NULL; - int macro = 0; + int macro; int year, month, day; int hour, minute, second, microsecond, fold; From 588d95a600068c4144db15a79eea3ea7d4f69035 Mon Sep 17 00:00:00 2001 From: Edison A <20975616+SimiCode@users.noreply.github.com> Date: Sat, 11 May 2019 16:54:42 -0700 Subject: [PATCH 40/43] Removed the need to initialize macro change all the `int macro = 0` to `int macro`; now that macro is required Co-Authored-By: Paul Ganssle --- Modules/_testcapimodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 273d05f4ddad37f..8a84d2f3940357c 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2344,7 +2344,7 @@ static PyObject * get_date_fromdate(PyObject *self, PyObject *args) { PyObject *rv = NULL; - int macro = 0; + int macro; int year, month, day; if (!PyArg_ParseTuple(args, "piii", ¯o, &year, &month, &day)) { From eb3e060b08d59fca65d0fdcfab9cee7d2d4250fa Mon Sep 17 00:00:00 2001 From: Edison A <20975616+SimiCode@users.noreply.github.com> Date: Sat, 11 May 2019 16:55:03 -0700 Subject: [PATCH 41/43] Removed the need to initialize macro change all the `int macro = 0` to `int macro`; now that macro is required Co-Authored-By: Paul Ganssle --- Modules/_testcapimodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 8a84d2f3940357c..606ff314898ebf6 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2454,7 +2454,7 @@ static PyObject * get_time_fromtimeandfold(PyObject *self, PyObject *args) { PyObject *rv = NULL; - int macro = 0; + int macro; int hour, minute, second, microsecond, fold; if (!PyArg_ParseTuple(args, "piiiii", From 1e4db0725201e88204a86d030f1ab9eb53dedf05 Mon Sep 17 00:00:00 2001 From: Edison A <20975616+SimiCode@users.noreply.github.com> Date: Sat, 11 May 2019 16:55:25 -0700 Subject: [PATCH 42/43] Removed the need to initialize macro change all the `int macro = 0` to `int macro`; now that macro is required Co-Authored-By: Paul Ganssle --- Modules/_testcapimodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 606ff314898ebf6..a2d43f992e362d5 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2481,7 +2481,7 @@ static PyObject * get_delta_fromdsu(PyObject *self, PyObject *args) { PyObject *rv = NULL; - int macro = 0; + int macro; int days, seconds, microseconds; if (!PyArg_ParseTuple(args, "piii", From a9c7623e056a3303d4675ae70f57b5db11ddf796 Mon Sep 17 00:00:00 2001 From: Edison A <20975616+SimiCode@users.noreply.github.com> Date: Sat, 11 May 2019 16:55:50 -0700 Subject: [PATCH 43/43] Removed the need to initialize macro change all the `int macro = 0` to `int macro`; now that macro is required Co-Authored-By: Paul Ganssle --- Modules/_testcapimodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index a2d43f992e362d5..b94e9717aa8ad49 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2429,7 +2429,7 @@ static PyObject * get_time_fromtime(PyObject *self, PyObject *args) { PyObject *rv = NULL; - int macro = 0; + int macro; int hour, minute, second, microsecond; if (!PyArg_ParseTuple(args, "piiii",