Skip to content

Commit

Permalink
fix pystack test
Browse files Browse the repository at this point in the history
  • Loading branch information
jhaigh0 committed Jan 16, 2025
1 parent 09aa698 commit b0238c0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
log = Logger("errorreports (pystack analysis)")


def retrieve_thread_traces_from_coredump_file() -> bytes | None:
def retrieve_thread_traces_from_coredump_file() -> bytes:
# Locate the core dumps dir
core_dumps_path = None
try:
core_dumps_path = _get_core_dumps_dir()
except ValueError as e:
log.error(str(e))
return None
return b""

# Get most recent dump file, check it's python (can you check it's from workbench?)
core_file = _get_most_recent_core_dump_file(core_dumps_path)
if core_file is None:
return None
return b""

# Run file through pystack and capture output
pystack_output = _get_output_from_pystack(core_file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +

from pathlib import Path
from tempfile import NamedTemporaryFile, TemporaryDirectory
from time import sleep
from unittest import TestCase
from unittest.mock import MagicMock, patch

from mantid.kernel.environment import is_linux
from mantidqt.dialogs.errorreports.run_pystack import _get_core_dumps_dir, _get_most_recent_core_dump_file


class TestRunPystack(TestCase):
MODULE_PATH = "mantidqt.dialogs.errorreports.run_pystack"

def setUp(self) -> None:
if not is_linux():
self.skipTest("pystack is only run on linux")

@patch(f"{MODULE_PATH}.ConfigService")
def test_get_core_dumps_dir_raises_if_not_set(self, mock_config_service: MagicMock):
mock_config_service.getString.return_value = ""
Expand Down Expand Up @@ -49,16 +55,16 @@ def test_get_most_recent_core_dump_file_gets_the_latest_file(self, mock_check_wo
for name in file_names:
open(f"{tmp_dir}/{name}", "a").close()
sleep(0.1)
latest_file = _get_most_recent_core_dump_file(tmp_dir)
latest_file = _get_most_recent_core_dump_file(Path(tmp_dir))
self.assertEqual(latest_file.name, file_names[-1])

@patch(f"{MODULE_PATH}.CORE_DUMP_RECENCY_LIMIT", 0.5)
def test_get_most_recent_core_dump_file_returns_none_if_there_are_no_new_files(self):
with TemporaryDirectory() as tmp_dir:
open(f"{tmp_dir}/test", "a").close()
sleep(0.6)
self.assertIsNone(_get_most_recent_core_dump_file(tmp_dir))
self.assertIsNone(_get_most_recent_core_dump_file(Path(tmp_dir)))

def test_get_most_recent_core_dump_file_returns_none_if_the_dir_is_empty(self):
with TemporaryDirectory() as tmp_dir:
self.assertIsNone(_get_most_recent_core_dump_file(tmp_dir))
self.assertIsNone(_get_most_recent_core_dump_file(Path(tmp_dir)))

0 comments on commit b0238c0

Please sign in to comment.