[IMP] attempt (again) to fix testing of datetime pattern conversions tests
In order to ensure that the conversion is at least sensible, we test the output of strftime and babel on the same pattern (after conversion from POSIX to LDML for Babel). This requires that both use the same locale. Previously, the default locale was being used(-ish), but it turns out when the locale is unset (getdefaultlocale() returns (None, None) ``strftime`` still manages to use some sort of default locale (C?), whereas Babel will yield the locale None. It turns out the runbot executes the server with no locale-related envvar set, and thus hits this very issue. Assume there are no concurrent tests being run and use setlocale to try and ensure strftime and babel see the same locale. Also, remove tests on %x and %X, turns out libc and babel generally have very different ideas about what constitutes a "national representation" of a date or time, so the patterns don't match in the first place. And I found no way to expand %x/%X into its sub-patterns. bzr revid: xmo@openerp.com-20140108162817-n5gd2oryaszf099k
This commit is contained in:
parent
6aa79d8cb3
commit
23b8f160d3
|
@ -41,14 +41,29 @@ class test_countingstream(unittest2.TestCase):
|
|||
self.assertEqual(s.index, 0)
|
||||
|
||||
class TestPosixToBabel(unittest2.TestCase):
|
||||
"""
|
||||
Attempts to compare the output of formatting a specific date using various
|
||||
patterns under strftime and babel. As a result, they need to use the same
|
||||
locale.
|
||||
"""
|
||||
def setUp(self):
|
||||
super(TestPosixToBabel, self).setUp()
|
||||
self.d = datetime.datetime(2007, 9, 8, 4, 5, 1)
|
||||
# use a somewhat non-standard locale
|
||||
self.test_locale = 'tr_TR'
|
||||
locale.setlocale(locale.LC_ALL, self.test_locale)
|
||||
locale.setlocale(locale.LC_TIME, self.test_locale)
|
||||
self.d = datetime.datetime(2007, 9, 7, 4, 5, 1)
|
||||
|
||||
def tearDown(self):
|
||||
super(TestPosixToBabel, self).tearDown()
|
||||
(code, encoding) = locale.getdefaultlocale()
|
||||
locale.setlocale(locale.LC_TIME, code)
|
||||
locale.setlocale(locale.LC_ALL, code)
|
||||
|
||||
def assert_eq(self, fmt, d=None):
|
||||
if d is None: d = self.d
|
||||
|
||||
locale = babel.Locale.default('LC_TIME')
|
||||
locale = babel.Locale(self.test_locale)
|
||||
ldml_format = misc.posix_to_ldml(fmt, locale=locale)
|
||||
self.assertEqual(
|
||||
d.strftime(fmt),
|
||||
|
@ -69,11 +84,7 @@ class TestPosixToBabel(unittest2.TestCase):
|
|||
def test_escape(self):
|
||||
self.assert_eq("%%m:%m %%d:%d %%y:%y")
|
||||
|
||||
def test_xX(self):
|
||||
self.assert_eq('%x %X')
|
||||
|
||||
def test_various_examples(self):
|
||||
self.assert_eq("%x - %I:%M%p")
|
||||
self.assert_eq('%Y-%m-%dT%H:%M:%S')
|
||||
self.assert_eq("%Y-%j")
|
||||
self.assert_eq("%a, %d %b %Y %H:%M:%S")
|
||||
|
|
Loading…
Reference in New Issue