summaryrefslogtreecommitdiff
path: root/ext/pybind11/tests/test_chrono.py
diff options
context:
space:
mode:
authorBobby R. Bruce <bbruce@ucdavis.edu>2019-09-23 13:52:58 -0700
committerBobby R. Bruce <bbruce@ucdavis.edu>2019-09-24 21:40:15 +0000
commitf97cf54db7a6f7642cc9fd122f23c4396c39bcf0 (patch)
tree17d2ed22a1114cb138500d46afddb3bafcc2b418 /ext/pybind11/tests/test_chrono.py
parent9235ae56c282d5a02ada3ed9b4e0fe2ee5738bde (diff)
downloadgem5-f97cf54db7a6f7642cc9fd122f23c4396c39bcf0.tar.xz
ext: Updated Pybind11 to version 2.4.1.
This updates Pybind11 from version 2.2.1 to version 2.4.1. This fixes warning/error received when "<experiment/optional>" is used when compiling using c++14 with clang. It should be noted that "ext/pybind11/include/pybind11/std.h" has been changed to include a fix added by commit ba42457254cc362eddc099f22b60d469cc6369e0. This is necessary to avoid build errors. Built: Linux (gcc, c++11) and MacOS (clang, c++14). Tested: Ran quick tests for X86, ARM, and RISC-V. Deprecates: https://gem5-review.googlesource.com/c/public/gem5/+/21019 Change-Id: Ie9783511cb6be50136076a55330e645f4f36d075 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/21119 Reviewed-by: Jason Lowe-Power <jason@lowepower.com> Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com> Maintainer: Jason Lowe-Power <jason@lowepower.com> Maintainer: Andreas Sandberg <andreas.sandberg@arm.com> Tested-by: kokoro <noreply+kokoro@google.com>
Diffstat (limited to 'ext/pybind11/tests/test_chrono.py')
-rw-r--r--ext/pybind11/tests/test_chrono.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/ext/pybind11/tests/test_chrono.py b/ext/pybind11/tests/test_chrono.py
index 2b75bd191..55c954406 100644
--- a/ext/pybind11/tests/test_chrono.py
+++ b/ext/pybind11/tests/test_chrono.py
@@ -40,6 +40,62 @@ def test_chrono_system_clock_roundtrip():
assert diff.microseconds == 0
+def test_chrono_system_clock_roundtrip_date():
+ date1 = datetime.date.today()
+
+ # Roundtrip the time
+ datetime2 = m.test_chrono2(date1)
+ date2 = datetime2.date()
+ time2 = datetime2.time()
+
+ # The returned value should be a datetime
+ assert isinstance(datetime2, datetime.datetime)
+ assert isinstance(date2, datetime.date)
+ assert isinstance(time2, datetime.time)
+
+ # They should be identical (no information lost on roundtrip)
+ diff = abs(date1 - date2)
+ assert diff.days == 0
+ assert diff.seconds == 0
+ assert diff.microseconds == 0
+
+ # Year, Month & Day should be the same after the round trip
+ assert date1.year == date2.year
+ assert date1.month == date2.month
+ assert date1.day == date2.day
+
+ # There should be no time information
+ assert time2.hour == 0
+ assert time2.minute == 0
+ assert time2.second == 0
+ assert time2.microsecond == 0
+
+
+def test_chrono_system_clock_roundtrip_time():
+ time1 = datetime.datetime.today().time()
+
+ # Roundtrip the time
+ datetime2 = m.test_chrono2(time1)
+ date2 = datetime2.date()
+ time2 = datetime2.time()
+
+ # The returned value should be a datetime
+ assert isinstance(datetime2, datetime.datetime)
+ assert isinstance(date2, datetime.date)
+ assert isinstance(time2, datetime.time)
+
+ # Hour, Minute, Second & Microsecond should be the same after the round trip
+ assert time1.hour == time2.hour
+ assert time1.minute == time2.minute
+ assert time1.second == time2.second
+ assert time1.microsecond == time2.microsecond
+
+ # There should be no date information (i.e. date = python base date)
+ assert date2.year == 1970
+ assert date2.month == 1
+ assert date2.day == 1
+
+
def test_chrono_duration_roundtrip():
# Get the difference between two times (a timedelta)
@@ -70,6 +126,19 @@ def test_chrono_duration_subtraction_equivalence():
assert cpp_diff.microseconds == diff.microseconds
+def test_chrono_duration_subtraction_equivalence_date():
+
+ date1 = datetime.date.today()
+ date2 = datetime.date.today()
+
+ diff = date2 - date1
+ cpp_diff = m.test_chrono4(date2, date1)
+
+ assert cpp_diff.days == diff.days
+ assert cpp_diff.seconds == diff.seconds
+ assert cpp_diff.microseconds == diff.microseconds
+
+
def test_chrono_steady_clock():
time1 = m.test_chrono5()
assert isinstance(time1, datetime.timedelta)
@@ -99,3 +168,9 @@ def test_floating_point_duration():
diff = m.test_chrono_float_diff(43.789012, 1.123456)
assert diff.seconds == 42
assert 665556 <= diff.microseconds <= 665557
+
+
+def test_nano_timepoint():
+ time = datetime.datetime.now()
+ time1 = m.test_nano_timepoint(time, datetime.timedelta(seconds=60))
+ assert(time1 == time + datetime.timedelta(seconds=60))