Repository navigation
Expand file tree
/
Copy pathtest_get_data.py
More file actions
99 lines (95 loc) · 2.58 KB
/
Copy pathtest_get_data.py
File metadata and controls
99 lines (95 loc) · 2.58 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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
'''
Test that formatting the raw data is working properly.
'''
from get_data import format_data
FORMAT_DATA_CASE = [
# Check that a standard return from Wikipedia is formatted properly. Wikipedia consistently
# returns the data in this exact format, so other tests aren't necessary.
[
{
'pageid': 1938,
'ns': 0,
'title': 'Andrew Carnegie',
'pageviews': {
'2021-02-08': 3218,
'2021-02-09': 9644, # etc etc
}
},
{
'pageid': 3747,
'ns': 0,
'title': 'Bill Gates',
'linkshere': [
{
'pageid': 663,
'ns': 0,
'title': 'Apollo 8',
'redirect': False
},
{
'pageid': 675,
'ns': 0,
'title': 'Affirming the consequent',
'redirect': False
},
]
},
{
'pageid': 11857,
'ns': 0,
'title': 'George Lucas'
},
{
'pageid': 14059,
'ns': 0,
'title': 'Howard Hughes'
}
],
{
'Andrew Carnegie':
{
'linkshere': [],
'pageviews':
{
'2021-02-08': 3218,
'2021-02-09': 9644
},
'pageid': 1938,
'total_views': 12862,
'linkshere_within_category': []
},
'Bill Gates':
{
'linkshere': ['Apollo 8', 'Affirming the consequent'],
'pageviews': {},
'pageid': 3747,
'total_views': 0,
'linkshere_within_category': []
},
'George Lucas':
{
'linkshere': [],
'pageviews': {},
'pageid': 11857,
'total_views': 0,
'linkshere_within_category': []
},
'Howard Hughes':
{
'linkshere': [],
'pageviews': {},
'pageid': 14059,
'total_views': 0,
'linkshere_within_category': []
}
}
]
# @pytest.mark.parametrize('raw_dict,formatted_dict', FORMAT_DATA_CASES)
def test_format_data():
'''
Check that the function format_data works properly.
Args:
raw_dict: A dictionary representing raw output from the wikipedia API.
formatted_dict: A properly formatted/filtered dataset.
'''
assert format_data(FORMAT_DATA_CASE[0]) == FORMAT_DATA_CASE[1]