Skip to content

Commit feece86

Browse files
committed
tests: Sanity check line-width option
Provide a unit test to validate the usage of the `--line-width` option. Signed-off-by: James Knight <[email protected]>
1 parent 6edc8aa commit feece86

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/test_cmd_pot.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
:copyright: Copyright 2019 by Takayuki SHIMIZUKAWA.
99
:license: BSD, see LICENSE for details.
1010
"""
11+
12+
import os
13+
1114
from click.testing import CliRunner
1215

1316
from sphinx_intl import commands
@@ -67,6 +70,38 @@ def test_update_difference_detect(temp):
6770
assert r4.output.count('Not Changed:') == 1
6871

6972

73+
def test_update_line_width(temp):
74+
with open('_build/locale/README.pot', 'r') as f:
75+
template = f.read()
76+
77+
with open('_build/locale/README.pot', 'w') as f:
78+
f.write(template)
79+
f.write('\nmsgid "foorbar identifier1"\nmsgstr ""\n')
80+
81+
po_dir = os.path.join('locale', 'ja', 'LC_MESSAGES')
82+
po_file = os.path.join(po_dir, 'README.po')
83+
84+
r1 = runner.invoke(commands.update, ['-d', 'locale', '-p', '_build/locale', '-l', 'ja'])
85+
assert r1.exit_code == 0
86+
87+
with open(po_file, 'r') as f:
88+
contents = f.read()
89+
assert '"foorbar identifier1"\n' in contents
90+
91+
# change the identifier to trigger an update and impose a lower line-width count
92+
with open('_build/locale/README.pot', 'w') as f:
93+
f.write(template)
94+
f.write('\nmsgid "foorbar identifier2"\nmsgstr ""\n')
95+
96+
r2 = runner.invoke(commands.update, ['-d', 'locale', '-p', '_build/locale', '-w', '1'])
97+
assert r2.exit_code == 0
98+
99+
with open(po_file, 'r') as f:
100+
contents = f.read()
101+
assert '"foorbar"\n' in contents
102+
assert '"identifier2"\n' in contents
103+
104+
70105
def test_stat(temp):
71106
r1 = runner.invoke(commands.update, ['-d', 'locale', '-p', '_build/locale', '-l', 'ja'])
72107
assert r1.exit_code == 0

0 commit comments

Comments
 (0)