Opened 10 years ago

Closed 10 years ago

#3396 closed (fixed)

test_client unittest fails under python 2.3

Reported by: Robert Myers <myer0052@…> Owned by: Adrian Holovaty
Component: Testing framework Version: master
Severity: Keywords:
Cc: adurdin@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: UI/UX:

Description

Running the Unittests for Django the following errors occur.

$python runtests.py --settings=testdj.settings
======================================================================
ERROR: Request a page that is protected with @login, but use bad credentials
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/www/local/django/tests/modeltests/test_client/models.py", line 101, in test_view_with_bad_login
    self.assertFalse(response)
AttributeError: 'ClientTest' object has no attribute 'assertFalse'

======================================================================
ERROR: Request a page that is protected with @login_required
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/www/local/django/tests/modeltests/test_client/models.py", line 92, in test_view_with_login
    self.assertTrue(response)
AttributeError: 'ClientTest' object has no attribute 'assertTrue'

======================================================================
FAIL: POST an empty dictionary to a view
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/www/local/django/tests/modeltests/test_client/models.py", line 53, in test_empty_post
    self.assertEqual(response.status_code, 200)
  File "/usr/lib/python2.3/unittest.py", line 302, in failUnlessEqual
    raise self.failureException, \
AssertionError: 500 != 200

----------------------------------------------------------------------
Ran 68 tests in 6.298s

FAILED (failures=1, errors=2)

Attachments (2)

test_client.patch (945 bytes) - added by Robert Myers <myer0052@…> 10 years ago.
test_client patch for first two errors
test_2.3.patch (2.1 KB) - added by adurdin@… 10 years ago.
Patch for these three errors (and one more)

Download all attachments as: .zip

Change History (12)

Changed 10 years ago by Robert Myers <myer0052@…>

Attachment: test_client.patch added

test_client patch for first two errors

comment:1 Changed 10 years ago by Robert Myers <myer0052@…>

Component: UncategorizedUnit test system
Needs documentation: unset
Needs tests: unset
Owner: changed from Jacob to Adrian Holovaty
Patch needs improvement: unset

comment:2 Changed 10 years ago by ramiro <rm0 _at_ gmx.net>

Robert,

It seems Jacob managed to solve this even before you had the chance of filing the ticket. See [4451] :)

comment:3 Changed 10 years ago by anonymous

Has patch: set
Patch needs improvement: set

Actually [4451] fixed one issue with decorator syntax, but there still are 3 unresolved errors. Two are fixed with the patch I attached but one is still unresolved.

see http://groups.google.com/group/django-developers/browse_thread/thread/bb93449d28c2e24

comment:4 Changed 10 years ago by Gary Wilson <gary.wilson@…>

Triage Stage: UnreviewedAccepted

Changed 10 years ago by adurdin@…

Attachment: test_2.3.patch added

Patch for these three errors (and one more)

comment:5 Changed 10 years ago by adurdin@…

The fourth error that I was experiencing when running the tests under 2.3 was:

======================================================================
ERROR: Doctest: regressiontests.forms.tests
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/andy/Projects/django-trunk-base/django/test/doctest.py", line 2150, in runTest
    failures, tries = runner.run(
  File "/Users/andy/Projects/django-trunk-base/django/test/doctest.py", line 1379, in run
    return self.__run(test, compileflags, out)
  File "/Users/andy/Projects/django-trunk-base/django/test/doctest.py", line 1267, in __run
    got += _exception_traceback(exc_info)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 259: ordinal not in range(128)

The failure is in the last test for RadioSelectWidget. I was testing with the following settings:

DEBUG = True

DATABASE_ENGINE = 'mysql'           # 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'.
DATABASE_NAME = 'test'             # Or path to database file if using sqlite3.
DATABASE_USER = 'root'             # Not used with sqlite3.
DATABASE_PASSWORD = ''         # Not used with sqlite3.
DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.

ROOT_URLCONF = None

SITE_ID = 1

comment:6 Changed 10 years ago by Robert Myers <myer0052@…>

That error is a config issue, in python 2.3 the default encoding is 'ascii'

edit your /usr/lib/python2.3/site.py or where ever you python lib lives and change this line

-encoding = "ascii" # Default value set by _PyUnicode_Init()
+encoding = "UTF-8" # Default value set by _PyUnicode_Init()

That will fix the unicode error you are seeing.

comment:7 Changed 10 years ago by Michael Radziej <mir@…>

Without looking into the details, but python's default encoding in version 2.4 is ASCII, and the idea of using a default encoding at all has basically been given up. The interface to set the default encoding in python is not only depracated but carefully hidden. It's only still there for experiments.

comment:8 Changed 10 years ago by adurdin@…

Cc: adurdin@… added

comment:9 Changed 10 years ago by Jacob

(In [4614]) Fixed a few Python2.3-related bugs in the tests (see #3396). A few more left, though.

comment:10 Changed 10 years ago by Jacob

Resolution: fixed
Status: newclosed

All but the last one -- related to newforms tests and unicode -- are fixed. I'm going to open a new ticket for the last failure to keep it separate from this one.

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