On Fri, Oct 2, 2009 at 3:18 AM, gentlestone <tibor.b...@hotmail.com> wrote:

>
> Hello Karen,
>
> another issue. If I'm using unicode characters in model's doctest:
>
>    u"""
>    >>> osoba = Osoba(meno = u"Ľudmila", priezvisko = u"Šafářová")
>    >>> osoba.save()
>    >>> subjekt = Subjekt(nazov = u"Žaba s.r.o.", osoba = osoba)
>    >>> subjekt.save()
>    >>> subjekt = Subjekt.objects.get(id = subjekt.id)
>    >>> subjekt
>    <Subjekt: Žaba s.r.o. - Šafářová Ľudmila>
>    """
> the test ends this way:
>
> ....................................../Library/Python/2.5/site-
> packages/django/test/_doctest.py:1502: UnicodeWarning: Unicode equal
> comparison failed to convert both arguments to Unicode - interpreting
> them as being unequal
>  if got == want:
> /Library/Python/2.5/site-packages/django/test/_doctest.py:1522:
> UnicodeWarning: Unicode equal comparison failed to convert both
> arguments to Unicode - interpreting them as being unequal
>  if got == want:
> /Library/Python/2.5/site-packages/django/test/_doctest.py:299:
> UnicodeWarning: Unicode equal comparison failed to convert both
> arguments to Unicode - interpreting them as being unequal
>  return want == got
> E.
> ======================================================================
> ERROR: Doctest: konres.subjekty.models.Subjekt
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>  File "/Library/Python/2.5/site-packages/django/test/_doctest.py",
> line 2175, in runTest
>    test, out=new.write, clear_globs=False)
>   File "/Library/Python/2.5/site-packages/django/test/_doctest.py",
> line 1403, in run
>    return self.__run(test, compileflags, out)
>   File "/Library/Python/2.5/site-packages/django/test/_doctest.py",
> line 1316, in __run
>    self.report_failure(out, test, example, got)
>   File "/Library/Python/2.5/site-packages/django/test/_doctest.py",
> line 1184, in report_failure
>    self._checker.output_difference(example, got, self.optionflags))
>   File "/Library/Python/2.5/site-packages/django/test/_doctest.py",
> line 1607, in output_difference
>    return 'Expected:\n%sGot:\n%s' % (_indent(want), _indent(got))
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position
> 14: ordinal not in range(128)
>
> Is it possible to use unicode chars in doctests?
>
> Can you help me pls? Doctest is so nice for join documentation and
> test it will be a pitty to leave them out.
>
>
This is similar but not quite the same as the other thread on non-ASCII
chars in doctests.  The workarounds are the same, though: to avoid problems,
don't use unicode literal doctest strings, and don't embed unicode literals
in the doctest strings.   This version works:

   """
   >>> osoba = Osoba(meno = "Ľudmila".decode('utf-8'), priezvisko =
"Šafářová".decode('utf-8'))
   >>> osoba.save()
   >>> subjekt = Subjekt(nazov = "Žaba s.r.o.".decode('utf-8'), osoba =
osoba)
   >>> subjekt.save()
   >>> subjekt = Subjekt.objects.get(id = subjekt.id)
   >>> subjekt
   <Subjekt: Žaba s.r.o. - Šafářová Ľudmila>
   """

Karen

--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to