Skip to content

Commit

Permalink
Final Refactor
Browse files Browse the repository at this point in the history
- Refactored the code , made it cleaner 
- added comments for test cases , numbering them and making them more clear
  • Loading branch information
sambhavnoobcoder authored Jul 31, 2024
1 parent ca49a09 commit 6b0f244
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/autocommit_command_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def setUp(self):
def tearDown(self):
patch.stopall()

#Test 1 : git_commit_basic
def test_git_commit_basic(self):
git_commit(issue_flag=False, push=False)
self.mock_subprocess.assert_called_with(["git", "commit", "-m", ANY], check=True)
Expand All @@ -45,6 +46,7 @@ def test_git_commit_basic(self):
self.assertIn("add new", commit_message)
self.assertIn("authentication", commit_message)

#Test 2 : git_commit_with_issue
def test_git_commit_with_issue(self):
self.mock_input.side_effect = ['y', 'y', '1', 'y']
git_commit(issue_flag=True, push=False)
Expand All @@ -55,6 +57,7 @@ def test_git_commit_with_issue(self):
self.assertIn("authentication", commit_message)
self.assertIn("(issue: #1)", commit_message)

#Test 3 : git_commit_with_push
def test_git_commit_with_push(self):
git_commit(issue_flag=False, push=True)
self.mock_subprocess.assert_has_calls([
Expand All @@ -66,16 +69,19 @@ def test_git_commit_with_push(self):
self.assertIn("add new", commit_message)
self.assertIn("authentication", commit_message)

#Test 4 : git_commit_change_message
def test_git_commit_change_message(self):
self.mock_input.side_effect = ['c', 'new commit message', 'y']
git_commit(issue_flag=False, push=False)
self.mock_subprocess.assert_called_with(["git", "commit", "-m", 'new commit message'], check=True)

#Test 5 : git_commit_cancel
def test_git_commit_cancel(self):
self.mock_input.side_effect = ['n']
git_commit(issue_flag=False, push=False)
self.mock_subprocess.assert_not_called()

#Test 6 : git_commit_all_flag
def test_git_commit_all_flag(self):
git_commit(all_flag=True, issue_flag=False, push=False)
self.mock_subprocess.assert_has_calls([
Expand All @@ -87,6 +93,7 @@ def test_git_commit_all_flag(self):
self.assertIn("add new", commit_message)
self.assertIn("authentication", commit_message)

#Test 7 : git_commit_no_related_issue
@patch('pieces.autocommit.autocommit.get_issue_details')
def test_git_commit_no_related_issue(self, mock_get_issue_details):
mock_get_issue_details.return_value = (None, None, "Issue markdown")
Expand All @@ -98,11 +105,13 @@ def test_git_commit_no_related_issue(self, mock_get_issue_details):
self.assertIn("add new", commit_message)
self.assertIn("authentication", commit_message)

#Test 8 : git_commit_no_changes
def test_git_commit_no_changes(self):
self.mock_get_changes.return_value = (None, None)
git_commit(issue_flag=False, push=False)
print(".No changes found")

#Test 9 : get_current_working_changes
def test_get_current_working_changes(self):
with patch('subprocess.run') as mock_run:
mock_run.return_value = MagicMock(stdout="diff --git a/file1.py b/file1.py\n+new line\n-old line")
Expand All @@ -111,6 +120,7 @@ def test_get_current_working_changes(self):
self.assertIsInstance(seeds, Seeds)
self.assertEqual(len(seeds.iterable), 1)

#Test 10 : get_issue_details
@patch('pieces.autocommit.autocommit.QGPTApi')
def test_get_issue_details(self, mock_qgpt_api):
mock_answer = MagicMock()
Expand Down

0 comments on commit 6b0f244

Please sign in to comment.