On Fri, 2007-10-26 at 12:30 -0700, mamcxyz wrote:
> I'm in the process to relaunch a django site. I build a dozen test
> (finally!) for it and work correctly before.
> 
> I update django to changeset 6601 and get a lot of errors. I fix
> almost all of them except this:
> 
>     self.assertContains(self.response,u'Buscar:')
>   File "D:\Programacion\Python\Python24\lib\site-packages\django\test
> \testcases.py", line 111, in assertContains
>     real_count = response.content.count(text)
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
> 162: ordinal not in range(128)

I suspect the problem is the use of .count() here and mixing Unicode and
str objects. You don't mention what the type of 'text' (Jeremy asked
about that, but I didn't see an answer in your reply), but if you do
this in Python:

        >>> s = u'\xc5ngstr\xf6m'
        >>> s.count('\xc3\x85')

you will get a UnicodeDecodeError because the Python doesn't know the
encoding of the bytestring in the argument to count() but it needs to
convert it to Unicode to compare with the unicode object on the left. So
Python assumes ASCII and everything goes to water.

The solution is probably to do something like this in your test:

        real_count = response.content.count(smart_unicode(text))
        
Basically, make sure that both arguments to count are of the same type
(bytestrings encoded with the same encoding, or both unicode objects).

Regards,
Malcolm

-- 
For every action there is an equal and opposite criticism. 
http://www.pointy-stick.com/blog/


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to