[test_utils] Add a basic test for i18n

This commit is contained in:
Yen Chi Hsuan 2015-12-26 05:13:50 +08:00
parent a5f07800dd
commit af9c89ba07
3 changed files with 36 additions and 2 deletions

View File

@ -17,3 +17,7 @@ notifications:
# channels:
# - "irc.freenode.org#youtube-dl"
# skip_join: true
addons:
apt:
packages:
- gettext

View File

@ -36,14 +36,14 @@ install: youtube-dl youtube-dl.1 youtube-dl.bash-completion youtube-dl.zsh youtu
codetest:
flake8 .
test:
test: update-gmo
#nosetests --with-coverage --cover-package=youtube_dl --cover-html --verbose --processes 4 test
nosetests --verbose test
$(MAKE) codetest
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
tar: youtube-dl.tar.gz

View File

@ -30,6 +30,7 @@ from youtube_dl.utils import (
fix_xml_ampersands,
InAdvancePagedList,
intlist_to_bytes,
I18N,
is_html,
js_to_json,
limit_length,
@ -746,6 +747,35 @@ The first line
{'nocheckcertificate': False}, '--check-certificate', 'nocheckcertificate', 'false', '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__':
unittest.main()