diff test/test_dates.py @ 6480:0f0cee081990

Force test of a locale We had a file descriptor leak in the i18n routines. The code that opens a .mo file and then closes it was not tested. Add a test for converting dates to german locale. Make test use the locale/locale subdirectory tree. To do this build the .mo files and put them into the proper tree structure: locale/locale/<two char lang code>/LC_MESSAGES/roundup.mo Also make py.test run with warnings made into errors. Try to get advanced warnings of deprecation issues, resource leaks etc. Ignore error generated by the markdown module that uses the old SelectableGroups interface to dict: DeprecationWarning: SelectableGroups dict interface is deprecated. Use select. Also ignore use of imp module in gpg.gpgme, U mode in docutils.io. Tried to split lines for the py.test run so each warning is on it's own line. Makes it more readable and editing in the future easier. Not sure if it's valid though. May need to revise.
author John Rouillard <rouilj@ieee.org>
date Mon, 06 Sep 2021 13:18:53 -0400
parents d76291836523
children 5be4f9104cf7
line wrap: on
line diff
--- a/test/test_dates.py	Sun Sep 05 23:38:10 2021 -0400
+++ b/test/test_dates.py	Mon Sep 06 13:18:53 2021 -0400
@@ -37,10 +37,18 @@
 
 class DateTestCase(unittest.TestCase):
     def setUp(self):
+        # force use of local locale directory. System locale dir 
+        # doesn't have the locale files installed, and without wiping
+        # the default the .mo file sometimes isn't found.
+        i18n.LOCALE_DIRS=[]
+        i18n.LOCALE_DIRS.insert(0,"locale/locale")
+
         self.old_gettext_ = i18n.gettext
         self.old_ngettext_ = i18n.ngettext
         i18n.gettext = i18n.get_translation(language='C').gettext
+        i18n.degettext = i18n.get_translation(language='de').gettext
         i18n.ngettext = i18n.get_translation(language='C').ngettext
+        i18n.dengettext = i18n.get_translation(language='de').ngettext
 
     def tearDown(self):
         i18n.gettext = self.old_gettext_
@@ -421,6 +429,46 @@
         ae('-1y', '1 year ago')
         ae('-2y', '2 years ago')
 
+    def testIntervalPrettyDe(self):
+        gettext = i18n.gettext
+        ngettext = i18n.ngettext
+
+        i18n.gettext = i18n.degettext
+        i18n.ngettext = i18n.dengettext
+        
+        def ae(spec, pretty):
+            self.assertEqual(Interval(spec).pretty(), pretty)
+        ae('2y', 'in 2 Jahren')
+        ae('1y', 'in 1 Jahr')
+        ae('2m', 'in 2 Monaten')
+        ae('59d', 'in 1 Monat')
+        ae('1m', 'in 1 Monat')
+        '''ae('29d', 'in 1 month')
+        ae('28d', 'in 4 weeks')
+        ae('8d', 'in 1 week')
+        ae('7d', 'in 7 days')
+        ae('1w', 'in 7 days')
+        ae('2d', 'in 2 days')
+        ae('1d', 'tomorrow')
+        ae('02:00:00', 'in 2 hours')
+        ae('01:59:00', 'in 1 3/4 hours')
+        ae('01:45:00', 'in 1 3/4 hours')
+        ae('01:30:00', 'in 1 1/2 hours')
+        ae('01:29:00', 'in 1 1/4 hours')
+        ae('01:00:00', 'in an hour')
+        ae('00:30:00', 'in 1/2 an hour')
+        ae('00:15:00', 'in 1/4 hour')
+        ae('00:02:00', 'in 2 minutes')
+        ae('00:01:00', 'in 1 minute')
+        ae('00:00:30', 'in a moment')
+        ae('-00:00:30', 'just now')
+        ae('-1d', 'yesterday')
+        ae('-1y', '1 year ago')
+        ae('-2y', '2 years ago')'''
+
+        i18n.gettext = gettext
+        i18n.ngettext = ngettext
+
     def testPyDatetime(self):
         d = datetime.datetime.now()
         Date(d)

Roundup Issue Tracker: http://roundup-tracker.org/