@@ -36,6 +36,7 @@ def test_measure_time_to_first_response(self):
36
36
mock_issue1 .comments = 2
37
37
mock_issue1 .created_at = "2023-01-01T00:00:00Z"
38
38
39
+ # Set up the mock GitHub issue comments
39
40
mock_comment1 = MagicMock ()
40
41
mock_comment1 .created_at = datetime .fromisoformat ("2023-01-02T00:00:00Z" )
41
42
mock_comment2 = MagicMock ()
@@ -63,27 +64,109 @@ def test_measure_time_to_first_response_no_comments(self):
63
64
# Check the results
64
65
self .assertEqual (result , expected_result )
65
66
67
+ def test_measure_time_to_first_response_with_pull_request_comments (self ):
68
+ """Test that measure_time_to_first_response with pull request comments."""
69
+
70
+ # Set up the mock GitHub issues
71
+ mock_issue1 = MagicMock ()
72
+ mock_issue1 .comments = 2
73
+ mock_issue1 .created_at = "2023-01-01T00:00:00Z"
74
+ mock_issue1 .pull_request_urls = {"url" : "https://api.github.com/repos/owner/repo/pulls/1" }
75
+
76
+ # Set up the mock GitHub pull request comments
77
+ mock_pr_comment1 = MagicMock ()
78
+ mock_pr_comment1 .submitted_at = datetime .fromisoformat ("2023-01-02T00:00:00Z" ) # first response
79
+ mock_pr_comment2 = MagicMock ()
80
+ mock_pr_comment2 .submitted_at = datetime .fromisoformat ("2023-01-02T12:00:00Z" )
81
+ mock_issue1 .issue .pull_request ().reviews .return_value = [mock_pr_comment1 , mock_pr_comment2 ]
82
+
83
+ # Call the function
84
+ result = measure_time_to_first_response (mock_issue1 , None )
85
+ expected_result = timedelta (days = 1 )
86
+
87
+ # Check the results
88
+ self .assertEqual (result , expected_result )
89
+
90
+ def test_measure_time_to_first_response_issue_comment_faster (self ):
91
+ """Test that measure_time_to_first_response issue comment faster."""
92
+
93
+ # Set up the mock GitHub issues
94
+ mock_issue1 = MagicMock ()
95
+ mock_issue1 .comments = 2
96
+ mock_issue1 .created_at = "2023-01-01T00:00:00Z"
97
+ mock_issue1 .pull_request_urls = {"url" : "https://api.github.com/repos/owner/repo/pulls/1" }
98
+
99
+ # Set up the mock GitHub issue comment
100
+ mock_comment1 = MagicMock ()
101
+ mock_comment1 .created_at = datetime .fromisoformat ("2023-01-02T00:00:00Z" ) # first response
102
+ mock_issue1 .issue .comments .return_value = [mock_comment1 ]
103
+
104
+ # Set up the mock GitHub pull request comment
105
+ mock_pr_comment1 = MagicMock ()
106
+ mock_pr_comment1 .submitted_at = datetime .fromisoformat ("2023-01-03T00:00:00Z" )
107
+ mock_issue1 .issue .pull_request ().reviews .return_value = [mock_pr_comment1 ]
108
+
109
+ # Call the function
110
+ result = measure_time_to_first_response (mock_issue1 , None )
111
+ expected_result = timedelta (days = 1 )
112
+
113
+ # Check the results
114
+ self .assertEqual (result , expected_result )
115
+
116
+ def test_measure_time_to_first_response_pull_request_comment_faster (self ):
117
+ """Test that measure_time_to_first_response pull request comment faster."""
118
+
119
+ # Set up the mock GitHub issues
120
+ mock_issue1 = MagicMock ()
121
+ mock_issue1 .comments = 2
122
+ mock_issue1 .created_at = "2023-01-01T00:00:00Z"
123
+ mock_issue1 .pull_request_urls = {"url" : "https://api.github.com/repos/owner/repo/pulls/1" }
124
+
125
+ # Set up the mock GitHub pull issue comment
126
+ mock_comment1 = MagicMock ()
127
+ mock_comment1 .created_at = datetime .fromisoformat ("2023-01-03T00:00:00Z" )
128
+ mock_issue1 .issue .comments .return_value = [mock_comment1 ]
129
+
130
+ # Set up the mock GitHub pull request comment
131
+ mock_pr_comment1 = MagicMock ()
132
+ mock_pr_comment1 .submitted_at = datetime .fromisoformat ("2023-01-02T00:00:00Z" ) # first response
133
+ mock_issue1 .issue .pull_request ().reviews .return_value = [mock_pr_comment1 ]
134
+
135
+ # Call the function
136
+ result = measure_time_to_first_response (mock_issue1 , None )
137
+ expected_result = timedelta (days = 1 )
138
+
139
+ # Check the results
140
+ self .assertEqual (result , expected_result )
141
+
66
142
def test_measure_time_to_first_response_ignore_users (self ):
67
143
"""Test that measure_time_to_first_response ignores comments from ignored users."""
68
144
# Set up the mock GitHub issues
69
145
mock_issue1 = MagicMock ()
70
- mock_issue1 .comments = 1
146
+ mock_issue1 .comments = 4
71
147
mock_issue1 .created_at = "2023-01-01T00:00:00Z"
72
148
73
- # Set up the mock GitHub comments (one ignored, one not ignored)
149
+ # Set up the mock GitHub issue comments (one ignored, one not ignored)
74
150
mock_comment1 = MagicMock ()
75
151
mock_comment1 .user .login = "ignored_user"
76
152
mock_comment1 .created_at = datetime .fromisoformat ("2023-01-02T00:00:00Z" )
77
-
78
153
mock_comment2 = MagicMock ()
79
154
mock_comment2 .user .login = "not_ignored_user"
80
- mock_comment2 .created_at = datetime .fromisoformat ("2023-01-03T00:00:00Z" )
81
-
155
+ mock_comment2 .created_at = datetime .fromisoformat ("2023-01-05T00:00:00Z" )
82
156
mock_issue1 .issue .comments .return_value = [mock_comment1 , mock_comment2 ]
83
157
158
+ # Set up the mock GitHub pull request comments (one ignored, one not ignored)
159
+ mock_pr_comment1 = MagicMock ()
160
+ mock_pr_comment1 .user .login = "ignored_user"
161
+ mock_pr_comment1 .submitted_at = datetime .fromisoformat ("2023-01-03T00:00:00Z" )
162
+ mock_pr_comment2 = MagicMock ()
163
+ mock_pr_comment2 .user .login = "not_ignored_user"
164
+ mock_pr_comment2 .submitted_at = datetime .fromisoformat ("2023-01-04T00:00:00Z" ) # first response
165
+ mock_issue1 .issue .pull_request ().reviews .return_value = [mock_pr_comment1 , mock_pr_comment2 ]
166
+
84
167
# Call the function
85
168
result = measure_time_to_first_response (mock_issue1 , None , ["ignored_user" ])
86
- expected_result = timedelta (days = 2 )
169
+ expected_result = timedelta (days = 3 )
87
170
88
171
# Check the results
89
172
self .assertEqual (result , expected_result )
@@ -92,20 +175,28 @@ def test_measure_time_to_first_response_only_ignored_users(self):
92
175
"""Test that measure_time_to_first_response returns empty for an issue with only ignored users."""
93
176
# Set up the mock GitHub issues
94
177
mock_issue1 = MagicMock ()
95
- mock_issue1 .comments = 1
178
+ mock_issue1 .comments = 4
96
179
mock_issue1 .created_at = "2023-01-01T00:00:00Z"
180
+ mock_issue1 .pull_request_urls = {"url" : "https://api.github.com/repos/owner/repo/pulls/1" }
97
181
98
- # Set up the mock GitHub comments (all ignored)
182
+ # Set up the mock GitHub issue comments (all ignored)
99
183
mock_comment1 = MagicMock ()
100
184
mock_comment1 .user .login = "ignored_user"
101
185
mock_comment1 .created_at = datetime .fromisoformat ("2023-01-02T00:00:00Z" )
102
-
103
186
mock_comment2 = MagicMock ()
104
187
mock_comment2 .user .login = "ignored_user2"
105
- mock_comment2 .created_at = datetime .fromisoformat ("2023-01-03T00:00:00Z" )
106
-
188
+ mock_comment2 .created_at = datetime .fromisoformat ("2023-01-05T00:00:00Z" )
107
189
mock_issue1 .issue .comments .return_value = [mock_comment1 , mock_comment2 ]
108
190
191
+ # Set up the mock GitHub pull request comments (all ignored)
192
+ mock_pr_comment1 = MagicMock ()
193
+ mock_pr_comment1 .user .login = "ignored_user"
194
+ mock_pr_comment1 .submitted_at = datetime .fromisoformat ("2023-01-03T00:00:00Z" )
195
+ mock_pr_comment2 = MagicMock ()
196
+ mock_pr_comment2 .user .login = "ignored_user2"
197
+ mock_pr_comment2 .submitted_at = datetime .fromisoformat ("2023-01-04T12:00:00Z" )
198
+ mock_issue1 .issue .pull_request ().reviews .return_value = [mock_pr_comment1 , mock_pr_comment2 ]
199
+
109
200
# Call the function
110
201
result = measure_time_to_first_response (
111
202
mock_issue1 , None , ["ignored_user" , "ignored_user2" ]
@@ -142,3 +233,17 @@ def test_get_average_time_to_first_response(self):
142
233
result = get_average_time_to_first_response (issues_with_metrics )
143
234
expected_result = timedelta (days = 1.5 )
144
235
self .assertEqual (result , expected_result )
236
+
237
+ def test_get_average_time_to_first_response_with_all_none (self ):
238
+ """Test that get_average_time_to_first_response with all None data."""
239
+
240
+ # Create mock data with all None
241
+ issues_with_metrics = [
242
+ IssueWithMetrics ("Issue 1" , "https://github.com/user/repo/issues/1" , None ),
243
+ IssueWithMetrics ("Issue 2" , "https://github.com/user/repo/issues/2" , None ),
244
+ ]
245
+
246
+ # Call the function and check the result
247
+ result = get_average_time_to_first_response (issues_with_metrics )
248
+ expected_result = None
249
+ self .assertEqual (result , expected_result )
0 commit comments