summaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_os.py17
-rw-r--r--Lib/test/test_time.py24
2 files changed, 40 insertions, 1 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index eb73af51ac..4d57bfbf9a 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -3549,6 +3549,23 @@ class TestPEP519(unittest.TestCase):
self.assertRaises(ZeroDivisionError, self.fspath,
_PathLike(ZeroDivisionError()))
+
+class TimesTests(unittest.TestCase):
+ def test_times(self):
+ times = os.times()
+ self.assertIsInstance(times, os.times_result)
+
+ for field in ('user', 'system', 'children_user', 'children_system',
+ 'elapsed'):
+ value = getattr(times, field)
+ self.assertIsInstance(value, float)
+
+ if os.name == 'nt':
+ self.assertEqual(times.children_user, 0)
+ self.assertEqual(times.children_system, 0)
+ self.assertEqual(times.elapsed, 0)
+
+
# Only test if the C version is provided, otherwise TestPEP519 already tested
# the pure Python implementation.
if hasattr(os, "_fspath"):
diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py
index a08fd1822b..b44646da70 100644
--- a/Lib/test/test_time.py
+++ b/Lib/test/test_time.py
@@ -64,6 +64,27 @@ class TimeTestCase(unittest.TestCase):
self.assertFalse(info.monotonic)
self.assertTrue(info.adjustable)
+ def test_time_ns_type(self):
+ def check_ns(sec, ns):
+ self.assertIsInstance(ns, int)
+
+ sec_ns = int(sec * 1e9)
+ # tolerate a difference of 50 ms
+ self.assertLess((sec_ns - ns), 50 ** 6, (sec, ns))
+
+ check_ns(time.time(),
+ time.time_ns())
+ check_ns(time.monotonic(),
+ time.monotonic_ns())
+ check_ns(time.perf_counter(),
+ time.perf_counter_ns())
+ check_ns(time.process_time(),
+ time.process_time_ns())
+
+ if hasattr(time, 'clock_gettime'):
+ check_ns(time.clock_gettime(time.CLOCK_REALTIME),
+ time.clock_gettime_ns(time.CLOCK_REALTIME))
+
def test_clock(self):
with self.assertWarns(DeprecationWarning):
time.clock()
@@ -76,7 +97,8 @@ class TimeTestCase(unittest.TestCase):
@unittest.skipUnless(hasattr(time, 'clock_gettime'),
'need time.clock_gettime()')
def test_clock_realtime(self):
- time.clock_gettime(time.CLOCK_REALTIME)
+ t = time.clock_gettime(time.CLOCK_REALTIME)
+ self.assertIsInstance(t, float)
@unittest.skipUnless(hasattr(time, 'clock_gettime'),
'need time.clock_gettime()')