Beispiel #1
0
def test_get_average():
    acc_data = AccountData(data_path1)
    total_expenses = sum([data[1] for data in acc_data.get_data()])
    days = (acc_data.get_data()[-1][0] - acc_data.get_data()[0][0]).days + 1

    assert (acc_data.get_average("Day") == total_expenses / days)
    assert (acc_data.get_average("Week") == sum(
        [data[1] for data in acc_data.get_data()[1:-1]]) / 3)
Beispiel #2
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)
Beispiel #3
0
def test_get_average__empty():
    #Should return 0 if there is no data
    acc_data = AccountData(data_path1, tag_nested_path)
    acc_data.filter_data("tags", "==", "Non-existing")
    assert (acc_data.get_average("Day") == 0)