bpo-36782: Created C API wrappers and added missing tests for functions in the PyDateTimeAPI. (#13088)
* created a c API wrapper for pyDate_FromDate and added the test
* 📜🤖 Added by blurb_it.
* fixed auto-alignment by vscode
* made changes as per PEP7
* Update 2019-05-04-21-25-19.bpo-36782.h3oPIb.rst
* Refactored code as per requested changes
* Remove Whitespace to Fix failed travis build
* Update 2019-05-04-21-25-19.bpo-36782.h3oPIb.rst
* Add a new line at end of ACKS
* Added C API function for PyDateTime_FromDateAndTime
* Added a test for the C API wrapper of PyDateTime_FromDateAndTime
* Added C API function for PyDateTime_FromDateAndTime
* Added a test for the C API wrapper of PyDateTime_FromDateAndTimeAndFold
* Remove Whitespace using patchcheck
* Added a C API function for PyTime_FromTime
* Added a test for the C API wrapper of PyTime_FromTime
* Added a C API function for PyTime_FromTimeAndFold
* Added a test for the C API wrapper of PyTime_FromTimeAndFold
* Added a C API function for PyDelta_FromDSU
* Added a test for the C API wrapper of PyDelta_FromDSU
* Refactor code, re-edit lines longer than 80 chars
* Fix Whitespace issues in DatetimeTester
* List all tests that were added in this PR
* Update 2019-05-04-21-25-19.bpo-36782.h3oPIb.rst
* Reformat code as per PEP7 guidelines
* Remove unused varibles from another function
* Added specific tests for the Fold Attribute
* Update 2019-05-04-21-25-19.bpo-36782.h3oPIb.rst
* Reformat code according to requested changes
* Reformat code to PEP7 Guidelines
* Reformat code to PEP7 Guidelines
* Re-add name to blurb
* Added a backtick to blurb file
* Update 2019-05-04-21-25-19.bpo-36782.h3oPIb.rst
* Remove the need to initialize mandatory parameters
* Make the macro parameter mandatory
* Re-arrange the order of unit-test args
* 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 <pganssle@users.noreply.github.com>
* 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 <pganssle@users.noreply.github.com>
* 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 <pganssle@users.noreply.github.com>
* 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 <pganssle@users.noreply.github.com>
* 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 <pganssle@users.noreply.github.com>
* 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 <pganssle@users.noreply.github.com>
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py
index af0047f..239a0b5 100644
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -6018,6 +6018,100 @@
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()
@@ -6028,9 +6122,6 @@
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),