| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
import pytest |
| 6 |
from unittest.mock import patch |
| 7 |
import sys |
| 8 |
import io |
| 9 |
from scalene import scalene_profiler |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
def test_main_exception_handling(): |
| 14 |
|
| 15 |
with patch( |
| 16 |
"scalene.scalene_profiler.Scalene.main", side_effect=Exception("Test Exception") |
| 17 |
): |
| 18 |
|
| 19 |
with patch("sys.stderr", new=io.StringIO()) as fake_stderr: |
| 20 |
|
| 21 |
with patch("sys.exit", side_effect=SystemExit) as mock_exit: |
| 22 |
|
| 23 |
with pytest.raises(SystemExit): |
| 24 |
from scalene.__main__ import main |
| 25 |
|
| 26 |
main() |
| 27 |
|
| 28 |
assert ( |
| 29 |
"ERROR: Calling Scalene main function failed: Test Exception" |
| 30 |
in fake_stderr.getvalue() |
| 31 |
) |
| 32 |
|
| 33 |
mock_exit.assert_called_once_with(1) |