-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from MarcinOrlowski/dev
Release 2.2.0
- Loading branch information
Showing
29 changed files
with
415 additions
and
132 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
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,6 @@ | ||
argparse | ||
wemake-python-styleguide | ||
pytest | ||
wheel | ||
setuptools | ||
twine |
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
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
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,80 @@ | ||
""" | ||
# trans-tool | ||
# The translation files checker and syncing tool. | ||
# | ||
# Copyright ©2021 Marcin Orlowski <mail [@] MarcinOrlowski.com> | ||
# https://github.com/MarcinOrlowski/trans-tool/ | ||
# | ||
""" | ||
from typing import Dict, Union, List | ||
|
||
from transtool.checks.substitutions import Substitutions | ||
from transtool.decorators.overrides import overrides | ||
from transtool.prop.file import PropFile | ||
from transtool.prop.items import Comment, Translation | ||
from tests.checks.checks_test_case import ChecksTestCase | ||
|
||
|
||
class SubstitutionsTests(ChecksTestCase): | ||
|
||
@overrides(ChecksTestCase) | ||
def get_checker(self, config: Union[Dict, None] = None) -> Substitutions: | ||
return Substitutions(config) | ||
|
||
# ################################################################################################# | ||
|
||
def _get_valid_strings(self) -> List[str]: | ||
return [ | ||
'Foo. Bar. All is fin5e!', | ||
'Foo!', | ||
] | ||
|
||
def _get_faulty_strings(self) -> List[str]: | ||
return [ | ||
'Triple dots...', | ||
'Ough!!!', | ||
] | ||
|
||
def test_translation_no_faults(self) -> None: | ||
for test in self._get_valid_strings(): | ||
self.check_single_file(Translation('key', test)) | ||
|
||
def test_empty_translation(self) -> None: | ||
self.check(PropFile(self.config)) | ||
|
||
# ################################################################################################# | ||
|
||
def test_comment_no_faults(self) -> None: | ||
for test in self._get_valid_strings(): | ||
self.check_single_file(Comment(test)) | ||
|
||
def test_comment_with_faults(self) -> None: | ||
faults = self._get_faulty_strings() | ||
|
||
for fault in faults: | ||
# We should see no issues if comment scanning is disabled. | ||
self.checker.config['comments'] = False | ||
self.check_single_file(Comment(fault)) | ||
|
||
# And some warnings when comment scanning in enabled. | ||
self.checker.config['comments'] = True | ||
self.check_single_file(Comment(fault), exp_warnings = 1) | ||
|
||
# ################################################################################################# | ||
|
||
def test_fail_with_error_flag(self) -> None: | ||
""" | ||
Ensures FLAG_FAIL_WITH_ERROR flag aborts scanning and returns error while | ||
FLAG_DEFAULT yields warning. | ||
""" | ||
cfg = { | ||
'regexp': r'([\.]{3})', | ||
'replace': '…', | ||
} | ||
self.checker.config['map'] = [cfg] | ||
|
||
cfg['flag'] = Substitutions.FLAG_DEFAULT | ||
self.check_single_file(Translation('key', 'Triple dots...'), exp_warnings = 1) | ||
|
||
cfg['flag'] = Substitutions.FLAG_FAIL_WITH_ERROR | ||
self.check_single_file(Translation('key', 'Triple dots...'), exp_errors = 1) |
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,59 @@ | ||
""" | ||
# trans-tool | ||
# The translation files checker and syncing tool. | ||
# | ||
# Copyright ©2021 Marcin Orlowski <mail [@] MarcinOrlowski.com> | ||
# https://github.com/MarcinOrlowski/trans-tool/ | ||
# | ||
""" | ||
|
||
import random | ||
|
||
from tests.test_case import TestCase | ||
from transtool.config.config import Config | ||
|
||
|
||
class TestConfig(TestCase): | ||
|
||
def test_set_checker_config(self) -> None: | ||
config = Config() | ||
checker_id = self.get_random_string('checker_id') | ||
checker_config = {} | ||
max_items = 10 | ||
for idx in range(random.randint(1, max_items)): | ||
checker_config[self.get_random_string(f'key{idx}')] = self.get_random_string(f'val{idx}') | ||
config.set_checker_config(checker_id, checker_config) | ||
|
||
self.assertIn(checker_id, config.checks) | ||
self.assertEqual(len(checker_config), len(config.checks[checker_id])) | ||
for key, val in checker_config.items(): | ||
self.assertIn(key, config.checks[checker_id]) | ||
self.assertEqual(val, config.checks[checker_id][key]) | ||
|
||
def test_set_checker_config_invalid_type(self) -> None: | ||
config = Config() | ||
checker_id = self.get_random_string('checker_id') | ||
with self.assertRaises(TypeError): | ||
# noinspection PyTypeChecker | ||
config.set_checker_config(checker_id, False) # noqa: WPS425 | ||
|
||
def test_get_checker_config(self) -> None: | ||
config = Config() | ||
checker_id = self.get_random_string('checker_id') | ||
checker_config = {} | ||
max_items = 10 | ||
for idx in range(random.randint(1, max_items)): | ||
checker_config[self.get_random_string(f'key{idx}')] = self.get_random_string(f'val{idx}') | ||
config.set_checker_config(checker_id, checker_config) | ||
|
||
read_config = config.get_checker_config(checker_id) | ||
self.assertEqual(len(checker_config), len(read_config)) | ||
for key, val in checker_config.items(): | ||
self.assertIn(key, read_config) | ||
self.assertEqual(val, read_config[key]) | ||
|
||
def test_get_checker_config_no_entry(self) -> None: | ||
config = Config() | ||
checker_id = self.get_random_string('checker_id') | ||
with self.assertRaises(KeyError): | ||
config.get_checker_config(checker_id) |
Oops, something went wrong.