Skip to content

Commit 0fe15c9

Browse files
authored
Merge pull request #100 from eichisanden/main
test: add test to test_time_to_first_response.py
2 parents 49a02ad + 5f6055c commit 0fe15c9

File tree

1 file changed

+116
-11
lines changed

1 file changed

+116
-11
lines changed

test_time_to_first_response.py

+116-11
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def test_measure_time_to_first_response(self):
3636
mock_issue1.comments = 2
3737
mock_issue1.created_at = "2023-01-01T00:00:00Z"
3838

39+
# Set up the mock GitHub issue comments
3940
mock_comment1 = MagicMock()
4041
mock_comment1.created_at = datetime.fromisoformat("2023-01-02T00:00:00Z")
4142
mock_comment2 = MagicMock()
@@ -63,27 +64,109 @@ def test_measure_time_to_first_response_no_comments(self):
6364
# Check the results
6465
self.assertEqual(result, expected_result)
6566

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+
66142
def test_measure_time_to_first_response_ignore_users(self):
67143
"""Test that measure_time_to_first_response ignores comments from ignored users."""
68144
# Set up the mock GitHub issues
69145
mock_issue1 = MagicMock()
70-
mock_issue1.comments = 1
146+
mock_issue1.comments = 4
71147
mock_issue1.created_at = "2023-01-01T00:00:00Z"
72148

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)
74150
mock_comment1 = MagicMock()
75151
mock_comment1.user.login = "ignored_user"
76152
mock_comment1.created_at = datetime.fromisoformat("2023-01-02T00:00:00Z")
77-
78153
mock_comment2 = MagicMock()
79154
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")
82156
mock_issue1.issue.comments.return_value = [mock_comment1, mock_comment2]
83157

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+
84167
# Call the function
85168
result = measure_time_to_first_response(mock_issue1, None, ["ignored_user"])
86-
expected_result = timedelta(days=2)
169+
expected_result = timedelta(days=3)
87170

88171
# Check the results
89172
self.assertEqual(result, expected_result)
@@ -92,20 +175,28 @@ def test_measure_time_to_first_response_only_ignored_users(self):
92175
"""Test that measure_time_to_first_response returns empty for an issue with only ignored users."""
93176
# Set up the mock GitHub issues
94177
mock_issue1 = MagicMock()
95-
mock_issue1.comments = 1
178+
mock_issue1.comments = 4
96179
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"}
97181

98-
# Set up the mock GitHub comments (all ignored)
182+
# Set up the mock GitHub issue comments (all ignored)
99183
mock_comment1 = MagicMock()
100184
mock_comment1.user.login = "ignored_user"
101185
mock_comment1.created_at = datetime.fromisoformat("2023-01-02T00:00:00Z")
102-
103186
mock_comment2 = MagicMock()
104187
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")
107189
mock_issue1.issue.comments.return_value = [mock_comment1, mock_comment2]
108190

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+
109200
# Call the function
110201
result = measure_time_to_first_response(
111202
mock_issue1, None, ["ignored_user", "ignored_user2"]
@@ -142,3 +233,17 @@ def test_get_average_time_to_first_response(self):
142233
result = get_average_time_to_first_response(issues_with_metrics)
143234
expected_result = timedelta(days=1.5)
144235
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

Comments
 (0)