summaryrefslogtreecommitdiff
path: root/ext/pybind11/tests/test_chrono.py
diff options
context:
space:
mode:
authorAndreas Sandberg <andreas.sandberg@arm.com>2017-02-27 13:17:51 +0000
committerAndreas Sandberg <andreas.sandberg@arm.com>2017-05-02 12:37:32 +0000
commitc79706ff4ce591df2151db5504d3c224f3c9965f (patch)
treeb56cd2bfe704a40575a71075e78194a4c516c98d /ext/pybind11/tests/test_chrono.py
parent359cb08623324b62d7c34973ae54d5bc7f23f9fd (diff)
downloadgem5-c79706ff4ce591df2151db5504d3c224f3c9965f.tar.xz
ext: Add pybind rev f4b81b3
Change-Id: I52e4fc9ebf2f59da57d8cf8f3e37cc79598c2f5f Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com> Reviewed-by: Andreas Hansson <andreas.hansson@arm.com> Reviewed-by: Curtis Dunham <curtis.dunham@arm.com> Reviewed-on: https://gem5-review.googlesource.com/2229 Reviewed-by: Tony Gutierrez <anthony.gutierrez@amd.com> Reviewed-by: Jason Lowe-Power <jason@lowepower.com> Reviewed-by: Pierre-Yves PĂ©neau <pierre-yves.peneau@lirmm.fr>
Diffstat (limited to 'ext/pybind11/tests/test_chrono.py')
-rw-r--r--ext/pybind11/tests/test_chrono.py116
1 files changed, 116 insertions, 0 deletions
diff --git a/ext/pybind11/tests/test_chrono.py b/ext/pybind11/tests/test_chrono.py
new file mode 100644
index 000000000..94ca55c76
--- /dev/null
+++ b/ext/pybind11/tests/test_chrono.py
@@ -0,0 +1,116 @@
+
+
+def test_chrono_system_clock():
+ from pybind11_tests import test_chrono1
+ import datetime
+
+ # Get the time from both c++ and datetime
+ date1 = test_chrono1()
+ date2 = datetime.datetime.today()
+
+ # The returned value should be a datetime
+ assert isinstance(date1, datetime.datetime)
+
+ # The numbers should vary by a very small amount (time it took to execute)
+ diff = abs(date1 - date2)
+
+ # There should never be a days/seconds difference
+ assert diff.days == 0
+ assert diff.seconds == 0
+
+ # We test that no more than about 0.5 seconds passes here
+ # This makes sure that the dates created are very close to the same
+ # but if the testing system is incredibly overloaded this should still pass
+ assert diff.microseconds < 500000
+
+
+def test_chrono_system_clock_roundtrip():
+ from pybind11_tests import test_chrono2
+ import datetime
+
+ date1 = datetime.datetime.today()
+
+ # Roundtrip the time
+ date2 = test_chrono2(date1)
+
+ # The returned value should be a datetime
+ assert isinstance(date2, datetime.datetime)
+
+ # 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
+
+
+def test_chrono_duration_roundtrip():
+ from pybind11_tests import test_chrono3
+ import datetime
+
+ # Get the difference between two times (a timedelta)
+ date1 = datetime.datetime.today()
+ date2 = datetime.datetime.today()
+ diff = date2 - date1
+
+ # Make sure this is a timedelta
+ assert isinstance(diff, datetime.timedelta)
+
+ cpp_diff = test_chrono3(diff)
+
+ assert cpp_diff.days == diff.days
+ assert cpp_diff.seconds == diff.seconds
+ assert cpp_diff.microseconds == diff.microseconds
+
+
+def test_chrono_duration_subtraction_equivalence():
+ from pybind11_tests import test_chrono4
+ import datetime
+
+ date1 = datetime.datetime.today()
+ date2 = datetime.datetime.today()
+
+ diff = date2 - date1
+ cpp_diff = 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():
+ from pybind11_tests import test_chrono5
+ import datetime
+
+ time1 = test_chrono5()
+ time2 = test_chrono5()
+
+ assert isinstance(time1, datetime.timedelta)
+ assert isinstance(time2, datetime.timedelta)
+
+
+def test_chrono_steady_clock_roundtrip():
+ from pybind11_tests import test_chrono6
+ import datetime
+
+ time1 = datetime.timedelta(days=10, seconds=10, microseconds=100)
+ time2 = test_chrono6(time1)
+
+ assert isinstance(time2, datetime.timedelta)
+
+ # They should be identical (no information lost on roundtrip)
+ assert time1.days == time2.days
+ assert time1.seconds == time2.seconds
+ assert time1.microseconds == time2.microseconds
+
+
+def test_floating_point_duration():
+ from pybind11_tests import test_chrono7
+ import datetime
+
+ # Test using 35.525123 seconds as an example floating point number in seconds
+ time = test_chrono7(35.525123)
+
+ assert isinstance(time, datetime.timedelta)
+
+ assert time.seconds == 35
+ assert 525122 <= time.microseconds <= 525123