fancygit 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,118 @@
1
+ import pytest
2
+ from unittest.mock import patch, MagicMock
3
+ from src.git_runner import GitRunner
4
+
5
+ @pytest.mark.unit
6
+ class TestGitRunner:
7
+ """Test cases for GitRunner class"""
8
+
9
+ def setup_method(self):
10
+ """Setup method called before each test"""
11
+ self.runner = GitRunner()
12
+
13
+ def test_git_runner_initialization(self):
14
+ """Test GitRunner initialization"""
15
+ assert self.runner.git_cmd == "git"
16
+
17
+ @patch('subprocess.run')
18
+ def test_run_git_command_success(self, mock_subprocess):
19
+ """Test successful git command execution"""
20
+ # Mock subprocess.run result
21
+ mock_result = MagicMock()
22
+ mock_result.returncode = 0
23
+ mock_result.stdout = "On branch main\nnothing to commit"
24
+ mock_result.stderr = ""
25
+ mock_subprocess.return_value = mock_result
26
+
27
+ returncode, stdout, stderr = self.runner.run_git_command(['status'])
28
+
29
+ assert returncode == 0
30
+ assert stdout == "On branch main\nnothing to commit"
31
+ assert stderr == ""
32
+ mock_subprocess.assert_called_once_with(
33
+ ['git', 'status'],
34
+ capture_output=True,
35
+ text=True,
36
+ check=False
37
+ )
38
+
39
+ @patch('subprocess.run')
40
+ def test_run_git_command_with_error(self, mock_subprocess):
41
+ """Test git command that returns an error"""
42
+ mock_result = MagicMock()
43
+ mock_result.returncode = 1
44
+ mock_result.stdout = ""
45
+ mock_result.stderr = "error: pathspec 'test.txt' did not match any files"
46
+ mock_subprocess.return_value = mock_result
47
+
48
+ returncode, stdout, stderr = self.runner.run_git_command(['add', 'test.txt'])
49
+
50
+ assert returncode == 1
51
+ assert stdout == ""
52
+ assert stderr == "error: pathspec 'test.txt' did not match any files"
53
+
54
+ @patch('subprocess.run')
55
+ def test_run_git_command_with_multiple_args(self, mock_subprocess):
56
+ """Test git command with multiple arguments"""
57
+ mock_result = MagicMock()
58
+ mock_result.returncode = 0
59
+ mock_result.stdout = "Everything up-to-date"
60
+ mock_result.stderr = ""
61
+ mock_subprocess.return_value = mock_result
62
+
63
+ returncode, stdout, stderr = self.runner.run_git_command(['push', 'origin', 'main'])
64
+
65
+ assert returncode == 0
66
+ assert stdout == "Everything up-to-date"
67
+ mock_subprocess.assert_called_once_with(
68
+ ['git', 'push', 'origin', 'main'],
69
+ capture_output=True,
70
+ text=True,
71
+ check=False
72
+ )
73
+
74
+ @patch('subprocess.run')
75
+ def test_run_git_command_exception(self, mock_subprocess):
76
+ """Test handling of subprocess exceptions"""
77
+ mock_subprocess.side_effect = Exception("Command not found")
78
+
79
+ returncode, stdout, stderr = self.runner.run_git_command(['status'])
80
+
81
+ assert returncode == -1
82
+ assert stdout == ""
83
+ assert stderr == "Command not found"
84
+
85
+ @patch('subprocess.run')
86
+ def test_run_git_command_empty_args(self, mock_subprocess):
87
+ """Test git command with no arguments"""
88
+ mock_result = MagicMock()
89
+ mock_result.returncode = 0
90
+ mock_result.stdout = "Git help output"
91
+ mock_result.stderr = ""
92
+ mock_subprocess.return_value = mock_result
93
+
94
+ returncode, stdout, stderr = self.runner.run_git_command([])
95
+
96
+ assert returncode == 0
97
+ assert stdout == "Git help output"
98
+ mock_subprocess.assert_called_once_with(
99
+ ['git'],
100
+ capture_output=True,
101
+ text=True,
102
+ check=False
103
+ )
104
+
105
+ @patch('subprocess.run')
106
+ def test_run_git_command_with_complex_output(self, mock_subprocess):
107
+ """Test git command with complex multi-line output"""
108
+ mock_result = MagicMock()
109
+ mock_result.returncode = 0
110
+ mock_result.stdout = "On branch main\nYour branch is up to date with 'origin/main'.\n\nChanges to be committed:\n modified: test.py\n"
111
+ mock_result.stderr = ""
112
+ mock_subprocess.return_value = mock_result
113
+
114
+ returncode, stdout, stderr = self.runner.run_git_command(['status'])
115
+
116
+ assert returncode == 0
117
+ assert "Changes to be committed:" in stdout
118
+ assert "modified: test.py" in stdout