diff --git a/silkaj/money/transfer.py b/silkaj/money/transfer.py index c5889b1a783b8ddd321bbe7830d5600777c74eec..526cf47d39574f422015255a3e50d63caad6baf4 100644 --- a/silkaj/money/transfer.py +++ b/silkaj/money/transfer.py @@ -105,6 +105,7 @@ Sending to many recipients is possible:\n\ "file_path", "--file", "-f", + type=click.Path(exists=True, dir_okay=False, path_type=Path), help="File`s path containing a list of amounts in absolute or \ relative reference and recipients` pubkeys", cls=tools.MutuallyExclusiveOption, @@ -126,7 +127,7 @@ def transfer_money( amountsud: List[float], allsources: bool, recipients: List[str], - file_path: str, + file_path: Path, comment: str, outputbackchange: str, yes: bool, @@ -196,7 +197,7 @@ No transaction sent.", def parse_file_containing_amounts_recipients( - file_path: str, + file_path: Path, ) -> Tuple[List[int], List[str]]: """ Parse file in a specific format @@ -213,7 +214,7 @@ def parse_file_containing_amounts_recipients( """ reference = "" amounts, recipients = [], [] - with Path(file_path).open(encoding="utf-8") as file: + with file_path.open(encoding="utf-8") as file: for n, raw_line in enumerate(file): line = shlex.split(raw_line, True) if line: diff --git a/tests/unit/money/test_transfer_file.py b/tests/unit/money/test_transfer_file.py index dd1424a50cdb2a3185cf247ec38ec3f9b6c6af29..7556abd9f0c8f586b57971f117c223517ddd56f9 100644 --- a/tests/unit/money/test_transfer_file.py +++ b/tests/unit/money/test_transfer_file.py @@ -24,7 +24,7 @@ from silkaj.money.transfer import parse_file_containing_amounts_recipients from tests.patched.money import patched_get_ud_value from tests.patched.test_constants import mock_ud_value -FILE_PATH = "recipients.txt" +FILE_PATH = Path("recipients.txt") @pytest.mark.parametrize( @@ -52,7 +52,7 @@ def test_parse_file_containing_amounts_recipients( runner = CliRunner() with runner.isolated_filesystem(): - Path(FILE_PATH).write_text(file_content, encoding="utf-8") + FILE_PATH.write_text(file_content, encoding="utf-8") amounts, recipients = parse_file_containing_amounts_recipients(FILE_PATH) assert amounts == amounts_exp assert recipients == recipients_exp @@ -78,7 +78,7 @@ SPEC_ERR = "No amounts or recipients specified" def test_parse_file_containing_amounts_recipients_errors(file_content, error, capsys): runner = CliRunner() with runner.isolated_filesystem(): - Path(FILE_PATH).write_text(file_content, encoding="utf-8") + FILE_PATH.write_text(file_content, encoding="utf-8") with pytest.raises(SystemExit): parse_file_containing_amounts_recipients(FILE_PATH) assert error in capsys.readouterr().out