-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_spd.py
66 lines (57 loc) · 1.99 KB
/
test_spd.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
import json
from spd import write_csv, plot, _clean_data
TEST_JSON = [
{
"name": "nottoday satan",
"email": "[email protected]",
"class_": "DEA",
"profile_url": "https://codechalleng.es/profiles/nottodaysatan",
"newbie_completed": 3,
"intro_completed": 1,
"regular_completed": 3,
"certificates": "",
},
{
"name": "nottoday satan",
"email": "[email protected]",
"class_": "period 2",
"profile_url": "https://codechalleng.es/profiles/nottodaysatan",
"newbie_completed": 2,
"intro_completed": 8,
"regular_completed": 1,
"certificates": "",
},
]
TEST_CSV = """
name,email,class_,profile_url,newbie_completed,intro_completed,regular_completed,certificates
nottoday satan,[email protected],DEA,https://codechalleng.es/profiles/nottodaysatan,3,1,3,
nottoday satan,[email protected],period 2,https://codechalleng.es/profiles/nottodaysatan,2,8,1,
"""
def test_csv_writer(tmp_path):
d = tmp_path / "testing_dir"
d.mkdir()
json_file = "test_data.json"
with open(d / json_file, "w") as f:
json.dump(TEST_JSON, f)
write_csv(location=d, json_file=json_file, csv_file="testing.csv")
assert (d / "testing.csv").is_file()
def test_plot(tmp_path, capfd):
d = tmp_path / "testing_dir"
d.mkdir()
csv_file = "test_csv.csv"
with open(d / csv_file, "w") as f:
f.write(TEST_CSV.strip("\n"))
plot(location=d, csv_file=csv_file)
output = capfd.readouterr()[0].strip()
assert "period 2" in output
def test_clean_data(tmp_path):
d = tmp_path / "testing_dir"
d.mkdir()
csv_file = "test_csv.csv"
with open(d / csv_file, "w") as f:
f.write(TEST_CSV.strip("\n"))
testing_data = _clean_data(d / csv_file)
assert len(testing_data) == 1 # filters out the DEA
assert (
testing_data.iloc[0]["total_completed"] == 11
) # does the correct assinment for df.total_completed