Django

Code

Ticket #3396 (closed: fixed)

Opened 2 years ago

Last modified 2 years ago

test_client unittest fails under python 2.3

Reported by: Robert Myers <myer0052@gmail.com> Assigned to: adrian
Milestone: Component: Testing framework
Version: SVN Keywords:
Cc: adurdin@gmail.com Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 1

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

test_client.patch (0.9 kB) - added by Robert Myers <myer0052@gmail.com> on 01/29/07 16:21:13.
test_client patch for first two errors
test_2.3.patch (2.1 kB) - added by adurdin@gmail.com on 01/31/07 14:37:30.
Patch for these three errors (and one more)

Change History

01/29/07 16:21:13 changed by Robert Myers <myer0052@gmail.com>

  • attachment test_client.patch added.

test_client patch for first two errors

01/29/07 16:25:24 changed by Robert Myers <myer0052@gmail.com>

  • owner changed from jacob to adrian.
  • needs_better_patch changed.
  • component changed from Uncategorized to Unit test system.
  • needs_tests changed.
  • needs_docs changed.

01/29/07 16:49:21 changed 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] :)

01/29/07 18:22:23 changed by anonymous

  • needs_better_patch set to 1.
  • has_patch set to 1.

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

01/30/07 09:59:07 changed by Gary Wilson <gary.wilson@gmail.com>

  • stage changed from Unreviewed to Accepted.

01/31/07 14:37:30 changed by adurdin@gmail.com

  • attachment test_2.3.patch added.

Patch for these three errors (and one more)

01/31/07 14:42:21 changed by adurdin@gmail.com

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

01/31/07 15:14:59 changed by Robert Myers <myer0052@gmail.com>

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.

01/31/07 16:17:04 changed by Michael Radziej <mir@noris.de>

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.

02/22/07 18:23:54 changed by adurdin@gmail.com

  • cc set to adurdin@gmail.com.

02/26/07 12:50:56 changed by jacob

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

02/26/07 13:01:09 changed by jacob

  • status changed from new to closed.
  • resolution set to fixed.

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.


Add/Change #3396 (test_client unittest fails under python 2.3)




Change Properties
Action