Repository navigation
Expand file tree
/
Copy pathtest_reading_functions.py
More file actions
52 lines (41 loc) · 3.04 KB
/
Copy pathtest_reading_functions.py
File metadata and controls
52 lines (41 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import pytest
import pandas as pd
import src
from src.global_vars import test_path_list, TEST_INPUT_PATH, groups
from src.reading_functions import create_customer_frequencies, create_recipes_dictionary, \
read_all_customers, create_customer_rules
# test data and parameters
functions_returning_dataframes = ["read_primi", "read_secondi", "read_contorni", "read_recipe_ingredients",
"read_recipe_groups", "read_recipe_courses", "read_frequencies",
"read_rules", "create_customer_frequencies"]
functions_returning_lists = ["read_ingredients_list", "read_customer", "read_all_customers", "create_ingredients_list",
"create_recipes_dictionary", "create_customer_rules"]
test_recipes = ['Pasta al tonno', 'Arrosto di manzo', 'Cavolfiori lessi']
test_dicts = [{'Portata': ['primo'], 'Gruppi': ['carboidrati', 'pesce'], 'Ingredienti': ['pasta', 'pomodoro',
'tonno', 'olio']},
{'Portata': ['secondo'], 'Gruppi': ['carne'], 'Ingredienti': ['manzo', 'olio', 'sale', 'vino rosso',
'salvia']},
{'Portata': ['contorno'], 'Gruppi': ['ortaggi'], 'Ingredienti': ['cavolfiori', 'olio', 'prezzemolo',
'sale']}]
customers = read_all_customers(test_path_list)
customers_dicts = [{'verdure a foglia': 'ortaggi'},
{'cereali': 'carboidrati'},
{'latticini': 'carne'}]
frequency_dataframes = [pd.DataFrame({"Gruppo": groups, "Frequenza": [2, 2, 2, 2, 2, 4, 2, 0]}),
pd.DataFrame({"Gruppo": groups, "Frequenza": [4, 2, 0, 2, 2, 2, 2, 2]}),
pd.DataFrame({"Gruppo": groups, "Frequenza": [2, 4, 2, 0, 2, 2, 2, 2]})]
@pytest.mark.parametrize("df_function", functions_returning_dataframes)
def test_emptiness_of_dataframes(df_function):
assert not getattr(src.reading_functions, df_function)().empty
@pytest.mark.parametrize("list_function", functions_returning_lists)
def test_emptiness_of_lists(list_function):
assert getattr(src.reading_functions, list_function)()
@pytest.mark.parametrize("test_recipe, test_dict", zip(test_recipes, test_dicts))
def test_create_recipes_dictionary(test_recipe, test_dict):
assert create_recipes_dictionary(TEST_INPUT_PATH)[test_recipe] == test_dict
@pytest.mark.parametrize("customer_path, customer_dict", zip(test_path_list, customers_dicts))
def test_create_customer_rules(customer_path, customer_dict):
assert create_customer_rules(TEST_INPUT_PATH, customer_path) == customer_dict
@pytest.mark.parametrize("customer, frequency_dataframe", zip(test_path_list, frequency_dataframes))
def test_create_customer_frequencies_(customer, frequency_dataframe):
pd.testing.assert_frame_equal(create_customer_frequencies(TEST_INPUT_PATH, customer), frequency_dataframe)