1010class TestWriteToJson (unittest .TestCase ):
1111 """Tests for the write_to_json function."""
1212
13+ # Show differences without omission in assertion
14+ maxDiff = None
15+
1316 def test_write_to_json (self ):
1417 """Test that write_to_json writes the correct JSON file."""
1518 issues_with_metrics = [
@@ -34,9 +37,27 @@ def test_write_to_json(self):
3437 labels_metrics = {},
3538 ),
3639 ]
37- average_time_to_first_response = timedelta (days = 2.5 )
38- average_time_to_close = timedelta (days = 5 )
39- average_time_to_answer = timedelta (days = 1 )
40+
41+ stats_time_to_first_response = {
42+ "avg" : timedelta (days = 2.5 ),
43+ "med" : timedelta (days = 2.5 ),
44+ "90p" : timedelta (days = 1.5 ),
45+ }
46+ stats_time_to_close = {
47+ "avg" : timedelta (days = 5 ),
48+ "med" : timedelta (days = 4 ),
49+ "90p" : timedelta (days = 3 ),
50+ }
51+ stats_time_to_answer = {
52+ "avg" : timedelta (days = 1 ),
53+ "med" : timedelta (days = 2 ),
54+ "90p" : timedelta (days = 3 ),
55+ }
56+ stats_time_in_labels = {
57+ "avg" : {"bug" : timedelta (days = 1 , hours = 16 , minutes = 24 , seconds = 12 )},
58+ "med" : {"bug" : timedelta (days = 1 , hours = 16 , minutes = 24 , seconds = 12 )},
59+ "90p" : {"bug" : timedelta (days = 1 , hours = 16 , minutes = 24 , seconds = 12 )},
60+ }
4061 num_issues_opened = 2
4162 num_issues_closed = 1
4263
@@ -75,12 +96,90 @@ def test_write_to_json(self):
7596 self .assertEqual (
7697 write_to_json (
7798 issues_with_metrics = issues_with_metrics ,
78- average_time_to_first_response = average_time_to_first_response ,
79- average_time_to_close = average_time_to_close ,
80- average_time_to_answer = average_time_to_answer ,
81- average_time_in_labels = {
82- "bug" : timedelta (days = 1 , hours = 16 , minutes = 24 , seconds = 12 )
99+ stats_time_to_first_response = stats_time_to_first_response ,
100+ stats_time_to_close = stats_time_to_close ,
101+ stats_time_to_answer = stats_time_to_answer ,
102+ stats_time_in_labels = stats_time_in_labels ,
103+ num_issues_opened = num_issues_opened ,
104+ num_issues_closed = num_issues_closed ,
105+ search_query = "is:issue repo:owner/repo" ,
106+ ),
107+ json .dumps (expected_output ),
108+ )
109+
110+ def test_write_to_json_with_no_response (self ):
111+ """Test where there is no answer to a issue."""
112+ issues_with_metrics = [
113+ IssueWithMetrics (
114+ title = "Issue 1" ,
115+ html_url = "https://github.com/owner/repo/issues/1" ,
116+ author = "alice" ,
117+ time_to_first_response = None ,
118+ time_to_close = None ,
119+ time_to_answer = None ,
120+ labels_metrics = {},
121+ ),
122+ IssueWithMetrics (
123+ title = "Issue 2" ,
124+ html_url = "https://github.com/owner/repo/issues/2" ,
125+ author = "bob" ,
126+ time_to_first_response = None ,
127+ time_to_close = None ,
128+ time_to_answer = None ,
129+ labels_metrics = {},
130+ ),
131+ ]
132+
133+ stats_time_to_first_response = None
134+ stats_time_to_close = None
135+ stats_time_to_answer = None
136+ stats_time_in_labels = {
137+ "avg" : {},
138+ "med" : {},
139+ "90p" : {},
140+ }
141+ num_issues_opened = 2
142+ num_issues_closed = 0
143+
144+ expected_output = {
145+ "average_time_to_first_response" : "None" ,
146+ "average_time_to_close" : "None" ,
147+ "average_time_to_answer" : "None" ,
148+ "average_time_in_labels" : {},
149+ "num_items_opened" : 2 ,
150+ "num_items_closed" : 0 ,
151+ "total_item_count" : 2 ,
152+ "issues" : [
153+ {
154+ "title" : "Issue 1" ,
155+ "html_url" : "https://github.com/owner/repo/issues/1" ,
156+ "author" : "alice" ,
157+ "time_to_first_response" : "None" ,
158+ "time_to_close" : "None" ,
159+ "time_to_answer" : "None" ,
160+ "label_metrics" : {},
83161 },
162+ {
163+ "title" : "Issue 2" ,
164+ "html_url" : "https://github.com/owner/repo/issues/2" ,
165+ "author" : "bob" ,
166+ "time_to_first_response" : "None" ,
167+ "time_to_close" : "None" ,
168+ "time_to_answer" : "None" ,
169+ "label_metrics" : {},
170+ },
171+ ],
172+ "search_query" : "is:issue repo:owner/repo" ,
173+ }
174+
175+ # Call the function and check the output
176+ self .assertEqual (
177+ write_to_json (
178+ issues_with_metrics = issues_with_metrics ,
179+ stats_time_to_first_response = stats_time_to_first_response ,
180+ stats_time_to_close = stats_time_to_close ,
181+ stats_time_to_answer = stats_time_to_answer ,
182+ stats_time_in_labels = stats_time_in_labels ,
84183 num_issues_opened = num_issues_opened ,
85184 num_issues_closed = num_issues_closed ,
86185 search_query = "is:issue repo:owner/repo" ,
0 commit comments