Skip to content
Snippets Groups Projects
Commit 2a64d214 authored by Moul's avatar Moul
Browse files

money transfer --file: Use click.Path() (#469)

parent e364767f
No related branches found
No related tags found
1 merge request!242Use click.Path() #469
......@@ -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:
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment