| 
1 | 1 | import os  | 
2 | 2 | import subprocess  | 
3 | 3 | import sys  | 
 | 4 | +import types  | 
4 | 5 | from functools import partial  | 
5 | 6 | 
 
  | 
6 | 7 | import pytest  | 
@@ -182,3 +183,59 @@ def test_unknown_args_before_double_dash_raises(mocker: MockFixture):  | 
182 | 183 |     assert "Invalid commitizen arguments were found before -- separator" in str(  | 
183 | 184 |         excinfo.value  | 
184 | 185 |     )  | 
 | 186 | + | 
 | 187 | + | 
 | 188 | +def test_commitizen_excepthook_non_commitizen_exception(mocker: MockFixture):  | 
 | 189 | +    """Test that commitizen_excepthook delegates to original_excepthook for non-CommitizenException."""  | 
 | 190 | +    # Mock the original excepthook  | 
 | 191 | +    mock_original_excepthook = mocker.Mock()  | 
 | 192 | +    mocker.patch("commitizen.cli.original_excepthook", mock_original_excepthook)  | 
 | 193 | + | 
 | 194 | +    # Create a regular exception  | 
 | 195 | +    test_exception = ValueError("test error")  | 
 | 196 | + | 
 | 197 | +    # Call commitizen_excepthook with the regular exception  | 
 | 198 | +    cli.commitizen_excepthook(ValueError, test_exception, None)  | 
 | 199 | + | 
 | 200 | +    # Verify original_excepthook was called with correct arguments  | 
 | 201 | +    mock_original_excepthook.assert_called_once_with(ValueError, test_exception, None)  | 
 | 202 | + | 
 | 203 | + | 
 | 204 | +def test_commitizen_excepthook_non_commitizen_exception_with_traceback(  | 
 | 205 | +    mocker: MockFixture,  | 
 | 206 | +):  | 
 | 207 | +    """Test that commitizen_excepthook handles traceback correctly for non-CommitizenException."""  | 
 | 208 | +    # Mock the original excepthook  | 
 | 209 | +    mock_original_excepthook = mocker.Mock()  | 
 | 210 | +    mocker.patch("commitizen.cli.original_excepthook", mock_original_excepthook)  | 
 | 211 | + | 
 | 212 | +    # Create a regular exception with a traceback  | 
 | 213 | +    test_exception = ValueError("test error")  | 
 | 214 | +    test_traceback = mocker.Mock(spec=types.TracebackType)  | 
 | 215 | + | 
 | 216 | +    # Call commitizen_excepthook with the regular exception and traceback  | 
 | 217 | +    cli.commitizen_excepthook(ValueError, test_exception, test_traceback)  | 
 | 218 | + | 
 | 219 | +    # Verify original_excepthook was called with correct arguments including traceback  | 
 | 220 | +    mock_original_excepthook.assert_called_once_with(  | 
 | 221 | +        ValueError, test_exception, test_traceback  | 
 | 222 | +    )  | 
 | 223 | + | 
 | 224 | + | 
 | 225 | +def test_commitizen_excepthook_non_commitizen_exception_with_invalid_traceback(  | 
 | 226 | +    mocker: MockFixture,  | 
 | 227 | +):  | 
 | 228 | +    """Test that commitizen_excepthook handles invalid traceback correctly for non-CommitizenException."""  | 
 | 229 | +    # Mock the original excepthook  | 
 | 230 | +    mock_original_excepthook = mocker.Mock()  | 
 | 231 | +    mocker.patch("commitizen.cli.original_excepthook", mock_original_excepthook)  | 
 | 232 | + | 
 | 233 | +    # Create a regular exception with an invalid traceback  | 
 | 234 | +    test_exception = ValueError("test error")  | 
 | 235 | +    test_traceback = mocker.Mock()  # Not a TracebackType  | 
 | 236 | + | 
 | 237 | +    # Call commitizen_excepthook with the regular exception and invalid traceback  | 
 | 238 | +    cli.commitizen_excepthook(ValueError, test_exception, test_traceback)  | 
 | 239 | + | 
 | 240 | +    # Verify original_excepthook was called with None as traceback  | 
 | 241 | +    mock_original_excepthook.assert_called_once_with(ValueError, test_exception, None)  | 
0 commit comments