Opened 2 years ago

Closed 2 years ago

#18964 closed Bug (fixed)

defaultfilters test passes unexpectedly under Python 3

Reported by: russellm Owned by: aaugustin
Component: Uncategorized Version: master
Severity: Release blocker Keywords: python3
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

defaultfilters.DefaultFiltersTests.test_floatformat_fail is currently marked as an expected failure; and under Python 2, it does fail.

Under Python 3 (at least, with Python 3.2.3 64 bit under OSX), the test passes.

It's entirely possible that the resolution is "don't worry about it" - after all, there are worse problems than an unexpected test pass. However, since it is an oddity in test suite results that may have gone unnoticed (since 'unexpected pass' would be easy to miss in test suite results), I'm marking this as a release blocker.

Change History (4)

comment:1 Changed 2 years ago by russellm

  • Keywords python3 added
  • Version changed from 1.4 to master

comment:2 Changed 2 years ago by aaugustin

  • Owner changed from nobody to aaugustin

comment:3 Changed 2 years ago by aaugustin

The test that unexpectedly passes is:

self.assertEqual(floatformat(1.00000000000000015, 16), '1.0000000000000002')

Under Python 2, it returns '1.0000000000000000'.


The explanation is pretty simple.

The first step of the floatformat template filter is to coerce its input as text, and this step introduces the difference between Python 2 and Python 3.

% python2.6
>>> 1.00000000000000015
1.0000000000000002
>>> str(_)
'1.0'
% python3.2
>>> 1.00000000000000015
1.0000000000000002
>>> str(_)
'1.0000000000000002'

I think it's related to this paragraph of Python 3.1's release notes:

Python now uses David Gay’s algorithm for finding the shortest floating point representation that doesn’t change its value.


Arguably, this is a bug in Python 2 that was fixed in Python 3. I'm going to mark the test as an expected failure only on Python 2.

comment:4 Changed 2 years ago by Aymeric Augustin <aymeric.augustin@…>

  • Resolution set to fixed
  • Status changed from new to closed

In 8d7e526229c27567860f7479dbce15d245742feb:

[1.5.x] Fixed #18964 -- floatformat test passes under py3k

Thanks Russell for the report.

Backport of b4420d9 from master.

Note: See TracTickets for help on using tickets.
Back to Top