Opened 18 years ago

Closed 18 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: dev
Severity: Keywords:
Cc: adurdin@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

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@…> 18 years ago.
test_client patch for first two errors
test_2.3.patch (2.1 KB ) - added by adurdin@… 18 years ago.
Patch for these three errors (and one more)

Download all attachments as: .zip

Change History (12)

by Robert Myers <myer0052@…>, 18 years ago

Attachment: test_client.patch added

test_client patch for first two errors

comment:1 by Robert Myers <myer0052@…>, 18 years ago

Component: UncategorizedUnit test system
Owner: changed from Jacob to Adrian Holovaty

comment:2 by ramiro <rm0 _at_ gmx.net>, 18 years ago

Robert,

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

comment:3 by anonymous, 18 years ago

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 by Gary Wilson <gary.wilson@…>, 18 years ago

Triage Stage: UnreviewedAccepted

by adurdin@…, 18 years ago

Attachment: test_2.3.patch added

Patch for these three errors (and one more)

comment:5 by adurdin@…, 18 years ago

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 by Robert Myers <myer0052@…>, 18 years ago

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 by Michael Radziej <mir@…>, 18 years ago

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 by adurdin@…, 18 years ago

Cc: adurdin@… added

comment:9 by Jacob, 18 years ago

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

comment:10 by Jacob, 18 years ago

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