Skip to content

Commit

Permalink
Fix test_format_error_message
Browse files Browse the repository at this point in the history
  • Loading branch information
kozlovsky committed Feb 5, 2024
1 parent eebf7ee commit 297414e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/tribler/core/utilities/tests/test_exit_codes.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
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'
assert get_error_name(99) == 'EXITCODE_DATABASE_IS_CORRUPTED'
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'
17 changes: 14 additions & 3 deletions src/tribler/gui/tests/test_core_manager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import errno
import os
import sys
import time
from unittest.mock import MagicMock, patch
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 297414e

Please sign in to comment.