Fix test errors on OSX

On OSX, if LC_TIME and LC_CTYPE differs the output of strftime is not properly decoded
in Python 3. This makes sure that the 'utils.DateFormatter' and the related Jinja filter
'strftime' set the same value for LC_TIME and LC_CTYPE while formatting.

Also, '%a' is removed from DEFAULT_DATE_FORMAT in 'custom_locale' tests. OSX and *nix have
different conversions for '%a' ('Jeu' vs 'jeu.') and there is not a feasible way to handle
the difference for tests.
This commit is contained in:
Deniz Turgut 2014-06-26 00:51:45 -04:00
commit 009543b7e4
33 changed files with 137 additions and 130 deletions

View file

@ -94,12 +94,18 @@ class DateFormatter(object):
self.locale = locale.setlocale(locale.LC_TIME)
def __call__(self, date, date_format):
old_locale = locale.setlocale(locale.LC_TIME)
old_lc_time = locale.setlocale(locale.LC_TIME)
old_lc_ctype = locale.setlocale(locale.LC_CTYPE)
locale.setlocale(locale.LC_TIME, self.locale)
# on OSX, encoding from LC_CTYPE determines the unicode output in PY3
# make sure it's same as LC_TIME
locale.setlocale(locale.LC_CTYPE, self.locale)
formatted = strftime(date, date_format)
locale.setlocale(locale.LC_TIME, old_locale)
locale.setlocale(locale.LC_TIME, old_lc_time)
locale.setlocale(locale.LC_CTYPE, old_lc_ctype)
return formatted