-
Notifications
You must be signed in to change notification settings - Fork 15
/
test_json_writer.py
68 lines (58 loc) · 2.1 KB
/
test_json_writer.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
""" Test the write_to_json function in json_writer.py. """
import json
import os
import unittest
from contributor_stats import ContributorStats
from json_writer import write_to_json
class TestWriteToJson(unittest.TestCase):
"""Test the write_to_json function."""
def setUp(self):
"""Set up data for the tests."""
self.filename = "test.json"
self.data = {
"start_date": "2022-01-01",
"end_date": "2022-01-31",
"organization": "test_org",
"repository_list": ["repo1", "repo2"],
"sponsor_info": False,
"link_to_profile": False,
"contributors": [
{
"username": "test_user",
"new_contributor": False,
"avatar_url": "https://test_url.com",
"contribution_count": 10,
"commit_url": "https://test_commit_url.com",
"sponsor_info": "",
}
],
}
def test_write_to_json(self):
"""Test that write_to_json writes the correct data to a JSON file."""
contributors = (
ContributorStats(
username="test_user",
new_contributor=False,
avatar_url="https://test_url.com",
contribution_count=10,
commit_url="https://test_commit_url.com",
sponsor_info="",
),
)
write_to_json(
contributors=contributors,
filename=self.filename,
start_date=self.data["start_date"],
end_date=self.data["end_date"],
organization=self.data["organization"],
repository_list=self.data["repository_list"],
sponsor_info=self.data["sponsor_info"],
link_to_profile=self.data["link_to_profile"],
)
with open(self.filename, "r", encoding="utf-8") as f:
result = json.load(f)
self.assertDictEqual(result, self.data)
def tearDown(self):
os.remove(self.filename)
if __name__ == "__main__":
unittest.main()