コード例 #1
0
    def test_binary(self):
        postfix = 'x or y'
        result = expression.build_expression(postfix)
        query = Or((RegexQuery.from_string('y'),
                    RegexQuery.from_string('x')))

        assert result == query

        postfix = 'x and y'
        result = expression.build_expression(postfix)
        query = And((RegexQuery.from_string('y'),
                     RegexQuery.from_string('x')))

        assert result == query
コード例 #2
0
ファイル: print.py プロジェクト: rafacastillol/ledgeroni
def print_transactions(ctx, filter_strs):
    "`ledgeroni print` subcommand"
    filter_query = MATCH_ALL
    if filter_strs:
        filter_query = expression.build_expression(' '.join(filter_strs))

    sorter = ctx.obj.get('SORTER', None)
    journal = Journal()
    price_db = ctx.obj.get('PRICE_DB', None)
    if price_db:
        journal.add_from_file(price_db)

    for filename in ctx.obj.get('LEDGER_FILES', []):
        journal.add_from_file(filename)

    errors = journal.verify_transaction_balances()
    if errors:
        for error in errors:
            errstr = 'ERROR! Transaction unbalanced: {}'.format(error.header)
            click.echo(errstr, err=True)
        sys.exit(1)

    if sorter:
        sorter.sort_journal(journal)

    click.echo('\n\n'.join(
        t.as_journal_format()
        for t in journal.transactions_matching(filter_query)))
コード例 #3
0
    def test_implicit_or(self):
        postfix = 'x y'
        result = expression.build_expression(postfix)
        query = Or((RegexQuery.from_string('y'),
                    RegexQuery.from_string('x')))

        assert result == query
コード例 #4
0
ファイル: balance.py プロジェクト: rafacastillol/ledgeroni
def print_balance(ctx, filter_strs):
    "`ledger balance` subcommand"
    filter_query = MATCH_ALL
    if filter_strs:
        filter_query = expression.build_expression(' '.join(filter_strs))
    journal = Journal()

    aggregate = AccountAggregate(query=filter_query)

    price_db = ctx.obj.get('PRICE_DB', None)
    if price_db:
        journal.add_from_file(price_db)

    for filename in ctx.obj.get('LEDGER_FILES', []):
        journal.add_from_file(filename)

    errors = journal.verify_transaction_balances()
    if errors:
        for error in errors:
            errstr = 'ERROR! Transaction unbalanced: {}'.format(error.header)
            click.echo(errstr, err=True)
        sys.exit(1)

    aggregate.add_from_journal(journal)

    balances = list(aggregate.iter_aggregates())
    _, _, total = balances[0]
    balances = balances[1:]
    for level, name, aggregate in balances:
        lvlstr = '\n'.join(format_amount(c, a)
                           for c, a in aggregate.items())
        lvlstr += '  ' * level + Fore.BLUE + name + Style.RESET_ALL
        click.echo(lvlstr)
    if len(balances) > 1:
        click.echo('-' * 20)
        totalstr = '\n'.join(format_amount(c, a)
                             for c, a in total.items())
        click.echo(totalstr)
コード例 #5
0
    def test_single(self):
        postfix = 'x'
        result = expression.build_expression(postfix)
        query = RegexQuery.from_string('x')

        assert result == query
コード例 #6
0
    def test_unary(self):
        postfix = 'not x'
        result = expression.build_expression(postfix)
        query = Not(RegexQuery.from_string('x'))

        assert result == query