Exemple #1
0
def test_update__save_load(tmp_path):
    account_data1 = AccountData("./example_data/data1.csv",
                                tag_file="./example_data/tags_nested.json")
    account_data2 = AccountData("./example_data/data2.csv",
                                account_name="other_data")

    summed_account = account_data1 / 2 + account_data2
    summed_account.update("./example_data/data_new.csv", "data1")

    #Save and load should not affect data
    summed_account.save(tmp_path / "account_data.csv")

    summed_account = AccountData(tmp_path / "account_data.csv")

    #Old data
    summed_account.filter_data("date", "==", datetime.date(2021, 1, 1))
    assert (summed_account.get_column("text") == [
        'Lorem Ipsum', 'Lorem Ipsum'
    ])
    summed_account.reset_filter()

    #New data
    summed_account.filter_data("date", "==", datetime.date(2021, 1, 5))
    assert (summed_account.get_column("text") == ['A1', 'SWISH FRÅN Namn'])
    summed_account.reset_filter()

    #Overlapping data should be updated
    summed_account.filter_data("date", "==", datetime.date(2021, 1, 4))
    assert (summed_account.get_column("text") == [
        '201229 A1', '201230 A3 ', '210101 B1', '210102 a4', 'Updated data'
    ])
    summed_account.filter_data("account", "==", "data1")
    assert (summed_account.get_column("amount") == [333.33 / 2])
    summed_account.reset_filter()
Exemple #2
0
def test_filter__date():
    acc_data1 = AccountData(data_path1, cat_path)
    first_date = acc_data1.get_column("date")[0]
    next_date = acc_data1.get_column("date")[1]
    acc_data1.filter_data("date", ">", first_date)

    assert (acc_data1.get_column("date")[0] == next_date)
Exemple #3
0
def test_div():
    acc_data = AccountData(data_path1)
    acc_data_div = acc_data / 2

    assert (sum(acc_data.get_column("amount")) / 2 == sum(
        acc_data_div.get_column("amount")))
    assert (len(acc_data.get_data()) == len(acc_data_div.get_data()))
Exemple #4
0
def test_get_average__filtered():
    acc_data = AccountData(data_path1, tag_path)
    #If we filter by something by other than date, we should still accumulate to the full extent of the data
    acc_data.filter_data("tags", "==", "tag2")
    assert (acc_data.get_average("Day") == sum(acc_data.get_column("amount")) /
            26)
    #If filter by date, accumulate should only be within the filtered dates
    acc_data.reset_filter()
    acc_data.filter_data("date", ">", datetime.date(2020, 12, 13))
    acc_data.filter_data("date", "<=", datetime.date(2020, 12, 20))
    assert (acc_data.get_average("Week") == (1000 + 100 - 25000) / 1)
    #The filter function should detect if the date filter is greater than the data and it should affect the average
    acc_data.reset_filter()
    acc_data.filter_data("date", ">=", datetime.date(2020, 12, 7))
    acc_data.filter_data("date", "<", datetime.date(2020, 12, 23))
    assert (acc_data.get_average("Week") == (1000 + 100 - 25000) / 1)
Exemple #5
0
def test_filter__amount(fun):
    acc_data1 = AccountData(data_path1, cat_path)
    acc_data1.filter_data("amount", fun, 200)
    for amount in acc_data1.get_column("amount"):
        if fun == ">":
            assert (amount > 200)
        elif fun == ">=":
            assert (amount >= 200)
        elif fun == "==":
            assert (amount == 200)
        elif fun == "!=":
            assert (amount != 200)
        elif fun == "<=":
            assert (amount <= 200)
        elif fun == "<":
            assert (amount < 200)
Exemple #6
0
def test_filter__not_tag_empty():
    acc_data = AccountData(data_path1, tag_file=tag_path)
    #Should only return those that has tags
    acc_data.filter_data("tags", "!=", [])
    assert (all(len(tags) > 0 for tags in acc_data.get_column("tags")))