-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.py
77 lines (68 loc) · 2.09 KB
/
tests.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import pytest
import dash_html_components as html
import pandas as pd
from generators import generate_table, generate_europe_map, generate_world_map
from app import DATA_UN, DATA_EU
df = pd.read_csv('data/{}'.format(DATA_UN))
dfeu = pd.read_csv('data/{}'.format(DATA_EU))
filtered_df = pd.DataFrame(df[df.Year == 2018], columns=['Czech name', 'eGov index']).reset_index()
# checks if the generate table function raises an exception when passed something else than a dataframe
@pytest.mark.parametrize(
"dataframe,max_rows",
[
(filtered_df, 10),
("not a dataframe", "hoho")
])
def test_func_table(dataframe, max_rows):
if isinstance(dataframe, pd.DataFrame):
try:
generate_table(dataframe, 10)
assert True
except Exception:
assert False
else:
try:
generate_table(dataframe, 10)
assert False
except Exception:
assert True
# checks if the generate worldmap function raises an exception when passed something else than a valid year
@pytest.mark.parametrize(
"dataframe,year",
[
(df, 2018),
("not a dataframe", "hoho")
])
def test_func_worldmap(dataframe, year):
if isinstance(year, int):
try:
generate_world_map(dataframe, year)
assert True
except Exception:
assert False
else:
try:
generate_world_map(dataframe, year)
assert False
except Exception:
assert True
# checks if the generate europemap function raises an exception when passed something else than a dataframe
@pytest.mark.parametrize(
"dataframe,year",
[
(dfeu, 2018),
("not a dataframe", "hoho")
])
def test_func_euromap(dataframe, year):
if isinstance(dataframe, pd.DataFrame):
try:
generate_europe_map(dataframe, year)
assert True
except Exception:
assert False
else:
try:
generate_europe_map(dataframe, year)
assert False
except Exception:
assert True