mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Add testcases
This commit is contained in:
parent
aba26657c5
commit
f5bc9fd5dd
@ -19,7 +19,7 @@ from docutils import nodes
|
||||
from docutils.parsers.rst import directives, roles
|
||||
from six import string_types
|
||||
|
||||
from sphinx import application
|
||||
from sphinx import application, locale
|
||||
from sphinx.builders.latex import LaTeXBuilder
|
||||
from sphinx.ext.autodoc import AutoDirective
|
||||
from sphinx.pycode import ModuleAnalyzer
|
||||
@ -147,6 +147,7 @@ class SphinxTestApp(application.Sphinx):
|
||||
AutoDirective._registry.clear()
|
||||
ModuleAnalyzer.cache.clear()
|
||||
LaTeXBuilder.usepackages = []
|
||||
locale.translators.clear()
|
||||
sys.path[:] = self._saved_path
|
||||
sys.modules.pop('autodoc_fodder', None)
|
||||
directives._directives = self._saved_directives
|
||||
|
BIN
tests/roots/test-locale/locale1/en/LC_MESSAGES/myext.mo
Normal file
BIN
tests/roots/test-locale/locale1/en/LC_MESSAGES/myext.mo
Normal file
Binary file not shown.
2
tests/roots/test-locale/locale1/en/LC_MESSAGES/myext.po
Normal file
2
tests/roots/test-locale/locale1/en/LC_MESSAGES/myext.po
Normal file
@ -0,0 +1,2 @@
|
||||
msgid "Hello world"
|
||||
msgstr "HELLO WORLD"
|
BIN
tests/roots/test-locale/locale2/en/LC_MESSAGES/myext.mo
Normal file
BIN
tests/roots/test-locale/locale2/en/LC_MESSAGES/myext.mo
Normal file
Binary file not shown.
2
tests/roots/test-locale/locale2/en/LC_MESSAGES/myext.po
Normal file
2
tests/roots/test-locale/locale2/en/LC_MESSAGES/myext.po
Normal file
@ -0,0 +1,2 @@
|
||||
msgid "Hello sphinx"
|
||||
msgstr "HELLO SPHINX"
|
60
tests/test_locale.py
Normal file
60
tests/test_locale.py
Normal file
@ -0,0 +1,60 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
test_locale
|
||||
~~~~~~~~~~
|
||||
|
||||
Test locale.
|
||||
|
||||
:copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from sphinx import locale
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def cleanup_translations():
|
||||
yield
|
||||
locale.translators = {}
|
||||
|
||||
|
||||
def test_init(rootdir):
|
||||
# not initialized yet
|
||||
_ = locale.get_translation('myext')
|
||||
assert _('Hello world') == 'Hello world'
|
||||
assert _('Hello sphinx') == 'Hello sphinx'
|
||||
assert _('Hello reST') == 'Hello reST'
|
||||
|
||||
# load locale1
|
||||
locale.init([rootdir / 'test-locale' / 'locale1'], 'en', 'myext')
|
||||
_ = locale.get_translation('myext')
|
||||
assert _('Hello world') == 'HELLO WORLD'
|
||||
assert _('Hello sphinx') == 'Hello sphinx'
|
||||
assert _('Hello reST') == 'Hello reST'
|
||||
|
||||
# load both locale1 and locale2
|
||||
locale.init([rootdir / 'test-locale' / 'locale1',
|
||||
rootdir / 'test-locale' / 'locale2'], 'en', 'myext')
|
||||
_ = locale.get_translation('myext')
|
||||
assert _('Hello world') == 'HELLO WORLD'
|
||||
assert _('Hello sphinx') == 'HELLO SPHINX'
|
||||
assert _('Hello reST') == 'Hello reST'
|
||||
|
||||
|
||||
def test_init_with_unknown_language(rootdir):
|
||||
locale.init([rootdir / 'test-locale' / 'locale1'], 'unknown', 'myext')
|
||||
_ = locale.get_translation('myext')
|
||||
assert _('Hello world') == 'Hello world'
|
||||
assert _('Hello sphinx') == 'Hello sphinx'
|
||||
assert _('Hello reST') == 'Hello reST'
|
||||
|
||||
|
||||
def test_add_message_catalog(app, rootdir):
|
||||
app.config.language = 'en'
|
||||
app.add_message_catalog('myext', rootdir / 'test-locale' / 'locale1')
|
||||
_ = locale.get_translation('myext')
|
||||
assert _('Hello world') == 'HELLO WORLD'
|
||||
assert _('Hello sphinx') == 'Hello sphinx'
|
||||
assert _('Hello reST') == 'Hello reST'
|
Loading…
Reference in New Issue
Block a user