Exemplo n.º 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)
Exemplo n.º 2
0
def test_reset_filter():
    acc_data1 = AccountData(data_path1, cat_path)
    original_data = acc_data1.get_data()
    acc_data1.filter_data("amount", "==", 1000)
    filtered_data = acc_data1.get_data()
    acc_data1.reset_filter()
    reset_data = acc_data1.get_data()
    assert (original_data == reset_data)
    assert (reset_data != filtered_data)
Exemplo n.º 3
0
def test_add():
    acc_data1 = AccountData(data_path1, tag_nested_path)
    acc_data2 = AccountData(data_path2, tag_nested_path)
    sum_data = acc_data1 + acc_data2

    #Categories should not change since both acc_data use the same tag file, though order may change (so sorting it)
    assert (sorted(list(acc_data1.get_tags())) == sorted(
        list(sum_data.get_tags())))
    #Length of get_data should be the sum of both
    assert (len(sum_data.get_data()) == len(acc_data1.get_data()) +
            len(acc_data2.get_data()))
Exemplo n.º 4
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()))
Exemplo n.º 5
0
def test_get_data__is_sorted():
    #Everything should sorted ascending by the first column (date) after initialization
    acc_data1 = AccountData(data_path1)

    all_data = acc_data1.get_data()
    last_date = all_data[0][0]
    for data in all_data[1:]:
        assert (data[0] >= last_date)
        last_date = data[0]
Exemplo n.º 6
0
def test_filter__empty():
    #If filtering twice with an inverted filter the result should be empty
    acc_data = AccountData(data_path1, cat_path)
    acc_data.filter_data("amount", ">=", 300)
    acc_data.filter_data("amount", "<", 300)
    assert (len(acc_data.get_data()) == 0)
    #Tags should also be empty
    assert (len(acc_data.get_tags()) == 0)
    #It should be possible to still call get_timeseries()
    assert (type(acc_data.get_timeseries()) == TimeSeries)
Exemplo n.º 7
0
def test_get_timeseries__correct_sum():
    #The total expenses should not change
    acc_data1 = AccountData(data_path2)
    sum1 = 0
    for data in acc_data1.get_data():
        sum1 += data[1]
    sum2 = 0
    for data in acc_data1.get_timeseries().data:
        sum2 += data[1]

    assert (sum1 == sum2)
Exemplo n.º 8
0
def test_get_data():
    acc_data1 = AccountData(data_path1)
    #Check that data corresponds to the first entry
    assert (acc_data1.get_data()[0][acc_data1.columns['amount']] == 100)
    #And that lenght is correct
    assert (len(acc_data1.get_data()) == 19)
Exemplo n.º 9
0
def test_filter__tag_empty():
    acc_data = AccountData(data_path1, tag_file=tag_path)
    #Should only return those that lack any tags.
    acc_data.filter_data("tags", "==", [])
    assert (acc_data.get_tags() == [])
    assert (len(acc_data.get_data()) > 0)