Skip to content

Commit b567dab

Browse files
committed
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.
1 parent 79215a3 commit b567dab

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

.travis.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,20 @@ before_script:
137137
# needed for test_mysql.mysqlDBTest.testFilteringSpecialChars
138138
- sed -i 's/CREATE DATABASE \%s/CREATE DATABASE \%s COLLATE utf8_general_ci/' roundup/backends/back_mysql.py
139139

140+
# build the .mo translation files and install them into a tree
141+
# (locale/locale under roundup directory root)
142+
# suitable for use by gettext.
143+
- (cd locale; make local_install; ls -lR locale)
144+
140145
script:
141146
- PATH=$VIRTUAL_ENV/bin:$PATH
142147
- export LD_LIBRARY_PATH=$VIRTUAL_ENV/lib:$LD_LIBRARY_PATH
143-
- py.test -v --maxfail=20 test/ --cov=roundup
148+
- py.test \
149+
-W error \
150+
-W "ignore::SelectableGroups" \
151+
-W "ignore:the imp module:DeprecationWarning:gpg.gpgme:15" \
152+
-W "ignore:'U' mode::docutils.io" \
153+
-v --maxfail=20 test/ --cov=roundup
144154

145155

146156
after_success:

locale/GNUmakefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ template:
5050
--copyright-holder="See Roundup README.txt" \
5151
-o $(TEMPLATE) $(SOURCES)
5252

53+
local_install: dist
54+
for file in $(MO_FILES); do \
55+
set -xv; lang=`basename $$file .mo`; \
56+
mkdir -p locale/$$lang/LC_MESSAGES; \
57+
cp $$file locale/$$lang/LC_MESSAGES/roundup.mo; \
58+
done
59+
5360
# helps to check template file before check in
5461
diff:
5562
svn diff roundup.pot|grep -v '^[-+]#'|vim -Rv -

test/test_dates.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,18 @@
3737

3838
class DateTestCase(unittest.TestCase):
3939
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+
4046
self.old_gettext_ = i18n.gettext
4147
self.old_ngettext_ = i18n.ngettext
4248
i18n.gettext = i18n.get_translation(language='C').gettext
49+
i18n.degettext = i18n.get_translation(language='de').gettext
4350
i18n.ngettext = i18n.get_translation(language='C').ngettext
51+
i18n.dengettext = i18n.get_translation(language='de').ngettext
4452

4553
def tearDown(self):
4654
i18n.gettext = self.old_gettext_
@@ -421,6 +429,46 @@ def ae(spec, pretty):
421429
ae('-1y', '1 year ago')
422430
ae('-2y', '2 years ago')
423431

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+
424472
def testPyDatetime(self):
425473
d = datetime.datetime.now()
426474
Date(d)

0 commit comments

Comments
 (0)