コード例 #1
0
def test_balance_assertions_cannot_mix_with_other_postings_2():
    input = from_triple_quoted_string("""
    2017-01-02 Blah blah
        Expenses:Cash   $40
        Assets:Cash   = $40
    """)
    with pytest.raises(BalanceAssertionTooComplicated):
        translate_file(input)
コード例 #2
0
def test_balance_assertions_cannot_mix_with_other_postings_3():
    """This is more of a bug than a feature"""
    input = from_triple_quoted_string("""
    2017-01-02 Blah blah
        Assets:Cash   $15 = $40
        Expenses:Cash   $-15
    """)
    with pytest.raises(BalanceAssertionTooComplicated):
        translate_file(input)
コード例 #3
0
def test_negative_currency_is_translated():
    """$-40 -> -40 USD, as is -$40"""
    input = from_triple_quoted_string("""
    2017-01-02 An ordinary transaction
        Expenses:Restaurants    $-40
        Assets:Cash

    2017-01-02 Another ordinary transaction
        Expenses:Restaurants    -$40
        Assets:Cash
    """)
    output = translate_file(input)
    assert output == from_triple_quoted_string("""
    * Accounts
    2010-01-01 open Assets:Cash
    2010-01-01 open Expenses:Restaurants
    * Transactions
    2017-01-02 * "An ordinary transaction"
      Expenses:Restaurants        -40 USD
      Assets:Cash

    2017-01-02 * "Another ordinary transaction"
      Expenses:Restaurants        -40 USD
      Assets:Cash
    """)
コード例 #4
0
def test_barf_on_commodities_with_numbers():
    input = from_triple_quoted_string("""
    2/6/2010 An ordinary transaction
        Expenses:Restaurants    40 "PDX4U"
        Assets:Cash
    """)
    with pytest.raises(InvalidCommodityError):
        output = translate_file(input)
コード例 #5
0
def test_allow_balance_assertions_with_zero():
    input = from_triple_quoted_string("""
    2017-01-02 Blah blah
        Assets:Cash   $0 = $40
    """)
    output = translate_file(input)
    assert output == from_triple_quoted_string("""
    * Accounts
    2010-01-01 open Assets:Cash
    * Transactions
    2017-01-02 balance Assets:Cash   40 USD
    """)
コード例 #6
0
def test_comments_are_copied_through():
    input = from_triple_quoted_string("""
    ; Intro comment
    ;; Multi-semicolon comment
        ;; Pre-spaced comment
    """)
    output = translate_file(input)
    assert output == from_triple_quoted_string("""
    * Accounts
    * Transactions
    ; Intro comment
    ;; Multi-semicolon comment
        ;; Pre-spaced comment
    """)
コード例 #7
0
def test_last_transaction_is_handled():
    """Ensure that if EOF happens during a transaction, we handle it"""
    input = from_triple_quoted_string("""
    2017-01-02 An ordinary transaction
        Expenses:Restaurants    40 USD
        Assets:Cash""")
    output = translate_file(input)
    assert output == from_triple_quoted_string("""
    * Accounts
    2010-01-01 open Assets:Cash
    2010-01-01 open Expenses:Restaurants
    * Transactions
    2017-01-02 * "An ordinary transaction"
      Expenses:Restaurants        40 USD
      Assets:Cash""")  # There won't be an extra blank line
コード例 #8
0
def test_lowercase_account_name_is_translated():
    input = from_triple_quoted_string("""
    2017-01-02 An ordinary transaction
        Expenses:eating out    40 USD
        Assets:Cash
    """)
    output = translate_file(input)
    assert output == from_triple_quoted_string("""
    * Accounts
    2010-01-01 open Assets:Cash
    2010-01-01 open Expenses:Xeatingout
    * Transactions
    2017-01-02 * "An ordinary transaction"
      Expenses:Xeatingout        40 USD
      Assets:Cash
    """)
コード例 #9
0
def test_strip_quoted_commodities():
    input = from_triple_quoted_string("""
    2/6/2010 An ordinary transaction
        Expenses:Restaurants    40 "PDX"
        Assets:Cash
    """)
    output = translate_file(input)
    assert output == from_triple_quoted_string("""
    * Accounts
    2010-01-01 open Assets:Cash
    2010-01-01 open Expenses:Restaurants
    * Transactions
    2010-02-06 * "An ordinary transaction"
      Expenses:Restaurants        40 PDX
      Assets:Cash
    """)
コード例 #10
0
def test_payee_quotes_are_translated():
    input = from_triple_quoted_string("""
    2017-01-02 Eating at my "favorite" restaurant
        Expenses:Restaurants    40 USD
        Assets:Cash
    """)
    output = translate_file(input)
    assert output == from_triple_quoted_string("""
    * Accounts
    2010-01-01 open Assets:Cash
    2010-01-01 open Expenses:Restaurants
    * Transactions
    2017-01-02 * "Eating at my \\"favorite\\" restaurant"
      Expenses:Restaurants        40 USD
      Assets:Cash
    """)
コード例 #11
0
def test_dont_transform_price_to_cost_basis_selling():
    input = from_triple_quoted_string("""
    2017-01-02 An ordinary transaction
        Expenses:Restaurants    -40 PDX  @ $1.10
        Assets:Cash
    """)
    output = translate_file(input)
    assert output == from_triple_quoted_string("""
    * Accounts
    2010-01-01 open Assets:Cash
    2010-01-01 open Expenses:Restaurants
    * Transactions
    2017-01-02 * "An ordinary transaction"
      Expenses:Restaurants        -40 PDX @ 1.10 USD
      Assets:Cash
    """)
コード例 #12
0
def test_backwards_commodities_are_OK():
    input = from_triple_quoted_string("""
    2/6/2010 An ordinary transaction
        Expenses:Restaurants    PDX 40 @ $1
        Assets:Cash
    """)
    output = translate_file(input)
    assert output == from_triple_quoted_string("""
    * Accounts
    2010-01-01 open Assets:Cash
    2010-01-01 open Expenses:Restaurants
    * Transactions
    2010-02-06 * "An ordinary transaction"
      Expenses:Restaurants        40 PDX {1 USD}
      Assets:Cash
    """)
コード例 #13
0
def test_fractional_currency_is_translated():
    """$40.12 -> 40.12 USD"""
    input = from_triple_quoted_string("""
    2017-01-02 An ordinary transaction
        Expenses:Restaurants    $40.12
        Assets:Cash
    """)
    output = translate_file(input)
    assert output == from_triple_quoted_string("""
    * Accounts
    2010-01-01 open Assets:Cash
    2010-01-01 open Expenses:Restaurants
    * Transactions
    2017-01-02 * "An ordinary transaction"
      Expenses:Restaurants        40.12 USD
      Assets:Cash
    """)
コード例 #14
0
def test_incomplete_decimals_are_translated():
    """$.12 -> 0.12 USD"""
    input = from_triple_quoted_string("""
    2017-01-02 An ordinary transaction
        Expenses:Restaurants    $.12
        Assets:Cash
    """)
    output = translate_file(input)
    assert output == from_triple_quoted_string("""
    * Accounts
    2010-01-01 open Assets:Cash
    2010-01-01 open Expenses:Restaurants
    * Transactions
    2017-01-02 * "An ordinary transaction"
      Expenses:Restaurants        0.12 USD
      Assets:Cash
    """)
コード例 #15
0
def test_transaction_is_translated():
    """Ensure we use beancount quoted payee syntax and two-space indent"""
    input = from_triple_quoted_string("""
    2017-01-02 An ordinary transaction
        Expenses:Restaurants    40 USD
        Assets:Cash
    """)
    output = translate_file(input)
    assert output == from_triple_quoted_string("""
    * Accounts
    2010-01-01 open Assets:Cash
    2010-01-01 open Expenses:Restaurants
    * Transactions
    2017-01-02 * "An ordinary transaction"
      Expenses:Restaurants        40 USD
      Assets:Cash
    """)
コード例 #16
0
def test_currency_with_pound_sign_is_translated():
    """£40 -> 40 GBP"""
    input = from_triple_quoted_string("""
    2017-01-02 An ordinary transaction
        Expenses:Restaurants    £40
        Assets:Cash
    """)
    output = translate_file(input)
    assert output == from_triple_quoted_string("""
    * Accounts
    2010-01-01 open Assets:Cash
    2010-01-01 open Expenses:Restaurants
    * Transactions
    2017-01-02 * "An ordinary transaction"
      Expenses:Restaurants        40 GBP
      Assets:Cash
    """)
コード例 #17
0
def test_comments_are_preserved_after_statements():
    input = from_triple_quoted_string("""
    2017-01-02 An ordinary transaction   ; Payee comment
        ; Transaction comment
        Expenses:Restaurants    40 USD   ; Posting comment
        Assets:Cash
    """)
    output = translate_file(input)
    assert output == from_triple_quoted_string("""
    * Accounts
    2010-01-01 open Assets:Cash
    2010-01-01 open Expenses:Restaurants
    * Transactions
    2017-01-02 * "An ordinary transaction"   ; Payee comment
      ; Transaction comment
      Expenses:Restaurants        40 USD   ; Posting comment
      Assets:Cash
    """)
コード例 #18
0
def test_flags_are_parsed():
    input = from_triple_quoted_string("""
    2/6/2010 ! An ordinary transaction
        Expenses:Restaurants    $40
        Assets:Cash
    2/6/2010 * A cleared transaction
        Expenses:Restaurants    $40
        Assets:Cash
    """)
    output = translate_file(input)
    assert output == from_triple_quoted_string("""
    * Accounts
    2010-01-01 open Assets:Cash
    2010-01-01 open Expenses:Restaurants
    * Transactions
    2010-02-06 ! "An ordinary transaction"
      Expenses:Restaurants        40 USD
      Assets:Cash
    2010-02-06 * "A cleared transaction"
      Expenses:Restaurants        40 USD
      Assets:Cash
    """)
コード例 #19
0
def test_balance_assertions_can_mix_with_comments():
    input = from_triple_quoted_string("""
    2017-01-02 Blah blah
        ; There are lots of important reasons why this is the balance
        ; at this particular moment in time. For starters, consider
        ; the global economic situation: a strong dollar combined with
        ; general instability
        Assets:Cash   = $40
        ; which doesn't even begin to enter the local, microeconomic factors
        ; such as my personal preference for a certain amount of cash
    """)
    output = translate_file(input)
    assert output == from_triple_quoted_string("""
    * Accounts
    2010-01-01 open Assets:Cash
    * Transactions
    2017-01-02 balance Assets:Cash   40 USD
      ; There are lots of important reasons why this is the balance
      ; at this particular moment in time. For starters, consider
      ; the global economic situation: a strong dollar combined with
      ; general instability
      ; which doesn't even begin to enter the local, microeconomic factors
      ; such as my personal preference for a certain amount of cash
    """)