[Grok-dev] z3c.testsetup versus docfilesuite encoding

Uli Fouquet uli at gnufix.de
Sat Oct 17 07:03:11 EDT 2009


Hi there,

Sorry for the delay. I was on holidays for a few weeks.

Am Mittwoch, den 07.10.2009, 17:40 +0200 schrieb Christian Theune:

> I noticed some annoyances with z3c.testsetup WRT doctest files and encoding:
> 
> - the default encoding is utf-8 and can not be turned to python's system
> default of None because of "or"-ing the optional parameter.

You could do::

  import sys
  testsuite = z3c.testsetup.register_all_tests(
    'mymod', encoding=sys.getdefaultencoding())
                                               

> - the encoding is only applied to functional docfile suites, but not the
> ones that are unit tests

I think that should be fixed with the latest release.

> - can the default please be the same as Python?

My experience is that most people that worry about encodings use
'utf-8'. And they often expect 'utf-8' to be handled out-of-the-box.
Getting back to Python default encoding would most probably break many
tests and could confuse beginners (I see, that there are still many more
encoding-related problems with testrunners and doctests).

As Python in general is moving towards complete 'utf-8-defaultness', I
don't see the point here. Maybe you want to explain your usecase?

> Why does one care about that encoding anyway?

Uh? For example to handle umlauts. A usecase quite common in
internationalized apps. With the encoding set to 'utf-8' you can do

  >>> myvar = u'ö'
  >>> myvar
  u'\xf6'

which is not nice, but gives at least a bit of encoding support (for
example ``print myvar`` would not work, as the doctest output parser
seems still to expect the Python default encoding). Without setting the
encoding this doctest would not be accepted by the testrunner at all
(except you set the Python default encoding to 'utf-8') and leave
beginners with a cryptic error message not really related to their
testcase.

As all this is not news to you, I wonder whether I missed your point. Is
there a better way to handle encoded strings in doctests?

Best regards,

-- 
Uli

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://mail.zope.org/pipermail/grok-dev/attachments/20091017/692ab3d0/attachment.bin 


More information about the Grok-dev mailing list