3tractorrides / release-notes-formatter

MIT License
0 stars 0 forks source link

Sweep: Add un-happy path variations to unit tests. #2

Closed 3tractorrides closed 8 months ago

3tractorrides commented 8 months ago

Details

Unit Tests: update tests within test_main.py to include un-happy scenarios, ie: cases where the methods don't receive appropriate or well formatted inputs.

Checklist - [X] Modify `test_main.py` ✓ https://github.com/3tractorrides/release-notes-formatter/commit/c2b470774881339870a1714e0d82158916fc272b [Edit](https://github.com/3tractorrides/release-notes-formatter/edit/sweep/add_unhappy_path_variations_to_unit_test/test_main.py#L5-L36) - [X] Running GitHub Actions for `test_main.py` ✓ [Edit](https://github.com/3tractorrides/release-notes-formatter/edit/sweep/add_unhappy_path_variations_to_unit_test/test_main.py#L5-L36) - [X] Modify `test_main.py` ✓ https://github.com/3tractorrides/release-notes-formatter/commit/da6d2944b42cc15ffe6aa35f6170538d6a36538f [Edit](https://github.com/3tractorrides/release-notes-formatter/edit/sweep/add_unhappy_path_variations_to_unit_test/test_main.py#L38-L77) - [X] Running GitHub Actions for `test_main.py` ✓ [Edit](https://github.com/3tractorrides/release-notes-formatter/edit/sweep/add_unhappy_path_variations_to_unit_test/test_main.py#L38-L77)
sweep-ai[bot] commented 8 months ago

🚀 Here's the PR! #3

See Sweep's progress at the progress dashboard!
Sweep Basic Tier: I'm using GPT-4. You have 5 GPT-4 tickets left for the month and 3 for the day. (tracking ID: e2786efbf1)

For more GPT-4 tickets, visit our payment portal. For a one week free trial, try Sweep Pro (unlimited GPT-4 tickets).

[!TIP] I can email you next time I complete a pull request if you set up your email here!


Actions (click)

GitHub Actions✓

Here are the GitHub Actions logs prior to making any changes:

Sandbox logs for 518f031
Checking test_main.py for syntax errors... ✅ test_main.py has no syntax errors! 1/1 ✓
Checking test_main.py for syntax errors...
✅ test_main.py has no syntax errors!

Sandbox passed on the latest main, so sandbox checks will be enabled for this issue.


Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I think are relevant in decreasing order of relevance (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/3tractorrides/release-notes-formatter/blob/518f03161bbcc8cc5ff9e2eeb49ab6f9045865d7/test_main.py#L4-L80

Step 2: ⌨️ Coding

--- 
+++ 
@@ -3,6 +3,30 @@
 from main import format_ticket_number_list, build_release_item_text

 class TestFormatTicketNumberList(unittest.TestCase):
+
+    def test_invalid_base_url(self):
+        input_string = "- AB#1234 - context with a ticket number."
+        base_url = 'invalid-url'
+        expected_output = input_string
+
+        transformed_content = format_ticket_number_list(re.search(r'(?<=- )AB[#-]?(\d+)', input_string), base_url)
+        self.assertEqual(transformed_content, expected_output)
+
+    def test_ticket_number_in_unexpected_format(self):
+        input_string = "This string has ticket 1234 not in expected format."
+        base_url = 'https://dev.azure.com/valid-url/'
+        expected_output = input_string
+
+        transformed_content = format_ticket_number_list(re.search(r'(?<=- )AB[#-]?(\d+)', input_string), base_url)
+        self.assertEqual(transformed_content, expected_output)
+
+    def test_input_without_ticket_number(self):
+        input_string = "This is a string without a ticket number."
+        base_url = 'https://dev.azure.com/valid-url/'
+        expected_output = input_string
+
+        transformed_content = format_ticket_number_list(re.search(r'(?<=- )AB[#-]?(\d+)', input_string), base_url)
+        self.assertEqual(transformed_content, expected_output)
     def test_format_ticket_number_list(self):
         input_string = "- AB#1234 - some context about this pr"
         base_url = 'https://dev.azure.com/parallax-app/Parallax%202023/_workitems/edit/'

Ran GitHub Actions for c2b470774881339870a1714e0d82158916fc272b:

--- 
+++ 
@@ -3,6 +3,30 @@
 from main import format_ticket_number_list, build_release_item_text

 class TestFormatTicketNumberList(unittest.TestCase):
+
+    def test_invalid_base_url(self):
+        input_string = "- AB#1234 - context with a ticket number."
+        base_url = 'invalid-url'
+        expected_output = input_string
+
+        transformed_content = format_ticket_number_list(re.search(r'(?<=- )AB[#-]?(\d+)', input_string), base_url)
+        self.assertEqual(transformed_content, expected_output)
+
+    def test_ticket_number_in_unexpected_format(self):
+        input_string = "This string has ticket 1234 not in expected format."
+        base_url = 'https://dev.azure.com/valid-url/'
+        expected_output = input_string
+
+        transformed_content = format_ticket_number_list(re.search(r'(?<=- )AB[#-]?(\d+)', input_string), base_url)
+        self.assertEqual(transformed_content, expected_output)
+
+    def test_input_without_ticket_number(self):
+        input_string = "This is a string without a ticket number."
+        base_url = 'https://dev.azure.com/valid-url/'
+        expected_output = input_string
+
+        transformed_content = format_ticket_number_list(re.search(r'(?<=- )AB[#-]?(\d+)', input_string), base_url)
+        self.assertEqual(transformed_content, expected_output)
     def test_format_ticket_number_list(self):
         input_string = "- AB#1234 - some context about this pr"
         base_url = 'https://dev.azure.com/parallax-app/Parallax%202023/_workitems/edit/'
@@ -76,6 +100,30 @@
         transformed_content = build_release_item_text(input_string, base_url)
         self.assertEqual(transformed_content, expected_output)

+    def test_input_without_ticket_number(self):
+        input_string = "This is a string without a ticket number."
+        base_url = 'https://dev.azure.com/valid-url/'
+        expected_output = input_string
+
+        transformed_content = build_release_item_text(input_string, base_url)
+        self.assertEqual(transformed_content, expected_output)
+
+    def test_ticket_number_in_unexpected_format(self):
+        input_string = "Text with TICKET-1234 not formatted."
+        base_url = 'https://dev.azure.com/valid-url/'
+        expected_output = input_string
+
+        transformed_content = build_release_item_text(input_string, base_url)
+        self.assertEqual(transformed_content, expected_output)
+
+    def test_invalid_base_url(self):
+        input_string = "- AB#1234 - context that should not get formatted."
+        base_url = 'invalid-url'
+        expected_output = input_string
+
+        transformed_content = build_release_item_text(input_string, base_url)
+        self.assertEqual(transformed_content, expected_output)
+
 if __name__ == '__main__':
     unittest.TextTestRunner().run(unittest.TestLoader().loadTestsFromTestCase(TestFormatTicketNumberList))
     unittest.TextTestRunner().run(unittest.TestLoader().loadTestsFromTestCase(TestBuildReleaseItemText))

Ran GitHub Actions for da6d2944b42cc15ffe6aa35f6170538d6a36538f:


Step 3: 🔁 Code Review

I have finished reviewing the code for completeness. I did not find errors for sweep/add_unhappy_path_variations_to_unit_test.


🎉 Latest improvements to Sweep:


💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request. Join Our Discord