Skip to content

Commit

Permalink
Use true division on Python 2 to match Python 3
Browse files Browse the repository at this point in the history
In case certain parameters turn out to be integers instead of floating
point values. This is not expected to be user-visible, but it can
arise in artificial tests of internal functions.

Refs #4.
  • Loading branch information
jamadden committed Aug 9, 2017
1 parent f988d00 commit 488cde4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Expand Up @@ -5,6 +5,11 @@
4.2.0 (unreleased)
==================

- Use true division on Python 2 to match Python 3, in case certain
parameters turn out to be integers instead of floating point values.
This is not expected to be user-visible, but it can arise in
artificial tests of internal functions.

- Add support for Python 3.5 and 3.6.

- Drop support for Python 2.6, 3.2 and 3.3.
Expand Down
2 changes: 2 additions & 0 deletions src/zope/datetime/__init__.py
Expand Up @@ -15,6 +15,8 @@
Encapsulation of date/time values
"""
from __future__ import division # We do lots of math, make sure it's consistent

import math
import re
# there is a method definition that makes just "time"
Expand Down
8 changes: 3 additions & 5 deletions src/zope/datetime/tests/test_datetime.py
Expand Up @@ -28,7 +28,6 @@ def test_error(self):
class TestFuncs(unittest.TestCase):

def test_correctYear(self):

self.assertEqual(2069, datetime._correctYear(69))
self.assertEqual(1998, datetime._correctYear(98))

Expand Down Expand Up @@ -69,10 +68,9 @@ def test_julianday(self):
self.assertEqual(datetime._julianday(0, 1, 1), 1721057)

def test_calendarday(self):
# XXX: Why do we get different things on Py2 vs Py3?
# Are the calculations wrapping around somewhere? Is it the integer
# division?
answer = (-4712, 1, 3) if str is bytes else (-4711, 2, 0)
# If we don't have the future import of division, we get
# different results on Py2/Py3 when we pass an integer.
answer = (-4711, 2, 0)
self.assertEqual(datetime._calendarday(1), answer)

def test_findLocalTimeZoneName(self):
Expand Down

0 comments on commit 488cde4

Please sign in to comment.