comparison 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
comparison
equal deleted inserted replaced
6479:808f7a8ed2b6 6480:0f0cee081990
35 skip_pytz = mark_class(pytest.mark.skip(reason="'pytz' not installed")) 35 skip_pytz = mark_class(pytest.mark.skip(reason="'pytz' not installed"))
36 36
37 37
38 class DateTestCase(unittest.TestCase): 38 class DateTestCase(unittest.TestCase):
39 def setUp(self): 39 def setUp(self):
40 # force use of local locale directory. System locale dir
41 # doesn't have the locale files installed, and without wiping
42 # the default the .mo file sometimes isn't found.
43 i18n.LOCALE_DIRS=[]
44 i18n.LOCALE_DIRS.insert(0,"locale/locale")
45
40 self.old_gettext_ = i18n.gettext 46 self.old_gettext_ = i18n.gettext
41 self.old_ngettext_ = i18n.ngettext 47 self.old_ngettext_ = i18n.ngettext
42 i18n.gettext = i18n.get_translation(language='C').gettext 48 i18n.gettext = i18n.get_translation(language='C').gettext
49 i18n.degettext = i18n.get_translation(language='de').gettext
43 i18n.ngettext = i18n.get_translation(language='C').ngettext 50 i18n.ngettext = i18n.get_translation(language='C').ngettext
51 i18n.dengettext = i18n.get_translation(language='de').ngettext
44 52
45 def tearDown(self): 53 def tearDown(self):
46 i18n.gettext = self.old_gettext_ 54 i18n.gettext = self.old_gettext_
47 i18n.ngettext = self.old_ngettext_ 55 i18n.ngettext = self.old_ngettext_
48 56
419 ae('-00:00:30', 'just now') 427 ae('-00:00:30', 'just now')
420 ae('-1d', 'yesterday') 428 ae('-1d', 'yesterday')
421 ae('-1y', '1 year ago') 429 ae('-1y', '1 year ago')
422 ae('-2y', '2 years ago') 430 ae('-2y', '2 years ago')
423 431
432 def testIntervalPrettyDe(self):
433 gettext = i18n.gettext
434 ngettext = i18n.ngettext
435
436 i18n.gettext = i18n.degettext
437 i18n.ngettext = i18n.dengettext
438
439 def ae(spec, pretty):
440 self.assertEqual(Interval(spec).pretty(), pretty)
441 ae('2y', 'in 2 Jahren')
442 ae('1y', 'in 1 Jahr')
443 ae('2m', 'in 2 Monaten')
444 ae('59d', 'in 1 Monat')
445 ae('1m', 'in 1 Monat')
446 '''ae('29d', 'in 1 month')
447 ae('28d', 'in 4 weeks')
448 ae('8d', 'in 1 week')
449 ae('7d', 'in 7 days')
450 ae('1w', 'in 7 days')
451 ae('2d', 'in 2 days')
452 ae('1d', 'tomorrow')
453 ae('02:00:00', 'in 2 hours')
454 ae('01:59:00', 'in 1 3/4 hours')
455 ae('01:45:00', 'in 1 3/4 hours')
456 ae('01:30:00', 'in 1 1/2 hours')
457 ae('01:29:00', 'in 1 1/4 hours')
458 ae('01:00:00', 'in an hour')
459 ae('00:30:00', 'in 1/2 an hour')
460 ae('00:15:00', 'in 1/4 hour')
461 ae('00:02:00', 'in 2 minutes')
462 ae('00:01:00', 'in 1 minute')
463 ae('00:00:30', 'in a moment')
464 ae('-00:00:30', 'just now')
465 ae('-1d', 'yesterday')
466 ae('-1y', '1 year ago')
467 ae('-2y', '2 years ago')'''
468
469 i18n.gettext = gettext
470 i18n.ngettext = ngettext
471
424 def testPyDatetime(self): 472 def testPyDatetime(self):
425 d = datetime.datetime.now() 473 d = datetime.datetime.now()
426 Date(d) 474 Date(d)
427 toomuch = datetime.MAXYEAR + 1 475 toomuch = datetime.MAXYEAR + 1
428 self.assertRaises(ValueError, Date, (toomuch, 1, 1, 0, 0, 0, 0, 1, -1)) 476 self.assertRaises(ValueError, Date, (toomuch, 1, 1, 0, 0, 0, 0, 1, -1))

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