with self.subTest(arg=arg, exact=exact):
self.assertFalse(is_tzinfo(arg, exact))
+ def test_date_from_date(self):
+ exp_date = date(1993, 8, 26)
+
+ 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)
+
+ 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(
+ macro,
+ exp_date.year,
+ exp_date.month,
+ exp_date.day,
+ exp_date.hour,
+ exp_date.minute,
+ exp_date.second,
+ exp_date.microsecond)
+
+ self.assertEqual(c_api_date, exp_date)
+
+ def test_datetime_from_dateandtimeandfold(self):
+ 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, fold=fold):
+ c_api_date = _testcapi.get_datetime_fromdateandtimeandfold(
+ macro,
+ exp_date.year,
+ exp_date.month,
+ exp_date.day,
+ exp_date.hour,
+ exp_date.minute,
+ exp_date.second,
+ exp_date.microsecond,
+ exp_date.fold)
+
+ 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)
+
+ 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)
+
+ self.assertEqual(c_api_time, exp_time)
+
+ def test_time_from_timeandfold(self):
+ exp_time = time(22, 12, 55, 99999)
+
+ for fold in [0, 1]:
+ 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)
+
+ 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)
+
+ 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)
+
+ self.assertEqual(c_api_delta, exp_delta)
+
def test_date_from_timestamp(self):
ts = datetime(1995, 4, 12).timestamp()
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),
}
}
+static PyObject *
+get_date_fromdate(PyObject *self, PyObject *args)
+{
+ PyObject *rv = NULL;
+ int macro;
+ int year, month, day;
+
+ if (!PyArg_ParseTuple(args, "piii", ¯o, &year, &month, &day)) {
+ return NULL;
+ }
+
+ if (macro) {
+ rv = PyDate_FromDate(year, month, day);
+ }
+ else {
+ rv = PyDateTimeAPI->Date_FromDate(
+ year, month, day,
+ PyDateTimeAPI->DateType);
+ }
+ return rv;
+}
+
+static PyObject *
+get_datetime_fromdateandtime(PyObject *self, PyObject *args)
+{
+ PyObject *rv = NULL;
+ int macro;
+ int year, month, day;
+ int hour, minute, second, microsecond;
+
+ if (!PyArg_ParseTuple(args, "piiiiiii",
+ ¯o,
+ &year, &month, &day,
+ &hour, &minute, &second, µsecond)) {
+ return NULL;
+ }
+
+ 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_datetime_fromdateandtimeandfold(PyObject *self, PyObject *args)
+{
+ PyObject *rv = NULL;
+ int macro;
+ int year, month, day;
+ int hour, minute, second, microsecond, fold;
+
+ if (!PyArg_ParseTuple(args, "piiiiiiii",
+ ¯o,
+ &year, &month, &day,
+ &hour, &minute, &second, µsecond,
+ &fold)) {
+ return NULL;
+ }
+
+ 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_time_fromtime(PyObject *self, PyObject *args)
+{
+ PyObject *rv = NULL;
+ int macro;
+ int hour, minute, second, microsecond;
+
+ if (!PyArg_ParseTuple(args, "piiii",
+ ¯o,
+ &hour, &minute, &second, µsecond)) {
+ return NULL;
+ }
+
+ 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_time_fromtimeandfold(PyObject *self, PyObject *args)
+{
+ PyObject *rv = NULL;
+ int macro;
+ int hour, minute, second, microsecond, fold;
+
+ if (!PyArg_ParseTuple(args, "piiiii",
+ ¯o,
+ &hour, &minute, &second, µsecond,
+ &fold)) {
+ return NULL;
+ }
+
+ 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_delta_fromdsu(PyObject *self, PyObject *args)
+{
+ PyObject *rv = NULL;
+ int macro;
+ int days, seconds, microseconds;
+
+ if (!PyArg_ParseTuple(args, "piii",
+ ¯o,
+ &days, &seconds, µseconds)) {
+ return NULL;
+ }
+
+ 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)
{
{"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},
+ {"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},
{"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_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_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},