diff --git a/src/tribler/core/utilities/tests/test_exit_codes.py b/src/tribler/core/utilities/tests/test_exit_codes.py index d576462d789..212d5e52cb0 100644 --- a/src/tribler/core/utilities/tests/test_exit_codes.py +++ b/src/tribler/core/utilities/tests/test_exit_codes.py @@ -1,9 +1,8 @@ -from unittest.mock import patch +import os from tribler.core.utilities.exit_codes import get_error_name -@patch('os.name', 'nt') def test_exit_codes(): assert get_error_name(0) == 'EXITCODE_OK' assert get_error_name(1) == 'EXITCODE_APPLICATION_ERROR' @@ -11,7 +10,8 @@ def test_exit_codes(): assert get_error_name(98) == 'EXITCODE_ANOTHER_GUI_PROCESS_IS_RUNNING' assert get_error_name(97) == 'EXITCODE_ANOTHER_CORE_PROCESS_IS_RUNNING' - assert get_error_name(-1073741819) == 'STATUS_ACCESS_VIOLATION' - assert get_error_name(-1073740940) == 'STATUS_HEAP_CORRUPTION' + if os.name == 'nt': + assert get_error_name(-1073741819) == 'STATUS_ACCESS_VIOLATION' + assert get_error_name(-1073740940) == 'STATUS_HEAP_CORRUPTION' assert get_error_name(1000000) == 'Unknown error' diff --git a/src/tribler/gui/tests/test_core_manager.py b/src/tribler/gui/tests/test_core_manager.py index 0a481f49123..9379127227e 100644 --- a/src/tribler/gui/tests/test_core_manager.py +++ b/src/tribler/gui/tests/test_core_manager.py @@ -1,4 +1,5 @@ import errno +import os import sys import time from unittest.mock import MagicMock, patch @@ -141,10 +142,20 @@ def test_decode_raw_core_output(core_manager): def test_format_error_message(): - actual = CoreManager.format_error_message(exit_code=errno.ENOENT, exit_status=1) - expected = '''The Tribler core has unexpectedly finished with exit code 2 (0x2) and status: 1. + actual = CoreManager.format_error_message(exit_code=99, exit_status=1) + expected = '''The Tribler core has unexpectedly finished with exit code 99 (0x63) and status: 1. -Error message: No such file or directory''' +Error message: EXITCODE_DATABASE_IS_CORRUPTED''' + + assert actual == expected + + +@pytest.mark.skipif(os.name != 'nt', reason='Test is only for Windows') +def test_format_error_message_windows(): + actual = CoreManager.format_error_message(exit_code=-1073741819, exit_status=1) + expected = '''The Tribler core has unexpectedly finished with exit code -1073741819 (0xc0000005) and status: 1. + +Error message: STATUS_ACCESS_VIOLATION''' assert actual == expected