cli main help test
parent
2b158c8b5f
commit
e823fce1f5
|
@ -4,6 +4,6 @@ from datetime import datetime
|
|||
|
||||
@dataclass(frozen=True)
|
||||
class SelectorDTO:
|
||||
type: str
|
||||
date: datetime
|
||||
amount: float
|
||||
type: str | None = None
|
||||
date: datetime | None = None
|
||||
amount: float | None = None
|
||||
|
|
|
@ -44,5 +44,5 @@ class JsonExpenseGateway(ExpenseGateway):
|
|||
if date is not None:
|
||||
result = [x for x in result if x.date == date]
|
||||
if amount is not None:
|
||||
result = [x for x in result if x.amount == amount]
|
||||
result = [x for x in result if x.amount.value == amount.value]
|
||||
return result
|
||||
|
|
|
@ -25,10 +25,10 @@ def get_select_parser(subparser: argparse._SubParsersAction) -> argparse.Argumen
|
|||
help="Select expenses by date",
|
||||
)
|
||||
select_parser.add_argument(
|
||||
"-p",
|
||||
"--price",
|
||||
"-a",
|
||||
"--amount",
|
||||
type=float,
|
||||
help="Select expenses by price",
|
||||
help="Select expenses by amount",
|
||||
)
|
||||
select_parser.add_argument(
|
||||
"-t",
|
||||
|
@ -68,6 +68,41 @@ def get_add_parser(subparser: argparse._SubParsersAction) -> argparse.ArgumentPa
|
|||
return add_parser
|
||||
|
||||
|
||||
def get_update_parser(subparser: argparse._SubParsersAction) -> argparse.ArgumentParser:
|
||||
add_parser = subparser.add_parser(name="add", help="Add new expense")
|
||||
add_parser.add_argument(
|
||||
"-i",
|
||||
"--id",
|
||||
type=int,
|
||||
help="Expense id",
|
||||
)
|
||||
add_parser.add_argument(
|
||||
"-t",
|
||||
"--type",
|
||||
type=str,
|
||||
help="Expense type. Available values: income, expense",
|
||||
)
|
||||
add_parser.add_argument(
|
||||
"-d",
|
||||
"--date",
|
||||
type=datetime.datetime.fromisoformat,
|
||||
help="Expense date",
|
||||
)
|
||||
add_parser.add_argument(
|
||||
"-a",
|
||||
"--amount",
|
||||
type=float,
|
||||
help="Expense price",
|
||||
)
|
||||
add_parser.add_argument(
|
||||
"-D",
|
||||
"--description",
|
||||
type=str,
|
||||
help="Expense description",
|
||||
)
|
||||
return add_parser
|
||||
|
||||
|
||||
def provide_parser() -> argparse.ArgumentParser:
|
||||
parser = argparse.ArgumentParser(description="Cli finance app")
|
||||
subparser = parser.add_subparsers(title="Availeble commands", dest="command")
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
import sys
|
||||
from contextlib import nullcontext
|
||||
|
||||
import pytest
|
||||
|
||||
from clifinance.main.app import main
|
||||
|
||||
app = "src/clifinance/main/app.py"
|
||||
|
||||
main_help_out = [
|
||||
"usage:",
|
||||
"app.py",
|
||||
"[-h]",
|
||||
"{balance,select,add}",
|
||||
"...",
|
||||
"Cli",
|
||||
"finance",
|
||||
"app",
|
||||
"options:",
|
||||
"-h,",
|
||||
"--help",
|
||||
"show",
|
||||
"this",
|
||||
"help",
|
||||
"message",
|
||||
"and",
|
||||
"exit",
|
||||
"Availeble",
|
||||
"commands:",
|
||||
"{balance,select,add}",
|
||||
"balance",
|
||||
"Get",
|
||||
"balance",
|
||||
"select",
|
||||
"Get",
|
||||
"expenses",
|
||||
"by",
|
||||
"filter",
|
||||
"add",
|
||||
"Add",
|
||||
"new",
|
||||
"expense",
|
||||
]
|
||||
|
||||
main_help_testdata = [
|
||||
(app, "-h", nullcontext(main_help_out)),
|
||||
(app, "--help", nullcontext(main_help_out)),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("app, arg, expectation", main_help_testdata)
|
||||
def test_main_help(capsys, app, arg, expectation):
|
||||
with expectation as e:
|
||||
sys.argv = [app, arg]
|
||||
|
||||
with pytest.raises(SystemExit) as excinfo:
|
||||
main()
|
||||
|
||||
out, err = capsys.readouterr()
|
||||
|
||||
assert excinfo.value.code == 0
|
||||
assert err == ""
|
||||
assert out.split() == e
|
Loading…
Reference in New Issue