示例#1
0
def test_fava_options(load_doc):
    """
    2016-06-14 custom "fava-option" "default-file"
    2016-06-14 custom "fava-option" "interval" "week"
    2016-04-14 custom "fava-option" "show-closed-accounts" "true"
    2016-04-14 custom "fava-option" "journal-show" "transaction open"
    2016-04-14 custom "fava-option" "currency-column" "10"
    2016-04-14 custom "fava-option" "insert-entry" "Ausgaben:Test"
    2016-04-14 custom "fava-option" "invalid"
    """

    entries, _, _ = load_doc
    options, errors = parse_options(entries)

    assert len(errors) == 1

    assert options['interval'] == 'week'
    assert options['insert-entry'] == [
        InsertEntryOption(
            datetime.date(2016, 4, 14),
            re.compile('Ausgaben:Test'),
            '<string>',
            7,
        )
    ]
    assert options['show-closed-accounts']
    assert options['journal-show'] == ['transaction', 'open']
    assert options['currency-column'] == 10
示例#2
0
def test_fava_options(load_doc):
    """
    2016-06-14 custom "fava-option" "default-file"
    2016-06-14 custom "fava-option" "interval" "week"
    2016-04-14 custom "fava-option" "show-closed-accounts" "true"
    2016-04-14 custom "fava-option" "journal-show" "transaction open"
    2016-04-14 custom "fava-option" "currency-column" "10"
    2016-04-14 custom "fava-option" "insert-entry" "Ausgaben:Test"
    2016-04-14 custom "fava-option" "invalid"
    2016-06-14 custom "fava-option" "conversion" "USD"
    """

    entries, _, _ = load_doc
    options, errors = parse_options(entries)

    assert len(errors) == 1

    assert options["interval"] == "week"
    assert options["insert-entry"] == [
        InsertEntryOption(
            datetime.date(2016, 4, 14),
            re.compile("Ausgaben:Test"),
            "<string>",
            7,
        )
    ]
    assert options["show-closed-accounts"]
    assert options["journal-show"] == ["transaction", "open"]
    assert options["currency-column"] == 10
    assert options["conversion"] == "USD"
示例#3
0
def test_fava_options(load_doc: LoaderResult) -> None:
    """
    2016-06-14 custom "fava-option" "default-file"
    2016-04-14 custom "fava-option" "show-closed-accounts" "true"
    2016-04-14 custom "fava-option" "currency-column" "10"
    2016-04-14 custom "fava-option" "indent" "4"
    2016-04-14 custom "fava-option" "insert-entry" "Ausgaben:Test"
    2016-04-14 custom "fava-option" "invalid"
    2016-04-14 custom "fava-option" "locale" "en"
    2016-04-14 custom "fava-option" "locale" "invalid"
    2016-04-14 custom "fava-option" "collapse-pattern" "Account:Name"
    2016-04-14 custom "fava-option" "collapse_pattern" "(invalid"
    2016-04-14 custom "fava-option" "fiscal-year-end" "01-11"
    2016-04-14 custom "fava-option" "conversion-currencies" "USD EUR HOOLI"
    """

    entries, _, _ = load_doc
    options, errors = parse_options(entries)  # type: ignore

    assert len(errors) == 3

    assert options.indent == 4
    assert options.insert_entry == [
        InsertEntryOption(
            datetime.date(2016, 4, 14),
            re.compile("Ausgaben:Test"),
            "<string>",
            6,
        )
    ]
    assert options.show_closed_accounts
    assert options.currency_column == 10
    assert options.collapse_pattern == [re.compile("Account:Name")]
    assert options.fiscal_year_end == FiscalYearEnd(1, 11)
    assert options.conversion_currencies == ("USD", "EUR", "HOOLI")
def test_fava_options(load_doc):
    """
    2016-06-14 custom "fava-option" "default-file"
    2016-04-14 custom "fava-option" "show-closed-accounts" "true"
    2016-04-14 custom "fava-option" "journal-show" "transaction open"
    2016-04-14 custom "fava-option" "currency-column" "10"
    2016-04-14 custom "fava-option" "indent" "4"
    2016-04-14 custom "fava-option" "insert-entry" "Ausgaben:Test"
    2016-04-14 custom "fava-option" "invalid"
    2016-04-14 custom "fava-option" "locale" "en"
    2016-04-14 custom "fava-option" "locale" "invalid"
    2016-04-14 custom "fava-option" "collapse-pattern" "Account:Name"
    2016-04-14 custom "fava-option" "collapse-pattern" "(invalid"
    2016-04-14 custom "fava-option" "fiscal-year-end" "01-11"
    """

    entries, _, _ = load_doc
    options, errors = parse_options(entries)

    assert len(errors) == 3

    assert options["indent"] == 4
    assert options["insert-entry"] == [
        InsertEntryOption(
            datetime.date(2016, 4, 14),
            re.compile("Ausgaben:Test"),
            "<string>",
            7,
        )
    ]
    assert options["show-closed-accounts"]
    assert options["journal-show"] == ["transaction", "open"]
    assert options["currency-column"] == 10
    assert options["collapse-pattern"] == [re.compile("Account:Name")]
    assert options["fiscal-year-end"] == FiscalYearEnd(1, 11)
示例#5
0
def test_insert_entry_transaction(tmp_path) -> None:
    file_content = dedent(
        """\
        2016-02-26 * "Uncle Boons" "Eating out alone"
            Liabilities:US:Chase:Slate                       -24.84 USD
            Expenses:Food:Restaurant                          24.84 USD
        """
    )
    samplefile = tmp_path / "example.beancount"
    samplefile.write_text(file_content)

    postings = [
        Posting(
            "Liabilities:US:Chase:Slate",
            A("-10.00 USD"),
            None,
            None,
            None,
            None,
        ),
        Posting("Expenses:Food", A("10.00 USD"), None, None, None, None),
    ]

    transaction = Transaction(
        {}, date(2016, 1, 1), "*", "new payee", "narr", None, None, postings,
    )

    # Test insertion without "insert-entry" options.
    insert_entry(transaction, str(samplefile), [], 61)
    assert samplefile.read_text("utf-8") == dedent(
        """\
        2016-02-26 * "Uncle Boons" "Eating out alone"
            Liabilities:US:Chase:Slate                       -24.84 USD
            Expenses:Food:Restaurant                          24.84 USD

        2016-01-01 * "new payee" "narr"
          Liabilities:US:Chase:Slate                         -10.00 USD
          Expenses:Food                                       10.00 USD
        """
    )

    # Verify that InsertEntryOptions with dates greater or equal than the
    # transaction dates are ignored.
    options = [
        InsertEntryOption(
            date(2015, 1, 1), re.compile(".*:Food"), str(samplefile), 1,
        ),
        InsertEntryOption(
            date(2015, 1, 2), re.compile(".*:FOOO"), str(samplefile), 1,
        ),
        InsertEntryOption(
            date(2017, 1, 1), re.compile(".*:Food"), str(samplefile), 6,
        ),
    ]
    new_options = insert_entry(
        transaction._replace(narration="narr1"), str(samplefile), options, 61
    )
    assert new_options[0].lineno == 5
    assert new_options[1].lineno == 5
    assert new_options[2].lineno == 10
    assert samplefile.read_text("utf-8") == dedent(
        """\
        2016-01-01 * "new payee" "narr1"
          Liabilities:US:Chase:Slate                         -10.00 USD
          Expenses:Food                                       10.00 USD

        2016-02-26 * "Uncle Boons" "Eating out alone"
            Liabilities:US:Chase:Slate                       -24.84 USD
            Expenses:Food:Restaurant                          24.84 USD

        2016-01-01 * "new payee" "narr"
          Liabilities:US:Chase:Slate                         -10.00 USD
          Expenses:Food                                       10.00 USD
        """
    )

    # Verify that previous postings are matched against InsertEntryOptions when
    # the last posting doesn't match.
    options = [
        InsertEntryOption(
            date(2015, 1, 1), re.compile(".*:Slate"), str(samplefile), 5,
        ),
        InsertEntryOption(
            date(2015, 1, 2), re.compile(".*:FOOO"), str(samplefile), 1,
        ),
    ]
    transaction = transaction._replace(narration="narr2")
    new_options = insert_entry(transaction, str(samplefile), options, 61)
    assert new_options[0].lineno == 9
    assert new_options[1].lineno == 1
    assert samplefile.read_text("utf-8") == dedent(
        """\
        2016-01-01 * "new payee" "narr1"
          Liabilities:US:Chase:Slate                         -10.00 USD
          Expenses:Food                                       10.00 USD

        2016-01-01 * "new payee" "narr2"
          Liabilities:US:Chase:Slate                         -10.00 USD
          Expenses:Food                                       10.00 USD

        2016-02-26 * "Uncle Boons" "Eating out alone"
            Liabilities:US:Chase:Slate                       -24.84 USD
            Expenses:Food:Restaurant                          24.84 USD

        2016-01-01 * "new payee" "narr"
          Liabilities:US:Chase:Slate                         -10.00 USD
          Expenses:Food                                       10.00 USD
        """
    )

    # Verify that preference is given to InsertEntryOptions with later dates in
    # case several of them match a posting.
    options = [
        InsertEntryOption(
            date(2015, 1, 1), re.compile(".*:Food"), str(samplefile), 5,
        ),
        InsertEntryOption(
            date(2015, 1, 2), re.compile(".*:Food"), str(samplefile), 1,
        ),
    ]
    transaction = transaction._replace(narration="narr3")
    insert_entry(transaction, str(samplefile), options, 61)
    assert samplefile.read_text("utf-8") == dedent(
        """\
        2016-01-01 * "new payee" "narr3"
          Liabilities:US:Chase:Slate                         -10.00 USD
          Expenses:Food                                       10.00 USD

        2016-01-01 * "new payee" "narr1"
          Liabilities:US:Chase:Slate                         -10.00 USD
          Expenses:Food                                       10.00 USD

        2016-01-01 * "new payee" "narr2"
          Liabilities:US:Chase:Slate                         -10.00 USD
          Expenses:Food                                       10.00 USD

        2016-02-26 * "Uncle Boons" "Eating out alone"
            Liabilities:US:Chase:Slate                       -24.84 USD
            Expenses:Food:Restaurant                          24.84 USD

        2016-01-01 * "new payee" "narr"
          Liabilities:US:Chase:Slate                         -10.00 USD
          Expenses:Food                                       10.00 USD
        """
    )
示例#6
0
def test_insert_entry_transaction(tmpdir):
    file_content = dedent(
        """
        2016-02-26 * "Uncle Boons" "Eating out alone"
            Liabilities:US:Chase:Slate                       -24.84 USD
            Expenses:Food:Restaurant                          24.84 USD

    """
    )
    samplefile = tmpdir.mkdir("fava_util_file3").join("example.beancount")
    samplefile.write(file_content)

    postings = [
        data.Posting(
            "Liabilities:US:Chase:Slate",
            amount.Amount(D("-10.00"), "USD"),
            None,
            None,
            None,
            None,
        ),
        data.Posting(
            "Expenses:Food",
            amount.Amount(D("10.00"), "USD"),
            None,
            None,
            None,
            None,
        ),
    ]

    transaction = data.Transaction(
        {},
        datetime.date(2016, 1, 1),
        "*",
        "new payee",
        "narr",
        None,
        None,
        postings,
    )

    # Test insertion without "insert-entry" options.
    insert_entry(transaction, [str(samplefile)], {})
    assert samplefile.read() == dedent(
        """
        2016-02-26 * "Uncle Boons" "Eating out alone"
            Liabilities:US:Chase:Slate                       -24.84 USD
            Expenses:Food:Restaurant                          24.84 USD

        2016-01-01 * "new payee" "narr"
          Liabilities:US:Chase:Slate                         -10.00 USD
          Expenses:Food                                       10.00 USD

    """
    )

    # Verify that InsertEntryOptions with dates greater or equal than the
    # transaction dates are ignored.
    options = [
        InsertEntryOption(
            datetime.date(2015, 1, 1),
            re.compile(".*:Food"),
            str(samplefile),
            2,
        ),
        InsertEntryOption(
            datetime.date(2015, 1, 2),
            re.compile(".*:FOOO"),
            str(samplefile),
            2,
        ),
        InsertEntryOption(
            datetime.date(2017, 1, 1),
            re.compile(".*:Food"),
            str(samplefile),
            6,
        ),
    ]
    transaction = transaction._replace(narration="narr1")
    insert_entry(transaction, [str(samplefile)], {"insert-entry": options})
    assert samplefile.read() == dedent(
        """
        2016-01-01 * "new payee" "narr1"
          Liabilities:US:Chase:Slate                         -10.00 USD
          Expenses:Food                                       10.00 USD

        2016-02-26 * "Uncle Boons" "Eating out alone"
            Liabilities:US:Chase:Slate                       -24.84 USD
            Expenses:Food:Restaurant                          24.84 USD

        2016-01-01 * "new payee" "narr"
          Liabilities:US:Chase:Slate                         -10.00 USD
          Expenses:Food                                       10.00 USD

    """
    )

    # Verify that previous postings are matched against InsertEntryOptions when
    # the last posting doesn't match.
    options = [
        InsertEntryOption(
            datetime.date(2015, 1, 1),
            re.compile(".*:Slate"),
            str(samplefile),
            6,
        ),
        InsertEntryOption(
            datetime.date(2015, 1, 2),
            re.compile(".*:FOOO"),
            str(samplefile),
            2,
        ),
    ]
    transaction = transaction._replace(narration="narr2")
    insert_entry(transaction, [str(samplefile)], {"insert-entry": options})
    assert samplefile.read() == dedent(
        """
        2016-01-01 * "new payee" "narr1"
          Liabilities:US:Chase:Slate                         -10.00 USD
          Expenses:Food                                       10.00 USD

        2016-01-01 * "new payee" "narr2"
          Liabilities:US:Chase:Slate                         -10.00 USD
          Expenses:Food                                       10.00 USD

        2016-02-26 * "Uncle Boons" "Eating out alone"
            Liabilities:US:Chase:Slate                       -24.84 USD
            Expenses:Food:Restaurant                          24.84 USD

        2016-01-01 * "new payee" "narr"
          Liabilities:US:Chase:Slate                         -10.00 USD
          Expenses:Food                                       10.00 USD

    """
    )

    # Verify that preference is given to InsertEntryOptions with later dates in
    # case several of them match a posting.
    options = [
        InsertEntryOption(
            datetime.date(2015, 1, 1),
            re.compile(".*:Food"),
            str(samplefile),
            6,
        ),
        InsertEntryOption(
            datetime.date(2015, 1, 2),
            re.compile(".*:Food"),
            str(samplefile),
            2,
        ),
    ]
    transaction = transaction._replace(narration="narr3")
    insert_entry(transaction, [str(samplefile)], {"insert-entry": options})
    assert samplefile.read() == dedent(
        """
        2016-01-01 * "new payee" "narr3"
          Liabilities:US:Chase:Slate                         -10.00 USD
          Expenses:Food                                       10.00 USD

        2016-01-01 * "new payee" "narr1"
          Liabilities:US:Chase:Slate                         -10.00 USD
          Expenses:Food                                       10.00 USD

        2016-01-01 * "new payee" "narr2"
          Liabilities:US:Chase:Slate                         -10.00 USD
          Expenses:Food                                       10.00 USD

        2016-02-26 * "Uncle Boons" "Eating out alone"
            Liabilities:US:Chase:Slate                       -24.84 USD
            Expenses:Food:Restaurant                          24.84 USD

        2016-01-01 * "new payee" "narr"
          Liabilities:US:Chase:Slate                         -10.00 USD
          Expenses:Food                                       10.00 USD

    """
    )
示例#7
0
def test_insert_entry_transaction(tmpdir):
    file_content = dedent("""
        2016-02-26 * "Uncle Boons" "Eating out alone"
            Liabilities:US:Chase:Slate                       -24.84 USD
            Expenses:Food:Restaurant                          24.84 USD

    """)
    samplefile = tmpdir.mkdir("fava_util_file3").join("example.beancount")
    samplefile.write(file_content)

    postings = [
        data.Posting(
            "Liabilities:US:Chase:Slate",
            amount.Amount(D("-10.00"), "USD"),
            None,
            None,
            None,
            None,
        ),
        data.Posting(
            "Expenses:Food",
            amount.Amount(D("10.00"), "USD"),
            None,
            None,
            None,
            None,
        ),
    ]

    transaction = data.Transaction(
        None,
        datetime.date(2016, 1, 1),
        "*",
        "new payee",
        "narr",
        None,
        None,
        postings,
    )

    insert_entry(transaction, [str(samplefile)], {})
    assert samplefile.read() == dedent("""
        2016-02-26 * "Uncle Boons" "Eating out alone"
            Liabilities:US:Chase:Slate                       -24.84 USD
            Expenses:Food:Restaurant                          24.84 USD

        2016-01-01 * "new payee" "narr"
          Liabilities:US:Chase:Slate                         -10.00 USD
          Expenses:Food                                       10.00 USD

    """)

    options = [
        InsertEntryOption(
            datetime.date(2015, 1, 1),
            re.compile(".*:Food"),
            str(samplefile),
            2,
        ),
        InsertEntryOption(
            datetime.date(2015, 1, 2),
            re.compile(".*:FOOO"),
            str(samplefile),
            2,
        ),
        InsertEntryOption(
            datetime.date(2017, 1, 1),
            re.compile(".*:Food"),
            str(samplefile),
            6,
        ),
    ]
    insert_entry(transaction, [str(samplefile)], {"insert-entry": options})
    assert samplefile.read() == dedent("""
        2016-01-01 * "new payee" "narr"
          Liabilities:US:Chase:Slate                         -10.00 USD
          Expenses:Food                                       10.00 USD

        2016-02-26 * "Uncle Boons" "Eating out alone"
            Liabilities:US:Chase:Slate                       -24.84 USD
            Expenses:Food:Restaurant                          24.84 USD

        2016-01-01 * "new payee" "narr"
          Liabilities:US:Chase:Slate                         -10.00 USD
          Expenses:Food                                       10.00 USD

    """)

    options = [
        InsertEntryOption(
            datetime.date(2015, 1, 1),
            re.compile(".*:Slate"),
            str(samplefile),
            5,
        ),
        InsertEntryOption(
            datetime.date(2015, 1, 2),
            re.compile(".*:FOOO"),
            str(samplefile),
            2,
        ),
    ]
    insert_entry(transaction, [str(samplefile)], {"insert-entry": options})
    assert samplefile.read() == dedent("""
        2016-01-01 * "new payee" "narr"
          Liabilities:US:Chase:Slate                         -10.00 USD
          Expenses:Food                                       10.00 USD
        2016-01-01 * "new payee" "narr"
          Liabilities:US:Chase:Slate                         -10.00 USD
          Expenses:Food                                       10.00 USD


        2016-02-26 * "Uncle Boons" "Eating out alone"
            Liabilities:US:Chase:Slate                       -24.84 USD
            Expenses:Food:Restaurant                          24.84 USD

        2016-01-01 * "new payee" "narr"
          Liabilities:US:Chase:Slate                         -10.00 USD
          Expenses:Food                                       10.00 USD

    """)
示例#8
0
def test_insert_entry_transaction(tmpdir):
    file_content = dedent("""
        2016-02-26 * "Uncle Boons" "Eating out alone"
            Liabilities:US:Chase:Slate                       -24.84 USD
            Expenses:Food:Restaurant                          24.84 USD

    """)
    samplefile = tmpdir.mkdir('fava_util_file3').join('example.beancount')
    samplefile.write(file_content)

    postings = [
        data.Posting('Liabilities:US:Chase:Slate',
                     amount.Amount(D('-10.00'), 'USD'), None, None, None,
                     None),
        data.Posting('Expenses:Food', amount.Amount(D('10.00'), 'USD'), None,
                     None, None, None),
    ]

    transaction = data.Transaction(None, datetime.date(2016, 1, 1), '*',
                                   'new payee', 'narr', None, None, postings)

    insert_entry(transaction, [str(samplefile)], [])
    assert samplefile.read() == dedent("""
        2016-02-26 * "Uncle Boons" "Eating out alone"
            Liabilities:US:Chase:Slate                       -24.84 USD
            Expenses:Food:Restaurant                          24.84 USD

        2016-01-01 * "new payee" "narr"
          Liabilities:US:Chase:Slate  -10.00 USD
          Expenses:Food                10.00 USD

    """)

    options = [
        InsertEntryOption(datetime.date(2015, 1, 1), re.compile('.*:Food'),
                          str(samplefile), 2),
        InsertEntryOption(datetime.date(2015, 1, 2), re.compile('.*:FOOO'),
                          str(samplefile), 2),
        InsertEntryOption(datetime.date(2017, 1, 1), re.compile('.*:Food'),
                          str(samplefile), 6),
    ]
    insert_entry(transaction, [str(samplefile)], options)
    assert samplefile.read() == dedent("""
        2016-01-01 * "new payee" "narr"
          Liabilities:US:Chase:Slate  -10.00 USD
          Expenses:Food                10.00 USD

        2016-02-26 * "Uncle Boons" "Eating out alone"
            Liabilities:US:Chase:Slate                       -24.84 USD
            Expenses:Food:Restaurant                          24.84 USD

        2016-01-01 * "new payee" "narr"
          Liabilities:US:Chase:Slate  -10.00 USD
          Expenses:Food                10.00 USD

    """)

    options = [
        InsertEntryOption(datetime.date(2015, 1, 1), re.compile('.*:Slate'),
                          str(samplefile), 5),
        InsertEntryOption(datetime.date(2015, 1, 2), re.compile('.*:FOOO'),
                          str(samplefile), 2),
    ]
    insert_entry(transaction, [str(samplefile)], options)
    assert samplefile.read() == dedent("""
        2016-01-01 * "new payee" "narr"
          Liabilities:US:Chase:Slate  -10.00 USD
          Expenses:Food                10.00 USD
        2016-01-01 * "new payee" "narr"
          Liabilities:US:Chase:Slate  -10.00 USD
          Expenses:Food                10.00 USD


        2016-02-26 * "Uncle Boons" "Eating out alone"
            Liabilities:US:Chase:Slate                       -24.84 USD
            Expenses:Food:Restaurant                          24.84 USD

        2016-01-01 * "new payee" "narr"
          Liabilities:US:Chase:Slate  -10.00 USD
          Expenses:Food                10.00 USD

    """)