diff --git a/README.md b/README.md index a3ecd80..b1af8f5 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,6 @@ * [Available validators](docs/checks/README.md) * [Usage examples](docs/usage.md) * [Config file](docs/config.md) -* [Features](#features) * [Changelog](docs/CHANGES.md) * [License](#license) @@ -83,3 +82,4 @@ Base: src/main/resources/resources/logisim/strings/soc/soc.properties * Written and copyrighted ©2021 by Marcin Orlowski * trans-tool is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT). * Project logo contains [elements from Flaticon.com](https://www.flaticon.com/free-icon/translation_99694). +* trans-tool project [PyPi page](https://pypi.org/project/trans-tool/). diff --git a/docs/CHANGES.md b/docs/CHANGES.md index f398363..8756986 100644 --- a/docs/CHANGES.md +++ b/docs/CHANGES.md @@ -6,6 +6,10 @@ # Changelog # +* v2.2.1 (2021-08-12) + * Corrected `setup.py` to properly modify image reference. + * Added more unit tests. + * v2.2.0 (2021-08-11) * Added ability to specify checks to run with `--checks` option. * Added more unit tests. diff --git a/setup.py b/setup.py index 696d0c5..5e71e7c 100755 --- a/setup.py +++ b/setup.py @@ -22,43 +22,43 @@ from setuptools import setup, find_packages with open('README.md', 'r') as fh: - readme = fh.read() - readme.replace('![trans-tool logo](artwork/trans-tool-logo.png)', - 'https://raw.githubusercontent.com/MarcinOrlowski/trans-tool/master/artwork/trans-tool-logo.png', 1) + logo_url = 'https://raw.githubusercontent.com/MarcinOrlowski/trans-tool/master/artwork/trans-tool-logo.png' + readme = fh.read().replace(r'![trans-tool logo](artwork/trans-tool-logo.png)', + f'![trans-tool logo]({logo_url})', 1) -setup( - name = Const.APP_NAME, - version = Const.APP_VERSION, - packages = find_packages(), + setup( + name = Const.APP_NAME, + version = Const.APP_VERSION, + packages = find_packages(), - install_requires = [ - 'argparse>=1.4.0', - ], - python_requires = '>=3.6', - entry_points = { - 'console_scripts': [ - 'trans-tool = transtool.main:TransTool.start', - 'transtool = transtool.main:TransTool.start', + install_requires = [ + 'argparse>=1.4.0', ], - }, + python_requires = '>=3.6', + entry_points = { + 'console_scripts': [ + 'trans-tool = transtool.main:TransTool.start', + 'transtool = transtool.main:TransTool.start', + ], + }, - author = 'Marcin Orlowski', - author_email = 'mail@marcinOrlowski.com', - description = 'The translation files checker and syncing tool.', - long_description = readme, - long_description_content_type = 'text/markdown', - url = Const.APP_URL, - keywords = 'translation helper locale language sync check validation', - project_urls = { - 'Bug Tracker': 'https://github.com/MarcinOrlowski/trans-tool/issues/', - 'Documentation': 'https://github.com/MarcinOrlowski/trans-tool/', - 'Source Code': 'https://github.com/MarcinOrlowski/trans-tool/', - }, - # https://choosealicense.com/ - license = 'MIT License', - classifiers = [ - 'Programming Language :: Python :: 3', - 'License :: OSI Approved :: MIT License', - 'Operating System :: OS Independent', - ], -) + author = 'Marcin Orlowski', + author_email = 'mail@marcinOrlowski.com', + description = 'The translation files checker and syncing tool.', + long_description = readme, + long_description_content_type = 'text/markdown', + url = Const.APP_URL, + keywords = 'translation helper locale language sync check validation', + project_urls = { + 'Bug Tracker': 'https://github.com/MarcinOrlowski/trans-tool/issues/', + 'Documentation': 'https://github.com/MarcinOrlowski/trans-tool/', + 'Source Code': 'https://github.com/MarcinOrlowski/trans-tool/', + }, + # https://choosealicense.com/ + license = 'MIT License', + classifiers = [ + 'Programming Language :: Python :: 3', + 'License :: OSI Approved :: MIT License', + 'Operating System :: OS Independent', + ], + ) diff --git a/tests/prop/test_comment.py b/tests/prop/test_comment.py index 891b894..7d2004a 100644 --- a/tests/prop/test_comment.py +++ b/tests/prop/test_comment.py @@ -23,12 +23,12 @@ def test_constructor(self) -> None: self.assertIsNone(item.key) def test_invalid_value(self) -> None: - with self.assertRaises(ValueError): + with self.assertRaises(TypeError): # Invalid value type # noinspection PyTypeChecker Comment(1234) - def test_without_marker(self) -> None: + def test_constructor_value_with_no_marker(self) -> None: """ Checks if constructing Comment without valid marker in passed value would automatically add such marker. @@ -38,10 +38,31 @@ def test_without_marker(self) -> None: comment = Comment(val) self.assertEqual(f'{Config.ALLOWED_COMMENT_MARKERS[0]} {val}', comment.to_string()) + def test_constructor_marker_invalid_value(self) -> None: + """ + Checks if constructing Comment with invalid marker would raise an Error. + """ + marker = self.get_random_string(length = 1) + self.assertNotIn(marker, Config.ALLOWED_COMMENT_MARKERS) + val = self.get_random_string() + with self.assertRaises(ValueError): + Comment(value = val, marker = marker) + + def test_constructor_marker_wrong_type(self) -> None: + """ + Ensures marker type is checked. + """ + with self.assertRaises(TypeError): + # Marker must be a string or TypeError is expected. + # noinspection PyTypeChecker + Comment(value = '', marker = 123) + def test_empty_value(self) -> None: comment = Comment('') self.assertEqual(Config.ALLOWED_COMMENT_MARKERS[0], comment.to_string()) + # ################################################################################################# + def test_to_string(self) -> None: config = Config() for marker in config.ALLOWED_COMMENT_MARKERS: diff --git a/tests/prop/test_translation.py b/tests/prop/test_translation.py index f93b06d..86356b8 100644 --- a/tests/prop/test_translation.py +++ b/tests/prop/test_translation.py @@ -125,6 +125,17 @@ def test_parse_translation_line_with_valid_entries(self) -> None: self.assertEqual(test.sep, res_sep) self.assertEqual(test.val, res_val) + def test_parse_translation_line_too_short(self) -> None: + """ + Ensures strings too short to form valid translation syntax are skipped + without parse attempt. + """ + max_len = Translation.MIN_LINE_LENGTH - 1 + self.assertGreater(max_len, 0) + line = ' ' * max_len + res = Translation.parse_translation_line(line) + self.assertIsNone(res) + def test_parse_translation_line_invalid_entries(self) -> None: lines = [ '{sep}{val}', diff --git a/tests/report/test_report_group.py b/tests/report/test_report_group.py index 730bfa7..bfa8182 100644 --- a/tests/report/test_report_group.py +++ b/tests/report/test_report_group.py @@ -8,6 +8,10 @@ """ import random +from transtool.config.config import Config + +from transtool.report.report import Report + from transtool.report.group import ReportGroup from transtool.report.items import Error, Warn from tests.test_case import TestCase @@ -82,3 +86,36 @@ def test_add_with_list(self) -> None: rg.add(reports + nones) # None's should be silently skipped self.assertEqual(len(reports), rg.errors + rg.warnings) + + def test_empty_not_empty(self) -> None: + config = Config() + report = Report(config) + + self.assertTrue(report.empty()) + self.assertFalse(report.not_empty()) + + rg = ReportGroup(self.get_random_string('report_group')) + rg.warn(line = None, msg = self.get_random_string('warn')) + + report.add(rg) + + self.assertFalse(report.empty()) + self.assertTrue(report.not_empty()) + + def test_fatal_is_ok(self) -> None: + config = Config() + report = Report(config) + + self.assertTrue(report.is_ok()) + self.assertFalse(report.is_fatal()) + + rg = ReportGroup(self.get_random_string('group')) + report.add(rg, skip_empty = False) + + rg.warn(line = None, msg = self.get_random_string('warn')) + self.assertTrue(report.is_ok()) + self.assertFalse(report.is_fatal()) + + rg.error(line = None, msg = self.get_random_string('error')) + self.assertFalse(report.is_ok()) + self.assertTrue(report.is_fatal()) diff --git a/transtool/const.py b/transtool/const.py index 2146381..bc6ddd1 100644 --- a/transtool/const.py +++ b/transtool/const.py @@ -12,7 +12,7 @@ class Const(object): APP_NAME: str = 'trans-tool' - APP_VERSION: str = '2.2.0' + APP_VERSION: str = '2.2.1' APP_URL: str = 'https://github.com/MarcinOrlowski/trans-tool/' APP_DESCRIPTION: List[str] = [ diff --git a/transtool/prop/items.py b/transtool/prop/items.py index d99e6ea..e714839 100644 --- a/transtool/prop/items.py +++ b/transtool/prop/items.py @@ -31,6 +31,8 @@ class Translation(PropItem): Class representing a translation entry. """ + MIN_LINE_LENGTH = 2 + def __init__(self, key: str, value: Union[str, None] = None, separator: str = '=') -> None: if not key: raise ValueError('No empty key allowed.') @@ -58,7 +60,7 @@ def to_string(self) -> str: @staticmethod def parse_translation_line(line: str) -> Union[Tuple[str, str, str], None]: # Min two chars (one letter key and separator) - if len(line) < 2: + if len(line) < Translation.MIN_LINE_LENGTH: return None # Find used separator first @@ -105,10 +107,12 @@ class Comment(PropItem): def __init__(self, value: str = '', marker: str = None) -> None: if not marker: marker = Config.ALLOWED_COMMENT_MARKERS[0] + if not isinstance(marker, str): + raise TypeError('Marker must be a string.') if marker not in Config.ALLOWED_COMMENT_MARKERS: raise ValueError(f'Invalid comment marker: "{marker}".') if not isinstance(value, str): - raise ValueError('Value must be a string.') + raise TypeError('Value must be a string.') if not value: value = f'{marker}' diff --git a/transtool/report/report.py b/transtool/report/report.py index 7878468..c42563e 100644 --- a/transtool/report/report.py +++ b/transtool/report/report.py @@ -44,8 +44,6 @@ def is_ok(self) -> bool: def is_fatal(self) -> bool: """ Helper to determine if report contains fatal errors. - - :return: """ cnt = self.errors if self.config.fatal: