-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from PressXtoChris/main
- Loading branch information
Showing
8 changed files
with
277 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"""A module containing unit tests for the time_to_merge module. | ||
This module contains unit tests for the measure_time_to_merge | ||
function in the time_to_merge module. | ||
The tests use mock GitHub pull request to test the function's behavior. | ||
Classes: | ||
TestMeasureTimeToMerge: A class to test the measure_time_to_merge function. | ||
""" | ||
from datetime import timedelta, datetime | ||
import unittest | ||
from unittest.mock import MagicMock | ||
|
||
from time_to_merge import measure_time_to_merge | ||
|
||
class TestMeasureTimeToMerge(unittest.TestCase): | ||
"""Test suite for the measure_time_to_merge function.""" | ||
|
||
def test_measure_time_to_merge_ready_for_review(self): | ||
"""Test that the function correctly measures the time to merge a pull request that was formerly a draft.""" | ||
# Create a mock pull request object | ||
pull_request = MagicMock() | ||
pull_request.merged_at = datetime.fromisoformat("2021-01-03T00:00:00Z") | ||
ready_for_review_at = datetime.fromisoformat("2021-01-01T00:00:00Z") | ||
|
||
# Call the function and check the result | ||
result = measure_time_to_merge(pull_request, ready_for_review_at) | ||
expected_result = timedelta(days=2) | ||
self.assertEqual(result, expected_result) | ||
|
||
def test_measure_time_to_merge_created_at(self): | ||
"""Test that the function correctly measures the time to merge a pull request that was never a draft.""" | ||
# Create a mock pull request object | ||
pull_request = MagicMock() | ||
pull_request.merged_at = datetime.fromisoformat("2021-01-03T00:00:00Z") | ||
pull_request.created_at = datetime.fromisoformat("2021-01-01T00:00:00Z") | ||
|
||
# Call the function and check the result | ||
result = measure_time_to_merge(pull_request, None) | ||
expected_result = timedelta(days=2) | ||
self.assertEqual(result, expected_result) | ||
|
||
def test_measure_time_to_merge_returns_none(self): | ||
"""Test that the function returns None if the pull request is not merged.""" | ||
# Create a mock issue object | ||
pull_request = MagicMock() | ||
pull_request.merged_at = None | ||
|
||
# Call the function and check that it returns None | ||
self.assertEqual(None, measure_time_to_merge(pull_request, None)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
"""A module containing unit tests for the time_to_ready_for_review module. | ||
This module contains unit tests for the get_time_to_ready_for_review | ||
function in the time_to_ready_for_review module. | ||
The tests use mock GitHub issues to test the functions' behavior. | ||
Classes: | ||
TestGetTimeToReadyForReview: A class to test the get_time_to_ready_for_review function. | ||
""" | ||
from datetime import datetime | ||
import unittest | ||
from unittest.mock import MagicMock | ||
|
||
from time_to_ready_for_review import get_time_to_ready_for_review | ||
|
||
class TestGetTimeToReadyForReview(unittest.TestCase): | ||
"""Test suite for the get_time_to_ready_for_review function.""" | ||
|
||
# def draft pr function | ||
def test_time_to_ready_for_review_draft(self): | ||
"""Test that the function returns None when the pull request is a draft""" | ||
pull_request = MagicMock() | ||
pull_request.draft = True | ||
issue = MagicMock() | ||
|
||
result = get_time_to_ready_for_review(issue, pull_request) | ||
expected_result = None | ||
self.assertEqual(result, expected_result) | ||
|
||
def test_get_time_to_ready_for_review_event(self): | ||
"""Test that the function correctly gets the time a pull request was marked as ready for review""" | ||
pull_request = MagicMock() | ||
pull_request.draft = False | ||
event = MagicMock() | ||
event.event = 'ready_for_review' | ||
event.created_at = datetime.fromisoformat("2021-01-01T00:00:00Z") | ||
issue = MagicMock() | ||
issue.issue.events.return_value=[event] | ||
|
||
result = get_time_to_ready_for_review(issue, pull_request) | ||
expected_result = event.created_at | ||
self.assertEqual(result, expected_result) | ||
|
||
def test_get_time_to_ready_for_review_no_event(self): | ||
"""Test that the function returns None when the pull request is not a draft and no ready_for_review event is found""" | ||
pull_request = MagicMock() | ||
pull_request.draft = False | ||
event = MagicMock() | ||
event.event = 'foobar' | ||
event.created_at = "2021-01-01T00:00:00Z" | ||
issue = MagicMock() | ||
issue.events.return_value=[event] | ||
|
||
result = get_time_to_ready_for_review(issue, pull_request) | ||
expected_result = None | ||
self.assertEqual(result, expected_result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.