On Wed, 2007-05-09 at 02:22 -0700, akaihola wrote: > I'm having a hard time trying to do my unit testing in unicode. I'm > using the unicode branch of Django. > > Here's a simple tests.py example: > > # -*- encoding: utf-8 -*- > u""" > >>> print u'\u00e4' > this output should not match the above test > """ > > When I run this with manage.py test, I get the following error: > File "/home/ambitone/asiakasprojektit/ostinato/hakuproto/python/ > django/test/doctest.py", line 2156, in runTest > raise self.failureException(self.format_failure(new.getvalue())) > AssertionError: <unprintable AssertionError object> > > If I change line 2156 of django/test/doctest.py to > raise > self.failureException(self.format_failure(new.getvalue()).encode('UTF-8')) > then everything works flawlessly. > > >From what I can tell this problem could be deeper than in Django. > Anyway, it would be nice to have a workaround.
The standard solution for doctests is to never use print in these cases. Rather, just display the string value, which will appear with hex encoding for any non-ASCII characaters. The output is then completely safe from decoding problems. This is what we do throughout the Django internal tests whenever the output is likely to produce non-ASCII characters. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---