File: test_cmd_pot.py

package info (click to toggle)
sphinx-intl 0.9.11-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 208 kB
  • sloc: python: 986; makefile: 2
file content (93 lines) | stat: -rw-r--r-- 3,102 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# -*- coding: utf-8 -*-
"""
    test_cmd_pot
    ~~~~~~~~~~~~~

    Test pot related commands.

    :copyright: Copyright 2015 by Takayuki SHIMIZUKAWA.
    :license: BSD, see LICENSE for details.
"""
from __future__ import with_statement

from click.testing import CliRunner

from sphinx_intl import commands

runner = CliRunner()


def test_update_pot_notfound(temp):
    r1 = runner.invoke(commands.update, ['-d', 'locale'])
    assert r1.exit_code != 0
    assert 'Please specify pot directory with -p option,' in r1.output


def test_update_no_language(temp):
    r1 = runner.invoke(commands.update, ['-d', 'locale', '-p', '_build/locale'])
    assert r1.exit_code != 0
    assert 'No languages are found. Please specify language with -l' in r1.output


def test_update_simple(temp):
    r1 = runner.invoke(commands.update, ['-d', 'locale', '-p', '_build/locale', '-l', 'ja'])
    assert r1.exit_code == 0


def test_update_difference_detect(temp):
    r1 = runner.invoke(commands.update, ['-d', 'locale', '-p', '_build/locale', '-l', 'ja'])
    assert r1.exit_code == 0
    assert r1.output.count('Create:') == 1
    assert r1.output.count('Update:') == 0
    assert r1.output.count('Not Changed:') == 0

    with open('_build/locale/README.pot', 'a') as f:
        f.write('\nmsgid "test1"\nmsgstr ""\n')

    r2 = runner.invoke(commands.update, ['-d', 'locale', '-p', '_build/locale'])
    assert r2.exit_code == 0
    assert r2.output.count('Create:') == 0
    assert r2.output.count('Update:') == 1
    assert r2.output.count('Not Changed:') == 0

    with open('_build/locale/README.pot', 'r') as f:
        d = f.read()
        d = d.replace('test1', 'test2')
    with open('_build/locale/README.pot', 'w') as f:
        f.write(d)

    r3 = runner.invoke(commands.update, ['-d', 'locale', '-p', '_build/locale'])
    assert r3.exit_code == 0
    assert r3.output.count('Create:') == 0
    assert r3.output.count('Update:') == 1
    assert r3.output.count('Not Changed:') == 0

    r4 = runner.invoke(commands.update, ['-d', 'locale', '-p', '_build/locale'])
    assert r4.exit_code == 0
    assert r4.output.count('Create:') == 0
    assert r4.output.count('Update:') == 0
    assert r4.output.count('Not Changed:') == 1


def test_stat(temp):
    r1 = runner.invoke(commands.update, ['-d', 'locale', '-p', '_build/locale', '-l', 'ja'])
    assert r1.exit_code == 0

    r2 = runner.invoke(commands.stat, ['-d', 'locale'])
    assert r2.exit_code == 0
    assert 'README.po: 0 translated, 0 fuzzy, 1 untranslated.' in r2.output


def test_stat_with_multiple_languages(temp):
    r1 = runner.invoke(commands.update, ['-d', 'locale', '-p', '_build/locale', '-l', 'ja,de,it'])
    assert r1.exit_code == 0

    # r2 = runner.invoke(commands.stat, ['-d', 'locale', '-l', 'ja,de', '-l', 'it'])
    r2 = runner.invoke(commands.stat, ['-d', 'locale', '-l', 'ja'])
    assert r2.exit_code == 0
    assert 'README.po: 0 translated, 0 fuzzy, 1 untranslated.' in r2.output


def test_build(temp):
    result = runner.invoke(commands.build, ['--locale-dir', 'locale'])
    assert result.exit_code == 0