-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
226 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
"""Tests for "min_translated_messages" configuration setting.""" | ||
|
||
import os | ||
|
||
import pytest | ||
|
||
|
||
TESTS = ( | ||
pytest.param( | ||
{ | ||
'index.md': ( | ||
'Hello\n\nBye' | ||
), | ||
}, | ||
{ | ||
'es/index.md.po': { | ||
'Hello': 'Hola', | ||
'Bye': '', | ||
}, | ||
}, | ||
{ | ||
'languages': ['en', 'es'], | ||
'min_translated_messages': '50%', | ||
}, | ||
{}, | ||
{ | ||
'index.html': [ | ||
'<p>Hello</p>', | ||
'<p>Bye</p>', | ||
], | ||
}, | ||
( | ||
'Excluding language "es". Translated 0% (0 of 3 messages)' | ||
' but required 50% at least.' | ||
), | ||
( | ||
'Excluding language "es". Translated ~33.33% (1 of 3 messages)' | ||
' but required 50% at least.' | ||
), | ||
id='min_translated_messages=50%', | ||
), | ||
pytest.param( | ||
{ | ||
'index.md': ( | ||
'Hello\n\nBye' | ||
), | ||
}, | ||
{ | ||
'es/index.md.po': { | ||
'Hello': 'Hola', | ||
'Bye': '', | ||
}, | ||
}, | ||
{ | ||
'languages': ['en', 'es'], | ||
'min_translated_messages': 2, | ||
}, | ||
{}, | ||
{ | ||
'index.html': [ | ||
'<p>Hello</p>', | ||
'<p>Bye</p>', | ||
], | ||
}, | ||
( | ||
'Excluding language "es". Translated 0 messages of' | ||
' 3 but required 2 translated messages at least.' | ||
), | ||
( | ||
'Excluding language "es". Translated 1 messages of' | ||
' 3 but required 2 translated messages at least.' | ||
), | ||
id='min_translated_messages=2', | ||
), | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
( | ||
'input_files_contents', | ||
'translations', | ||
'plugin_config', | ||
'additional_config', | ||
'expected_output_files', | ||
'expected_first_build_log', | ||
'expected_second_build_log', | ||
), | ||
TESTS, | ||
) | ||
def test_navigation_and_page_building_plugins( | ||
input_files_contents, | ||
translations, | ||
plugin_config, | ||
additional_config, | ||
expected_output_files, | ||
expected_first_build_log, | ||
expected_second_build_log, | ||
mkdocs_build, | ||
): | ||
def check_translation_files_not_exists(context): | ||
es_path = os.path.join(context['site_dir'], 'es') | ||
es_index_path = os.path.join(es_path, 'index.html') | ||
assert not os.path.exists(es_path) | ||
assert not os.path.exists(es_index_path) | ||
|
||
mkdocs_log, plugin_log = mkdocs_build( | ||
input_files_contents, | ||
translations, | ||
plugin_config, | ||
additional_config, | ||
expected_output_files, | ||
callback_after_first_build=check_translation_files_not_exists, | ||
allow_missing_translations=True, | ||
) | ||
|
||
# first build log | ||
assert expected_first_build_log in plugin_log | ||
|
||
# second build log | ||
assert expected_second_build_log in ( | ||
plugin_log.split(expected_first_build_log)[-1] # after first build log | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters