summaryrefslogtreecommitdiff
path: root/Lib/test/datetimetester.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-09-08 23:58:54 +0200
committerVictor Stinner <victor.stinner@gmail.com>2015-09-08 23:58:54 +0200
commitbbd2c26bb917642217efd84fc4a3dd0b3e0f0a20 (patch)
treee7d9a410401f1879038e0251264e031013640d68 /Lib/test/datetimetester.py
parentf3df521008df3c72db7d804a5c576674a7c3d678 (diff)
downloadcpython-bbd2c26bb917642217efd84fc4a3dd0b3e0f0a20.tar.gz
Revert change 0eb8c182131e:
"""Issue #23517: datetime.timedelta constructor now rounds microseconds to nearest with ties going away from zero (ROUND_HALF_UP), as Python 2 and Python older than 3.3, instead of rounding to nearest with ties going to nearest even integer (ROUND_HALF_EVEN).""" datetime.timedelta uses rounding mode ROUND_HALF_EVEN again.
Diffstat (limited to 'Lib/test/datetimetester.py')
-rw-r--r--Lib/test/datetimetester.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py
index f23add35db..d87b106cff 100644
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -663,14 +663,16 @@ class TestTimeDelta(HarmlessMixedComparison, unittest.TestCase):
# Single-field rounding.
eq(td(milliseconds=0.4/1000), td(0)) # rounds to 0
eq(td(milliseconds=-0.4/1000), td(0)) # rounds to 0
- eq(td(milliseconds=0.5/1000), td(microseconds=1))
- eq(td(milliseconds=-0.5/1000), td(microseconds=-1))
+ eq(td(milliseconds=0.5/1000), td(microseconds=0))
+ eq(td(milliseconds=-0.5/1000), td(microseconds=-0))
eq(td(milliseconds=0.6/1000), td(microseconds=1))
eq(td(milliseconds=-0.6/1000), td(microseconds=-1))
- eq(td(seconds=0.5/10**6), td(microseconds=1))
- eq(td(seconds=-0.5/10**6), td(microseconds=-1))
- eq(td(seconds=1/2**7), td(microseconds=7813))
- eq(td(seconds=-1/2**7), td(microseconds=-7813))
+ eq(td(milliseconds=1.5/1000), td(microseconds=2))
+ eq(td(milliseconds=-1.5/1000), td(microseconds=-2))
+ eq(td(seconds=0.5/10**6), td(microseconds=0))
+ eq(td(seconds=-0.5/10**6), td(microseconds=-0))
+ eq(td(seconds=1/2**7), td(microseconds=7812))
+ eq(td(seconds=-1/2**7), td(microseconds=-7812))
# Rounding due to contributions from more than one field.
us_per_hour = 3600e6
@@ -683,6 +685,10 @@ class TestTimeDelta(HarmlessMixedComparison, unittest.TestCase):
eq(td(hours=-.2/us_per_hour), td(0))
eq(td(days=-.4/us_per_day, hours=-.2/us_per_hour), td(microseconds=-1))
+ # Test for a patch in Issue 8860
+ eq(td(microseconds=0.5), 0.5*td(microseconds=1.0))
+ eq(td(microseconds=0.5)//td.resolution, 0.5*td.resolution//td.resolution)
+
def test_massive_normalization(self):
td = timedelta(microseconds=-1)
self.assertEqual((td.days, td.seconds, td.microseconds),