~trufas/ledgeroni

34d9de19c34e7ad190b2676ee65a517331101b6c — Rafael Castillo 1 year, 9 months ago 97851fc
Fix balance crashing with no filter
2 files changed, 14 insertions(+), 2 deletions(-)

M ledgeroni/commands/balance.py
M tests/integration/test_balance.py
M ledgeroni/commands/balance.py => ledgeroni/commands/balance.py +2 -1
@@ 6,6 6,7 @@ import click
from colorama import Fore, Style

from ledgeroni.journal import Journal
from ledgeroni.query import MATCH_ALL
from ledgeroni.aggregate import AccountAggregate
from ledgeroni.util import format_amount
from ledgeroni import expression


@@ 16,7 17,7 @@ from ledgeroni import expression
@click.pass_context
def print_balance(ctx, filter_strs):
    "`ledger balance` subcommand"
    filter_query = None
    filter_query = MATCH_ALL
    if filter_strs:
        filter_query = expression.build_expression(' '.join(filter_strs))
    journal = Journal(query=filter_query)

M tests/integration/test_balance.py => tests/integration/test_balance.py +12 -1
@@ 18,7 18,7 @@ def test_bal_alias():
        '-f', 'tests/sample_data/index.ledger', '--price-db',
        'tests/sample_data/prices_db', 'bal'])
    assert result.exit_code == 0
    assert "1.50 BTC  Asset:Bitcoin Wallet" in result.output
    assert '1.50 BTC  Asset:Bitcoin Wallet' in result.output


def test_without_ledger():


@@ 27,3 27,14 @@ def test_without_ledger():
    result = runner.invoke(cli, [
        '--price-db', 'tests/sample_data/prices_db', 'balance'])
    assert result.exit_code == 2


def test_filtering():
    "Test posting filtering"
    runner = CliRunner()
    result = runner.invoke(cli, [
        '-f', 'tests/sample_data/index.ledger', '--price-db',
        'tests/sample_data/prices_db', 'bal', 'paypal'])
    assert result.exit_code == 0
    assert 'Bank:Paypal' in result.output
    assert 'income' not in result.output