mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-19 15:28:28 +01:00
test: run: refactor signal handler tests
Current test is testing for signal handler restoration in an obscure way. As a result, the test wasn't actually testing anything, because KeyboardInterrupt is raised by default_int_handler, and so raising it in a mock won't be caught by signal handlers, because they are dealing with real singnals. Fix #2406 Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
@@ -2,6 +2,10 @@ from dvc.path_info import PathInfo
|
||||
from dvc.stage import Stage, StageUpdateError
|
||||
from dvc.dependency.repo import DependencyREPO
|
||||
|
||||
import signal
|
||||
import threading
|
||||
import subprocess
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
from unittest import TestCase
|
||||
@@ -82,3 +86,24 @@ def test_stage_update(mocker):
|
||||
is_repo_import.return_value = False
|
||||
with pytest.raises(StageUpdateError):
|
||||
stage.update()
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
not isinstance(threading.current_thread(), threading._MainThread),
|
||||
reason="Not running in the main thread.",
|
||||
)
|
||||
def test_stage_run_ignore_sigint(mocker):
|
||||
stage = Stage(None, "path")
|
||||
|
||||
proc = mocker.Mock()
|
||||
communicate = mocker.Mock()
|
||||
proc.configure_mock(returncode=0, communicate=communicate)
|
||||
popen = mocker.patch.object(subprocess, "Popen", return_value=proc)
|
||||
signal_mock = mocker.patch("signal.signal")
|
||||
|
||||
stage._run()
|
||||
|
||||
assert popen.called_once()
|
||||
assert communicate.called_once_with()
|
||||
signal_mock.assert_any_call(signal.SIGINT, signal.SIG_IGN)
|
||||
assert signal.getsignal(signal.SIGINT) == signal.default_int_handler
|
||||
|
||||
Reference in New Issue
Block a user