summaryrefslogtreecommitdiff
path: root/tests/test_util_i18n.py
diff options
context:
space:
mode:
authorshimizukawa <shimizukawa@gmail.com>2017-01-07 02:13:50 +0900
committershimizukawa <shimizukawa@gmail.com>2017-01-07 02:14:29 +0900
commit4c22cd10caa7b9621ece480fade5653d65226fcc (patch)
tree19a64268e9814dfa12087dc2d432c5339a23a0a9 /tests/test_util_i18n.py
parentf695aac2e28e1463385b399b61fc2c4b4ef40c5c (diff)
parent620616cdbd92147f6ea7bbeb670dc3a0562235ff (diff)
downloadsphinx-git-4c22cd10caa7b9621ece480fade5653d65226fcc.tar.gz
Merge branch 'stable'
Diffstat (limited to 'tests/test_util_i18n.py')
-rw-r--r--tests/test_util_i18n.py136
1 files changed, 65 insertions, 71 deletions
diff --git a/tests/test_util_i18n.py b/tests/test_util_i18n.py
index 933f3403a..a8fb8b0b3 100644
--- a/tests/test_util_i18n.py
+++ b/tests/test_util_i18n.py
@@ -17,8 +17,9 @@ from os import path
from babel.messages.mofile import read_mo
from sphinx.util import i18n
from sphinx.errors import SphinxError
+import pytest
-from util import TestApp, with_tempdir, raises
+from util import TestApp
def test_catalog_info_for_file_and_path():
@@ -37,13 +38,12 @@ def test_catalog_info_for_sub_domain_file_and_path():
assert cat.mo_path == path.join('path', 'sub/domain.mo')
-@with_tempdir
-def test_catalog_outdated(dir):
- (dir / 'test.po').write_text('#')
- cat = i18n.CatalogInfo(dir, 'test', 'utf-8')
+def test_catalog_outdated(tempdir):
+ (tempdir / 'test.po').write_text('#')
+ cat = i18n.CatalogInfo(tempdir, 'test', 'utf-8')
assert cat.is_outdated() # if mo is not exist
- mo_file = (dir / 'test.mo')
+ mo_file = (tempdir / 'test.mo')
mo_file.write_text('#')
assert not cat.is_outdated() # if mo is exist and newer than po
@@ -51,31 +51,29 @@ def test_catalog_outdated(dir):
assert cat.is_outdated() # if mo is exist and older than po
-@with_tempdir
-def test_catalog_write_mo(dir):
- (dir / 'test.po').write_text('#')
- cat = i18n.CatalogInfo(dir, 'test', 'utf-8')
+def test_catalog_write_mo(tempdir):
+ (tempdir / 'test.po').write_text('#')
+ cat = i18n.CatalogInfo(tempdir, 'test', 'utf-8')
cat.write_mo('en')
assert path.exists(cat.mo_path)
with open(cat.mo_path, 'rb') as f:
assert read_mo(f) is not None
-@with_tempdir
-def test_get_catalogs_for_xx(dir):
- (dir / 'loc1' / 'xx' / 'LC_MESSAGES').makedirs()
- (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test1.po').write_text('#')
- (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test2.po').write_text('#')
- (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test3.pot').write_text('#')
- (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub').makedirs()
- (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test4.po').write_text('#')
- (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test5.po').write_text('#')
- (dir / 'loc1' / 'en' / 'LC_MESSAGES').makedirs()
- (dir / 'loc1' / 'en' / 'LC_MESSAGES' / 'test6.po').write_text('#')
- (dir / 'loc1' / 'xx' / 'LC_ALL').makedirs()
- (dir / 'loc1' / 'xx' / 'LC_ALL' / 'test7.po').write_text('#')
-
- catalogs = i18n.find_catalog_source_files([dir / 'loc1'], 'xx', force_all=False)
+def test_get_catalogs_for_xx(tempdir):
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES').makedirs()
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test1.po').write_text('#')
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test2.po').write_text('#')
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test3.pot').write_text('#')
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub').makedirs()
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test4.po').write_text('#')
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test5.po').write_text('#')
+ (tempdir / 'loc1' / 'en' / 'LC_MESSAGES').makedirs()
+ (tempdir / 'loc1' / 'en' / 'LC_MESSAGES' / 'test6.po').write_text('#')
+ (tempdir / 'loc1' / 'xx' / 'LC_ALL').makedirs()
+ (tempdir / 'loc1' / 'xx' / 'LC_ALL' / 'test7.po').write_text('#')
+
+ catalogs = i18n.find_catalog_source_files([tempdir / 'loc1'], 'xx', force_all=False)
domains = set(c.domain for c in catalogs)
assert domains == set([
'test1',
@@ -85,24 +83,22 @@ def test_get_catalogs_for_xx(dir):
])
-@with_tempdir
-def test_get_catalogs_for_en(dir):
- (dir / 'loc1' / 'xx' / 'LC_MESSAGES').makedirs()
- (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'xx_dom.po').write_text('#')
- (dir / 'loc1' / 'en' / 'LC_MESSAGES').makedirs()
- (dir / 'loc1' / 'en' / 'LC_MESSAGES' / 'en_dom.po').write_text('#')
+def test_get_catalogs_for_en(tempdir):
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES').makedirs()
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'xx_dom.po').write_text('#')
+ (tempdir / 'loc1' / 'en' / 'LC_MESSAGES').makedirs()
+ (tempdir / 'loc1' / 'en' / 'LC_MESSAGES' / 'en_dom.po').write_text('#')
- catalogs = i18n.find_catalog_source_files([dir / 'loc1'], 'en', force_all=False)
+ catalogs = i18n.find_catalog_source_files([tempdir / 'loc1'], 'en', force_all=False)
domains = set(c.domain for c in catalogs)
assert domains == set(['en_dom'])
-@with_tempdir
-def test_get_catalogs_with_non_existent_locale(dir):
- catalogs = i18n.find_catalog_source_files([dir / 'loc1'], 'xx')
+def test_get_catalogs_with_non_existent_locale(tempdir):
+ catalogs = i18n.find_catalog_source_files([tempdir / 'loc1'], 'xx')
assert not catalogs
- catalogs = i18n.find_catalog_source_files([dir / 'loc1'], None)
+ catalogs = i18n.find_catalog_source_files([tempdir / 'loc1'], None)
assert not catalogs
@@ -111,25 +107,24 @@ def test_get_catalogs_with_non_existent_locale_dirs():
assert not catalogs
-@with_tempdir
-def test_get_catalogs_for_xx_without_outdated(dir):
- (dir / 'loc1' / 'xx' / 'LC_MESSAGES').makedirs()
- (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test1.po').write_text('#')
- (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test1.mo').write_text('#')
- (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test2.po').write_text('#')
- (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test2.mo').write_text('#')
- (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test3.pot').write_text('#')
- (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test3.mo').write_text('#')
- (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub').makedirs()
- (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test4.po').write_text('#')
- (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test4.mo').write_text('#')
- (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test5.po').write_text('#')
- (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test5.mo').write_text('#')
-
- catalogs = i18n.find_catalog_source_files([dir / 'loc1'], 'xx', force_all=False)
+def test_get_catalogs_for_xx_without_outdated(tempdir):
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES').makedirs()
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test1.po').write_text('#')
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test1.mo').write_text('#')
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test2.po').write_text('#')
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test2.mo').write_text('#')
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test3.pot').write_text('#')
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test3.mo').write_text('#')
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub').makedirs()
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test4.po').write_text('#')
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test4.mo').write_text('#')
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test5.po').write_text('#')
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test5.mo').write_text('#')
+
+ catalogs = i18n.find_catalog_source_files([tempdir / 'loc1'], 'xx', force_all=False)
assert not catalogs
- catalogs = i18n.find_catalog_source_files([dir / 'loc1'], 'xx', force_all=True)
+ catalogs = i18n.find_catalog_source_files([tempdir / 'loc1'], 'xx', force_all=True)
domains = set(c.domain for c in catalogs)
assert domains == set([
'test1',
@@ -139,29 +134,27 @@ def test_get_catalogs_for_xx_without_outdated(dir):
])
-@with_tempdir
-def test_get_catalogs_from_multiple_locale_dirs(dir):
- (dir / 'loc1' / 'xx' / 'LC_MESSAGES').makedirs()
- (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test1.po').write_text('#')
- (dir / 'loc2' / 'xx' / 'LC_MESSAGES').makedirs()
- (dir / 'loc2' / 'xx' / 'LC_MESSAGES' / 'test1.po').write_text('#')
- (dir / 'loc2' / 'xx' / 'LC_MESSAGES' / 'test2.po').write_text('#')
+def test_get_catalogs_from_multiple_locale_dirs(tempdir):
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES').makedirs()
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test1.po').write_text('#')
+ (tempdir / 'loc2' / 'xx' / 'LC_MESSAGES').makedirs()
+ (tempdir / 'loc2' / 'xx' / 'LC_MESSAGES' / 'test1.po').write_text('#')
+ (tempdir / 'loc2' / 'xx' / 'LC_MESSAGES' / 'test2.po').write_text('#')
- catalogs = i18n.find_catalog_source_files([dir / 'loc1', dir / 'loc2'], 'xx')
+ catalogs = i18n.find_catalog_source_files([tempdir / 'loc1', tempdir / 'loc2'], 'xx')
domains = sorted(c.domain for c in catalogs)
assert domains == ['test1', 'test1', 'test2']
-@with_tempdir
-def test_get_catalogs_with_compact(dir):
- (dir / 'loc1' / 'xx' / 'LC_MESSAGES').makedirs()
- (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test1.po').write_text('#')
- (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test2.po').write_text('#')
- (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub').makedirs()
- (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test3.po').write_text('#')
- (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test4.po').write_text('#')
+def test_get_catalogs_with_compact(tempdir):
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES').makedirs()
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test1.po').write_text('#')
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test2.po').write_text('#')
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub').makedirs()
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test3.po').write_text('#')
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test4.po').write_text('#')
- catalogs = i18n.find_catalog_source_files([dir / 'loc1'], 'xx', gettext_compact=True)
+ catalogs = i18n.find_catalog_source_files([tempdir / 'loc1'], 'xx', gettext_compact=True)
domains = set(c.domain for c in catalogs)
assert domains == set(['test1', 'test2', 'sub'])
@@ -251,4 +244,5 @@ def test_get_filename_for_language():
# invalid figure_language_filename
app.env.config.figure_language_filename = '{root}.{invalid}{ext}'
- raises(SphinxError, i18n.get_image_filename_for_language, 'foo.png', app.env)
+ with pytest.raises(SphinxError):
+ i18n.get_image_filename_for_language('foo.png', app.env)