garden: use 4-space indents
[git-cola.git] / test / i18n_test.py
blob5a11376fa7cc931fff8a5cf9b2adc061d4b9a817
1 """Tests for the i18n translation module"""
2 import os
4 import pytest
6 from cola import i18n
7 from cola.i18n import N_
8 from cola.compat import uchr
11 @pytest.fixture(autouse=True)
12 def i18n_context():
13 """Perform cleanup/teardown of the i18n module"""
14 yield
15 i18n.uninstall()
18 def test_translates_noun():
19 """Test that strings with @@noun are translated"""
20 i18n.install('ja_JP')
21 expect = uchr(0x30B3) + uchr(0x30DF) + uchr(0x30C3) + uchr(0x30C8)
22 actual = N_('Commit@@verb')
23 assert expect == actual
26 def test_translates_verb():
27 """Test that strings with @@verb are translated"""
28 i18n.install('de_DE')
29 expect = 'Commit aufnehmen'
30 actual = N_('Commit@@verb')
31 assert expect == actual
34 def test_translates_english_noun():
35 """Test that English strings with @@noun are properly handled"""
36 i18n.install('en_US.UTF-8')
37 expect = 'Commit'
38 actual = N_('Commit@@noun')
39 assert expect == actual
42 def test_translates_english_verb():
43 """Test that English strings with @@verb are properly handled"""
44 i18n.install('en_US.UTF-8')
45 expect = 'Commit'
46 actual = N_('Commit@@verb')
47 assert expect == actual
50 def test_translates_random_english():
51 """Test that random English strings are passed through as-is"""
52 i18n.install('en_US.UTF-8')
53 expect = 'Random'
54 actual = N_('Random')
55 assert expect == actual
58 def test_translate_push_pull_french():
59 i18n.install('fr_FR')
60 expect = 'Tirer'
61 actual = N_('Pull')
62 assert expect == actual
64 expect = 'Pousser'
65 actual = N_('Push')
66 assert expect == actual
69 def test_get_filename_for_locale():
70 """Ensure that the appropriate .po files are found"""
71 actual = i18n.get_filename_for_locale('does_not_exist')
72 assert actual is None
74 actual = i18n.get_filename_for_locale('id_ID')
75 assert os.path.basename(actual) == 'id_ID.po'
77 actual = i18n.get_filename_for_locale('ja_JP')
78 assert os.path.basename(actual) == 'ja.po'