Skip to content

Commit ede2dba

Browse files
committed
Make i18n tests work
These use installed roundup locales but should use the checked-out locales. Also revert monkey patches in i18n after the test.
1 parent 50b0bf6 commit ede2dba

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

test/test_dates.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ def setUp(self):
4040
# force use of local locale directory. System locale dir
4141
# doesn't have the locale files installed, and without wiping
4242
# the default the .mo file sometimes isn't found.
43-
i18n.LOCALE_DIRS=[]
44-
i18n.LOCALE_DIRS.insert(0,"locale/locale")
43+
self.backup_domain = i18n.DOMAIN
44+
i18n.DOMAIN = ''
45+
self.backup_locale_dirs = i18n.LOCALE_DIRS
46+
i18n.LOCALE_DIRS=["locale"]
4547

4648
self.old_gettext_ = i18n.gettext
4749
self.old_ngettext_ = i18n.ngettext
@@ -53,6 +55,8 @@ def setUp(self):
5355
def tearDown(self):
5456
i18n.gettext = self.old_gettext_
5557
i18n.ngettext = self.old_ngettext_
58+
i18n.LOCALE_DIRS = self.backup_locale_dirs
59+
i18n.DOMAIN = self.backup_domain
5660

5761
def testDateInterval(self):
5862
ae = self.assertEqual

test/test_liveserver.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import shutil, errno, pytest, json, gzip, os, re
22

3+
from roundup import i18n
34
from roundup.anypy.strings import b2s
45
from roundup.cgi.wsgi_handler import RequestDispatcher
56
from .wsgi_liveserver import LiveServerTestCase
@@ -40,7 +41,7 @@
4041
class SimpleTest(LiveServerTestCase):
4142
# have chicken and egg issue here. Need to encode the base_url
4243
# in the config file but we don't know it until after
43-
# the server is started nd has read the config.ini.
44+
# the server is started and has read the config.ini.
4445
# so only allow one port number
4546
port_range = (9001, 9001) # default is (8080, 8090)
4647

@@ -49,7 +50,7 @@ class SimpleTest(LiveServerTestCase):
4950

5051
@classmethod
5152
def setup_class(cls):
52-
'''All test in this class use the same roundup instance.
53+
'''All tests in this class use the same roundup instance.
5354
This instance persists across all tests.
5455
Create the tracker dir here so that it is ready for the
5556
create_app() method to be called.
@@ -75,6 +76,13 @@ def setup_class(cls):
7576

7677
cls.db.commit()
7778
cls.db.close()
79+
80+
# Force locale config to find locales in checkout not in
81+
# installed directories
82+
cls.backup_domain = i18n.DOMAIN
83+
cls.backup_locale_dirs = i18n.LOCALE_DIRS
84+
i18n.LOCALE_DIRS = ['locale']
85+
i18n.DOMAIN = ''
7886

7987
@classmethod
8088
def teardown_class(cls):
@@ -87,6 +95,8 @@ def teardown_class(cls):
8795
shutil.rmtree(cls.dirname)
8896
except OSError as error:
8997
if error.errno not in (errno.ENOENT, errno.ESRCH): raise
98+
i18n.LOCALE_DIRS = cls.backup_locale_dirs
99+
i18n.DOMAIN = cls.backup_domain
90100

91101
def create_app(self):
92102
'''The wsgi app to start'''

0 commit comments

Comments
 (0)