Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#20514 closed Bug (invalid)

django.contrib.gis.tests.test_measure.{AreaTest,DistanceTest} fail in py3

Reported by: idella4 Owned by: nobody
Component: GIS Version: 1.5
Severity: Normal Keywords: tests
Cc: bmispelon@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

PYTHONPATH=.:../Django-1.5.1-python3_2/lib/:../Django-1.5.1-python3_2/ python tests/runtests.py --settings=test_sqlite -v1

.......ss.sE........E.........ssssssss..................
======================================================================
ERROR: testAccess (django.contrib.gis.tests.test_measure.AreaTest)
Testing access in different units
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/portage/dev-python/django-1.5.1/work/Django-1.5.1/django/contrib/gis/tests/test_measure.py", line 175, in testAccess
    self.assertAlmostEqual(a.sq_ft, 1076.391, 3)
TypeError: assertAlmostEqual() takes exactly 3 positional arguments (4 given)

======================================================================
ERROR: testAccess (django.contrib.gis.tests.test_measure.DistanceTest)
Testing access in different units
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/portage/dev-python/django-1.5.1/work/Django-1.5.1/django/contrib/gis/tests/test_measure.py", line 43, in testAccess
    self.assertAlmostEqual(d.ft, 328.084, 3)
TypeError: assertAlmostEqual() takes exactly 3 positional arguments (4 given)

----------------------------------------------------------------------
Ran 4963 tests in 855.328s

FAILED (errors=2, skipped=175, expected failures=4)

(a.sq_ft, 1076.391, 3)
(d.ft, 328.084, 3)

Well I count 3 positional arguments, py3 counts 4 given.
tilt.
py3 can't count??

Change History (17)

comment:1 by idella4, 12 years ago

comment:2 by Baptiste Mispelon, 12 years ago

Cc: bmispelon@… added
Component: Testing frameworkGIS
Easy pickings: unset
Resolution: needsinfo
Status: newclosed

Hi,

I can't reproduce the issue (using python 3.3 here). I tried running the contrib.gis tests on master, on stable/1.5.x and on the 1.5.1 tag too and they all pass.

I think your setup may be at fault here (this would have been caught by our CI server too). Can you try running the tests in a clean environment? Do you have a strange version of unittest on your path maybe?

I'm marking this as needsinfo for now. Please reopen when you have more info on how to reproduce the issue.

Thanks

PS: The "wrong" argument count comes from the fact that python automatically passes the instance (self) as a first parameter when calling a method.

comment:3 by Simon Charette, 12 years ago

self is the first positional argument here.

comment:4 by Claude Paroz, 12 years ago

Exact Python version might help, too.

comment:5 by Ian Delaney <della5@…>, 12 years ago

it was py3.2.3. Hopefully I just need 3.2.4

comment:6 by Ian Delaney <della5@…>, 12 years ago

I only run tests in a clean environment. An ebuild deletes the source code on each run.

Is PYTHONPATH=. python3.2 tests/runtests.py --settings=test_sqlite -v1 the best or most apt way to run the test suite?

in reply to:  6 comment:7 by Baptiste Mispelon, 12 years ago

Is PYTHONPATH=. python3.2 tests/runtests.py --settings=test_sqlite -v1 the best or most apt way to run the test suite?

That should work, yes. AFAIK, the recommended way is PYTHONPATH=..:$PYTHONPATH python ./runtests.py --settings=test_sqlite (run from the tests directory) [1]

I'll try to get my hands on a 3.2 build to see if I can trigger the issue too.

Have you tried running the full test suite as well?
I checked and assertAlmostEqual is also used in the modeltests tests. Do those fail too?

[1] https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/unit-tests/#quickstart

comment:8 by Ian Delaney <della5@…>, 12 years ago

bmispelon , eeer the full testsuite? I thought I had. What am I missing??

On there-run both py3.2.4 and 3.3.0 failed on them again. So this is from the ebuild simply unpacking the source, cd into it and running the testsuite without any building so if that's not clean I don't know what is. You say that py counts the self so why is the tally then not 4???
I'm running it again from cd into tests and PYTHONPATH=..:$PYTHONPATH python ./runtests.py --settings=test_sqlite which ought be the same.

comment:9 by Ian Delaney <della5@…>, 12 years ago

I'm guessing I've run the whole suite, it takes about 15 minutes, those couple of fails occur right at the end, so I'm guessing any modeltests are run and pass. If there were anything else fail I'd have entered it

comment:10 by Claude Paroz, 12 years ago

Are you really using CPython? Using positional arguments to pass parameters to a method with mixed positional/keyword arguments is explicitely admitted (see http://docs.python.org/3.2/tutorial/controlflow.html#keyword-arguments). And as you are the first to signal this error, something must be special on your side.

See also assertAlmostEqual definition: http://hg.python.org/cpython/file/687295c6c8f2/Lib/unittest/case.py#l527

comment:11 by Ian Delaney <della5@…>, 12 years ago

hmm well this

======================================================================
FAIL: testAccess (django.contrib.gis.tests.test_measure.AreaTest)
Testing access in different units
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/mnt/gen2/TmpDir/portage/dev-python/django-1.5-r1/work/Django-1.5/django/contrib/gis/tests/test_measure.py", line 175, in testAccess
    self.assertAlmostEqual(a.sq_ft, 1076.391)
AssertionError: 1076.391041670972 != 1076.391 within 7 places

======================================================================
FAIL: testAccess (django.contrib.gis.tests.test_measure.DistanceTest)
Testing access in different units
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/mnt/gen2/TmpDir/portage/dev-python/django-1.5-r1/work/Django-1.5/django/contrib/gis/tests/test_measure.py", line 43, in testAccess
    self.assertAlmostEqual(d.ft, 328.084)
AssertionError: 328.0839895013123 != 328.084 within 7 places

----------------------------------------------------------------------

resulted from taking out the last arg (3) out of the two instances of self.assertAlmostEqual.
The 7 default comes into play. The absence of the , 3 indeed took away the <takes exactly 3 positional arguments (4 given)> error.

But why only me? Am I using CPython?. Well I'm not using pypy and I think that only leaves cpython.
I'm re-running it again with what makes sense to me to get it to pass.

self.assertAlmostEqual(a.sq_ft, 1076.391, places=3)

The self I don't know offhand how to exclude without breaking.
The places= being an optional ought be honoured, making for 2 args and 1 optional, no?
My system is just a run o' the mill gentoo python developer system, with all 6 pythons and 3 pypys emerged.

comment:12 by Ian Delaney <della5@…>, 12 years ago


Ran 4963 tests in 883.139s

OK (skipped=177, expected failures=4)
Destroying test database for alias 'default'...

that would be a yes

comment:13 by Ian Delaney <della5@…>, 12 years ago

Has patch: set

diff -ur Django-1.5.orig/django/contrib/gis/tests/test_measure.py Django-1.5/django/contrib/gis/tests/test_measure.py
--- django/contrib/gis/tests/test_measure.py 2013-02-27 03:04:14.000000000 +0800
+++ django/contrib/gis/tests/test_measure.py 2013-05-28 04:40:18.983011224 +0800
@@ -40,7 +40,7 @@

"Testing access in different units"
d = D(m=100)
self.assertEqual(d.km, 0.1)

  • self.assertAlmostEqual(d.ft, 328.084, 3)

+ self.assertAlmostEqual(d.ft, 328.084, places=3)

def testAccessInvalid(self):

"Testing access in invalid units"

@@ -172,7 +172,7 @@

"Testing access in different units"
a = A(sq_m=100)
self.assertEqual(a.sq_km, 0.0001)

  • self.assertAlmostEqual(a.sq_ft, 1076.391, 3)

+ self.assertAlmostEqual(a.sq_ft, 1076.391, places=3)

def testAccessInvaliA(self):

"Testing access in invalid units"

this works for me, hope you find it appliccable

comment:14 by Ian Delaney <della5@…>, 12 years ago

see there

testuser@archtester ~/cvsPortage/gentoo-x86/dev-python/django $ grep AlmostEqual -r /mnt/gen2/TmpDir/portage/dev-python/django-1.5-r1/work/Django-1.5/tests/modeltests/
/mnt/gen2/TmpDir/portage/dev-python/django-1.5-r1/work/Django-1.5/tests/modeltests/aggregation/tests.py:        self.assertAlmostEqual(vals["friends__age__avg"], 34.07, places=2)
/mnt/gen2/TmpDir/portage/dev-python/django-1.5-r1/work/Django-1.5/tests/modeltests/aggregation/tests.py:        self.assertAlmostEqual(vals["authors__age__avg"], 38.2857, places=2)
/mnt/gen2/TmpDir/portage/dev-python/django-1.5-r1/work/Django-1.5/tests/modeltests/aggregation/tests.py:        self.assertAlmostEqual(vals["amazon_mean"], 4.08, places=2)

, places= is used in all 3 instances, and they all passed for me

comment:15 by Ian Delaney <della5@…>, 12 years ago

I'm totally miffed by why yours passes under py3 and mine doesn't. There must be something 'special on my side' logically. Any guesses? I got nothing.
The adding of places= simply makes the code consistent between tests. I won't re-open this since that really needs pinning that special quality, however the patch won't break anything and will make for consistency. I've added the patch to the 1.5 versions in portage.

comment:16 by Claude Paroz, 12 years ago

Resolution: needsinfoinvalid

I think I found the bug: http://bugs.python.org/issue10353

Now the question is for you why you are still affected by this bug fixed some time ago. Either some older Python installation is left somewhere on your system, or a very recent Python commit reinstated this bug. In any case, this is not Django's fault, as self.assertAlmostEqual(a.sq_ft, 1076.391, places=3) or self.assertAlmostEqual(a.sq_ft, 1076.391, 3) are strictly equivalent.

comment:17 by Ian Delaney <della5@…>, 12 years ago

right. well my python installs are recent and current, sp I'd go for something re-instating it. I'll see if some other python devs have some idea. thx

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