Skip to content

Commit

Permalink
fails: теперь не можем протестировать bx post через СliRunner
Browse files Browse the repository at this point in the history
  • Loading branch information
epogrebnyak committed Jan 13, 2024
1 parent 2c334d0 commit 4bd12e8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
8 changes: 4 additions & 4 deletions abacus/typer_cli/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@

from .post import postx


@app.callback()
def callback():
"""
Typer app, including Click subapp
"""


@app.command()
def init(company_name: Optional[str] = None, overwrite: bool = False):
from abacus.typer_cli.chart import init as chart_init
Expand All @@ -34,9 +36,6 @@ def init(company_name: Optional[str] = None, overwrite: bool = False):
sys.exit(exit_code)





@app.command()
def report(
balance_sheet: Annotated[
Expand Down Expand Up @@ -75,5 +74,6 @@ def unlink(
else:
...


combined_typer_click_app = typer.main.get_command(app)
combined_typer_click_app.add_command(postx, "post")
combined_typer_click_app.add_command(postx, "post")
4 changes: 3 additions & 1 deletion abacus/typer_cli/post.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import click


@click.command(name="post")
@click.option("--entry", type=(str, str, int), multiple=True)
@click.option("--debit", type=(str, int), multiple=True)
Expand All @@ -11,8 +12,9 @@ def postx(entry, debit, credit, strict):
print(debit)
print(credit)
print(strict)


# chart = get_chart()
# store = get_store()
# entries = CompoundEntry(debits=debit, credits=credit).to_entries(chart.null_account)
# store.append_many(entries)

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extend-exclude=["minimal.py"]
[tool.poetry]
name = "abacus-py"
version = "0.8.6"
description = "A minimal, yet valid double-entry accounting system in Python."
description = "A minimal yet valid double-entry accounting system in Python."
authors = ["Evgeniy Pogrebnyak <[email protected]>"]
readme = "README.md"
packages = [
Expand Down
16 changes: 14 additions & 2 deletions tests/test_typer_cli.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from dataclasses import dataclass
from dataclasses import dataclass, field
from pathlib import Path
from shlex import split

import pytest
from typer.testing import CliRunner

from abacus.typer_cli import app
from abacus.typer_cli.app import combined_typer_click_app as app
from abacus.typer_cli.base import UserChartCLI
from abacus.user_chart import AccountLabel, T

Expand Down Expand Up @@ -108,11 +108,16 @@ def test_script_as_setting(setting):
class Line:
script: str
comment: str | None = None
stdout_contains: list[str] = field(default_factory=list)

@property
def args(self):
return split(self.script)

def prints(self, s: str):
self.stdout_contains.append(s)
return self


class HappyLine(Line):
...
Expand All @@ -136,6 +141,10 @@ def all_happy(script: str):
[HappyLine("ledger init")],
[SadLine("ledger unlink --yes")],
[HappyLine("ledger init"), HappyLine("ledger unlink --yes")],
[HappyLine(
"post --entry asset:cash capital:eq 1000 --credit income:sales 50 --credit liability:vat 10 --debit asset:ar 60 --strict"
).prints("True").prints("income:sales")
],
all_happy(
"""
chart init
Expand All @@ -159,6 +168,9 @@ def test_by_line(lines):
assert result.exit_code == 0
case SadLine(_, _):
assert result.exit_code == 1
if line.stdout_contains:
for s in line.stdout_contains:
assert s in result.stdout


@pytest.mark.cli
Expand Down

0 comments on commit 4bd12e8

Please sign in to comment.