[test_utils] Add a basic test for i18n
This commit is contained in:
parent
a5f07800dd
commit
af9c89ba07
@ -17,3 +17,7 @@ notifications:
|
|||||||
# channels:
|
# channels:
|
||||||
# - "irc.freenode.org#youtube-dl"
|
# - "irc.freenode.org#youtube-dl"
|
||||||
# skip_join: true
|
# skip_join: true
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
packages:
|
||||||
|
- gettext
|
||||||
|
4
Makefile
4
Makefile
@ -36,14 +36,14 @@ install: youtube-dl youtube-dl.1 youtube-dl.bash-completion youtube-dl.zsh youtu
|
|||||||
codetest:
|
codetest:
|
||||||
flake8 .
|
flake8 .
|
||||||
|
|
||||||
test:
|
test: update-gmo
|
||||||
#nosetests --with-coverage --cover-package=youtube_dl --cover-html --verbose --processes 4 test
|
#nosetests --with-coverage --cover-package=youtube_dl --cover-html --verbose --processes 4 test
|
||||||
nosetests --verbose test
|
nosetests --verbose test
|
||||||
$(MAKE) codetest
|
$(MAKE) codetest
|
||||||
|
|
||||||
ot: offlinetest
|
ot: offlinetest
|
||||||
|
|
||||||
offlinetest: codetest
|
offlinetest: codetest update-gmo
|
||||||
nosetests --verbose test --exclude test_download.py --exclude test_age_restriction.py --exclude test_subtitles.py --exclude test_write_annotations.py --exclude test_youtube_lists.py
|
nosetests --verbose test --exclude test_download.py --exclude test_age_restriction.py --exclude test_subtitles.py --exclude test_write_annotations.py --exclude test_youtube_lists.py
|
||||||
|
|
||||||
tar: youtube-dl.tar.gz
|
tar: youtube-dl.tar.gz
|
||||||
|
@ -30,6 +30,7 @@ from youtube_dl.utils import (
|
|||||||
fix_xml_ampersands,
|
fix_xml_ampersands,
|
||||||
InAdvancePagedList,
|
InAdvancePagedList,
|
||||||
intlist_to_bytes,
|
intlist_to_bytes,
|
||||||
|
I18N,
|
||||||
is_html,
|
is_html,
|
||||||
js_to_json,
|
js_to_json,
|
||||||
limit_length,
|
limit_length,
|
||||||
@ -746,6 +747,35 @@ The first line
|
|||||||
{'nocheckcertificate': False}, '--check-certificate', 'nocheckcertificate', 'false', 'true', '='),
|
{'nocheckcertificate': False}, '--check-certificate', 'nocheckcertificate', 'false', 'true', '='),
|
||||||
['--check-certificate=true'])
|
['--check-certificate=true'])
|
||||||
|
|
||||||
|
def test_i18n(self):
|
||||||
|
old_locale = os.environ.get('LC_ALL')
|
||||||
|
if old_locale is not None:
|
||||||
|
del os.environ['LC_ALL']
|
||||||
|
|
||||||
|
instance = I18N()
|
||||||
|
instance.set_default_language('en_US')
|
||||||
|
self.assertEqual(instance.translate('Test URL: %s'), 'Test URL: %s')
|
||||||
|
|
||||||
|
instance = I18N()
|
||||||
|
instance.set_default_language('zh_TW')
|
||||||
|
self.assertEqual(instance.translate('Test URL: %s'), '測試網址:%s')
|
||||||
|
|
||||||
|
# A fake language code
|
||||||
|
instance = I18N()
|
||||||
|
instance.set_default_language('pp_QQ')
|
||||||
|
self.assertEqual(instance.translate('Test URL: %s'), 'Test URL: %s')
|
||||||
|
|
||||||
|
# setting locale via environ is not applicable on Windows
|
||||||
|
if not sys.platform.startswith('win'):
|
||||||
|
os.environ['LC_ALL'] = 'zh_TW'
|
||||||
|
instance = I18N()
|
||||||
|
self.assertEqual(instance.translate('Test URL: %s'), '測試網址:%s')
|
||||||
|
|
||||||
|
if old_locale is not None:
|
||||||
|
os.environ['LC_ALL'] = old_locale
|
||||||
|
else:
|
||||||
|
del os.environ['LC_ALL']
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user