mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-03-17 06:20:27 +00:00
Fix checker test cases for non-english locales.
This commit is contained in:
parent
4cc19f4e9c
commit
cd6ee8a1bc
3 changed files with 14 additions and 8 deletions
|
|
@ -132,7 +132,7 @@ def get_link_pat (arg, strict=False):
|
|||
}
|
||||
|
||||
|
||||
def init_i18n ():
|
||||
def init_i18n (loc=None):
|
||||
"""Initialize i18n with the configured locale dir. The environment
|
||||
variable LOCPATH can also specify a locale dir.
|
||||
|
||||
|
|
@ -142,7 +142,7 @@ def init_i18n ():
|
|||
locdir = os.environ['LOCPATH']
|
||||
else:
|
||||
locdir = os.path.join(get_install_data(), 'share', 'locale')
|
||||
i18n.init(configdata.name.lower(), locdir)
|
||||
i18n.init(configdata.name.lower(), locdir, loc=loc)
|
||||
# install translated log level names
|
||||
import logging
|
||||
logging.addLevelName(logging.CRITICAL, _('CRITICAL'))
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ class NullTranslator (gettext.NullTranslations):
|
|||
install_builtin(self, do_unicode)
|
||||
|
||||
|
||||
def init (domain, directory):
|
||||
def init (domain, directory, loc=None):
|
||||
"""Initialize this gettext i18n module. Searches for supported languages
|
||||
and installs the gettext translator class."""
|
||||
global default_language, default_encoding
|
||||
|
|
@ -70,7 +70,10 @@ def init (domain, directory):
|
|||
mo_file = os.path.join(path, '%s.mo' % domain)
|
||||
if os.path.exists(mo_file):
|
||||
supported_languages.add(lang)
|
||||
loc, encoding = get_locale()
|
||||
if loc is None:
|
||||
loc, encoding = get_locale()
|
||||
else:
|
||||
encoding = get_locale()[1]
|
||||
if loc in supported_languages:
|
||||
default_language = loc
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ import linkcheck.checker
|
|||
import linkcheck.configuration
|
||||
import linkcheck.director
|
||||
import linkcheck.logger
|
||||
import linkcheck.i18n
|
||||
from .. import get_file
|
||||
|
||||
# helper alias
|
||||
|
|
@ -141,10 +140,14 @@ class LinkCheckTest (unittest.TestCase):
|
|||
Functional test class with ability to test local files.
|
||||
"""
|
||||
|
||||
def setUp (self):
|
||||
"""Ensure the current locale setting is the default.
|
||||
Otherwise, warnings will get translated and will break tests."""
|
||||
super(LinkCheckTest, self).setUp()
|
||||
linkcheck.init_i18n(loc='C')
|
||||
|
||||
def norm (self, url, encoding=None):
|
||||
"""
|
||||
Helper function to norm a url.
|
||||
"""
|
||||
"""Helper function to norm a url."""
|
||||
return linkcheck.url.url_norm(url, encoding=encoding)[0]
|
||||
|
||||
def get_attrs (self, **kwargs):
|
||||
|
|
|
|||
Loading…
Reference in a new issue