[TIP] Testing locale-dependent behaviour

Alexandre Fayolle alexandre.fayolle at logilab.fr
Mon Nov 24 23:53:01 PST 2008


Le Tuesday 25 November 2008 07:42:29 Thomas Lotze, vous avez écrit :
> Is there a best practice how to test locale-dependent code, given that one
> cannot be sure when writing the tests which locales are available on the
> machines that may execute them later? Is there any way to define a locale
> from inside a test environment in order to achieve some specific behavior
> to test for?
>
> As an example, I want to be able to check that a function that calls
> str.upper at some point behaves differently under a locale that knows
> about umlauts than under the C locale, but the tests may get executed on a
> machine that doesn't have any umlaut-aware locales.

Is  it an error (not code-level but deployment level) not to have an 
umlaut-aware locale on the target machine? If so, just fail() if there is no 
such locale. Otherwise, I'd just skip() the test with an explicit message, 
hoping that someone will notice and configure the locales on the test running 
machine. 

From what you describe, the availability of a given set of locales looks like 
a dependency for your test, in the same way that you might have a dependency 
on some third party python modules for your tests to run, or on some external 
software configuration (directory layout, some server listening on a TCP 
port...) : this needs to be documented somewhere, and a nice way of making 
sure the configuration is correct is writing a test for it :-)

-- 
Alexandre Fayolle                              LOGILAB, Paris (France)
Formations Python, Zope, Plone, Debian:  http://www.logilab.fr/formations
Développement logiciel sur mesure:       http://www.logilab.fr/services
Informatique scientifique:               http://www.logilab.fr/science
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 481 bytes
Desc: This is a digitally signed message part.
Url : http://lists.idyll.org/pipermail/testing-in-python/attachments/20081125/c0c55199/attachment.pgp 


More information about the testing-in-python mailing list