summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2010-05-09 09:30:06 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2010-05-09 09:30:06 (GMT)
commit7000e9e01bb784dfc23a70a9d736613ae83c8dad (patch)
tree993dfea355ae52e05bf1d81ad01dd16790869f3b /Lib
parent860852fdf434cb566ace9879ba2a6be0e2569765 (diff)
downloadcpython-7000e9e01bb784dfc23a70a9d736613ae83c8dad.zip
cpython-7000e9e01bb784dfc23a70a9d736613ae83c8dad.tar.gz
cpython-7000e9e01bb784dfc23a70a9d736613ae83c8dad.tar.bz2
Issue #8644: Improve accuracy of timedelta.total_seconds method.
(Backport of r80979 to py3k.) Thanks Alexander Belopolsky.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_datetime.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/test/test_datetime.py b/Lib/test/test_datetime.py
index 52387a0..4715ce1 100644
--- a/Lib/test/test_datetime.py
+++ b/Lib/test/test_datetime.py
@@ -2,7 +2,7 @@
See http://www.zope.org/Members/fdrake/DateTimeWiki/TestCases
"""
-
+from __future__ import division
import os
import pickle
import cPickle
@@ -269,6 +269,13 @@ class TestTimeDelta(HarmlessMixedComparison, unittest.TestCase):
for total_seconds in [123456.789012, -123456.789012, 0.123456, 0, 1e6]:
td = timedelta(seconds=total_seconds)
self.assertEqual(td.total_seconds(), total_seconds)
+ # Issue8644: Test that td.total_seconds() has the same
+ # accuracy as td / timedelta(seconds=1).
+ for ms in [-1, -2, -123]:
+ td = timedelta(microseconds=ms)
+ self.assertEqual(td.total_seconds(),
+ ((24*3600*td.days + td.seconds)*10**6
+ + td.microseconds)/10**6)
def test_carries(self):
t1 = timedelta(days=100,