| 905 | "exception, exval", [(EngineError, 1), (InvalidPythonProcess, 2)] |
| 906 | ) |
| 907 | def test_process_core_error(exception, exval, capsys): |
| 908 | # GIVEN |
| 909 | |
| 910 | argv = ["pystack", "core", "corefile", "executable"] |
| 911 | |
| 912 | # WHEN |
| 913 | |
| 914 | with patch( |
| 915 | "pystack.__main__.get_process_threads_for_core" |
| 916 | ) as get_process_threads_mock, patch( |
| 917 | "pystack.__main__.print_thread" |
| 918 | ) as print_thread_mock, patch( |
| 919 | "sys.argv", argv |
| 920 | ), patch( |
| 921 | "pathlib.Path.exists", return_value=True |
| 922 | ), patch( |
| 923 | "pystack.__main__.CoreFileAnalyzer" |
| 924 | ), patch( |
| 925 | "pystack.__main__.is_elf", return_value=True |
| 926 | ), patch( |
| 927 | "pystack.__main__.is_gzip", return_value=False |
| 928 | ): |
| 929 | # THEN |
| 930 | get_process_threads_mock.side_effect = exception("Oh no!") |
| 931 | with pytest.raises(SystemExit) as excinfo: |
| 932 | main() |
| 933 | assert excinfo.value.code == exval |
| 934 | |
| 935 | # THEN |
| 936 | |
| 937 | get_process_threads_mock.assert_called_once() |
| 938 | print_thread_mock.assert_not_called() |
| 939 | capture = capsys.readouterr() |
| 940 | assert "Oh no!" in capture.err |
| 941 | |
| 942 | |
| 943 | def test_process_core_exhaustive(): |