Skip to content

Commit

Permalink
Merge pull request #48 from MarcinOrlowski/dev
Browse files Browse the repository at this point in the history
Release 2.2.1
  • Loading branch information
MarcinOrlowski authored Aug 12, 2021
2 parents bfba116 + f74b77d commit 5d3c3c9
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 44 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -83,3 +82,4 @@ Base: src/main/resources/resources/logisim/strings/soc/soc.properties
* Written and copyrighted &copy;2021 by Marcin Orlowski <mail (#) marcinorlowski (.) com>
* 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/).
4 changes: 4 additions & 0 deletions docs/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
72 changes: 36 additions & 36 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '[email protected]',
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 = '[email protected]',
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',
],
)
25 changes: 23 additions & 2 deletions tests/prop/test_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand Down
11 changes: 11 additions & 0 deletions tests/prop/test_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}',
Expand Down
37 changes: 37 additions & 0 deletions tests/report/test_report_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
2 changes: 1 addition & 1 deletion transtool/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = [
Expand Down
8 changes: 6 additions & 2 deletions transtool/prop/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}'

Expand Down
2 changes: 0 additions & 2 deletions transtool/report/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 5d3c3c9

Please sign in to comment.