Skip to content

Commit

Permalink
Merge pull request #57 from MarcinOrlowski/dev
Browse files Browse the repository at this point in the history
Release 2.5.2
  • Loading branch information
MarcinOrlowski authored Sep 14, 2021
2 parents ba01ba9 + f6383b0 commit 894d7a9
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

# Changelog #

* v2.5.2 (2021-09-14)
* Added tests for last line's LF handling.

* v2.5.1 (2021-09-14)
* `--write` now preserves LF of base file's last line (if present).

Expand Down
42 changes: 41 additions & 1 deletion tests/prop/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import copy
import random
from pathlib import Path
from typing import List
from unittest.mock import Mock, mock_open, patch

from transtool.config.builder import ConfigBuilder
Expand Down Expand Up @@ -342,13 +343,52 @@ def test_save_no_target_file(self) -> None:
"""
Checks if save() will fail if no target file name is given nor object's
`file` property is `None`.
:return:
"""
config = Config()
propfile = PropFile(config)
with self.assertRaises(ValueError):
propfile.save()

def test_save_no_trailing_lf(self) -> None:
"""
Ensures that save() will not add any trailing LF as last line
if source data do not end up with empty line.
"""
config = Config()
propfile = PropFile(config)

item = Translation(self.get_random_string('key'), self.get_random_string('value'))
propfile.append(item)

# Check file content is written as expected.
expected = [item.to_string()]

self.do_compare_output_with_saved_content(propfile, expected)

def test_save_trailing_lf_is_saved(self) -> None:
"""
Ensures that save() will do add any trailing LF as last line
if source data ends with empty line.
"""
config = Config()
propfile = PropFile(config)

item = Translation(self.get_random_string('key'), self.get_random_string('value'))
propfile.append(item)
propfile.append(Blank())

# Check file content is written as expected.
expected = [item.to_string(), '']

self.do_compare_output_with_saved_content(propfile, expected)

def do_compare_output_with_saved_content(self, propfile: PropFile, expected: List[str]) -> None:
with patch('builtins.open', mock_open()) as manager:
propfile.save(self.get_random_string())
fh = manager()
# FIXME: LF/CRLF should be configurable
fh.write.assert_called_once_with('\n'.join(expected))

# #################################################################################################

@patch('pathlib.Path.exists')
Expand Down
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.5.1'
APP_VERSION: str = '2.5.2'
APP_URL: str = 'https://github.com/MarcinOrlowski/trans-tool/'

APP_DESCRIPTION: List[str] = [
Expand Down

0 comments on commit 894d7a9

Please sign in to comment.