summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_time.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2012-02-08 13:31:50 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2012-02-08 13:31:50 (GMT)
commitccd5715a149388eec2f40e5efacac83d3fe357ca (patch)
tree69b6582c3ed63f6527e56ebdc996c99dccbba910 /Lib/test/test_time.py
parent6f91ce74a04e958b2e5b1d1904110739eea66841 (diff)
downloadcpython-ccd5715a149388eec2f40e5efacac83d3fe357ca.zip
cpython-ccd5715a149388eec2f40e5efacac83d3fe357ca.tar.gz
cpython-ccd5715a149388eec2f40e5efacac83d3fe357ca.tar.bz2
PEP 410
Diffstat (limited to 'Lib/test/test_time.py')
-rw-r--r--Lib/test/test_time.py33
1 files changed, 29 insertions, 4 deletions
diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py
index a89c511..52904fa 100644
--- a/Lib/test/test_time.py
+++ b/Lib/test/test_time.py
@@ -1,10 +1,10 @@
+import locale
+import platform
+import sys
+import sysconfig
from test import support
import time
import unittest
-import locale
-import sysconfig
-import sys
-import platform
# Max year is only limited by the size of C int.
SIZEOF_INT = sysconfig.get_config_var('SIZEOF_INT') or 4
@@ -345,6 +345,31 @@ class TimeTestCase(unittest.TestCase):
self.assertGreater(t2, t1)
self.assertAlmostEqual(dt, 0.1, delta=0.2)
+ def test_timestamp(self):
+ import decimal
+ calls = [
+ (time.time,),
+ (time.mktime, time.localtime()),
+ ]
+ if hasattr(time, 'monotonic'):
+ calls.append((time.monotonic,))
+ if hasattr(time, 'wallclock'):
+ calls.append((time.wallclock,))
+ if hasattr(time, 'CLOCK_REALTIME'):
+ if hasattr(time, 'clock_gettime'):
+ calls.append((time.clock_gettime, time.CLOCK_REALTIME))
+ if hasattr(time, 'clock_getres'):
+ calls.append((time.clock_getres, time.CLOCK_REALTIME))
+ for call in calls:
+ func, *args = call
+
+ # test invalid timestamp
+ for invalid in ("int", decimal.Context):
+ self.assertRaises(ValueError, func, *args, timestamp=invalid)
+
+ for type in (int, float, decimal.Decimal):
+ self.assertIsInstance(func(*args, timestamp=type), type)
+
def test_wallclock(self):
t1 = time.wallclock()
t2 = time.wallclock()