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)
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)
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()