Monday, October 10, 2011

Unicode in unit tests

Hi all,

I try to use a utf8 string in a Django unit test and have included
# -*- coding: utf-8 -*-
but django-admin.py still complaints there is no encoding.

Traceback (most recent call last):
File "/home/basti/work/virtualenv/bin/django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "/home/basti/work/virtualenv/lib/python2.7/site-packages/django/core/management/__init__.py", line 429, in execute_from_command_line
utility.execute()
File "/home/basti/work/virtualenv/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/basti/work/virtualenv/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/basti/work/virtualenv/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/home/basti/work/virtualenv/lib/python2.7/site-packages/south/management/commands/test.py", line 8, in handle
super(Command, self).handle(*args, **kwargs)
File "/home/basti/work/virtualenv/lib/python2.7/site-packages/django/core/management/commands/test.py", line 37, in handle
failures = test_runner.run_tests(test_labels)
File "/home/basti/work/virtualenv/lib/python2.7/site-packages/django/test/simple.py", line 358, in run_tests
suite = self.build_suite(test_labels, extra_tests)
File "/home/basti/work/virtualenv/lib/python2.7/site-packages/django/test/simple.py", line 248, in build_suite
suite.addTest(build_suite(app))
File "/home/basti/work/virtualenv/lib/python2.7/site-packages/django/test/simple.py", line 77, in build_suite
test_module = get_tests(app_module)
File "/home/basti/work/virtualenv/lib/python2.7/site-packages/django/test/simple.py", line 35, in get_tests
test_module = __import__('.'.join(app_path + [TEST_MODULE]), {}, {}, TEST_MODULE)
SyntaxError: Non-ASCII character '\xc3' in file tests.py on line 242, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

The string it's complaining about is also declared as unicode string
using u"" and I've tried to set TEST_CHARSET and TEST_DATABASE_CHARSET
to utf8, but still no luck.
Any hints on how to solve that?
TIA && have a nice day!

Basti
--
Bastian Ballmann / Web Developer
Notch Interactive GmbH / Badenerstrasse 571 / 8048 Zürich
Phone +41 43 818 20 91 / www.notch-interactive.com

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment