mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +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:
@@ -5,9 +5,6 @@ import logging
|
||||
import mock
|
||||
import shutil
|
||||
import filecmp
|
||||
import subprocess
|
||||
import signal
|
||||
import threading
|
||||
import pytest
|
||||
|
||||
from dvc.main import main
|
||||
@@ -272,66 +269,6 @@ class TestRunBadName(TestDvc):
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
not isinstance(threading.current_thread(), threading._MainThread),
|
||||
reason="Not running in the main thread.",
|
||||
)
|
||||
@mock.patch.object(subprocess.Popen, "wait", new=KeyboardInterrupt)
|
||||
def test_keyboard_interrupt(repo_dir, dvc_repo):
|
||||
assert (
|
||||
main(
|
||||
[
|
||||
"run",
|
||||
"-d",
|
||||
repo_dir.FOO,
|
||||
"-d",
|
||||
repo_dir.CODE,
|
||||
"-o",
|
||||
"out",
|
||||
"-f",
|
||||
"out.dvc",
|
||||
"python",
|
||||
repo_dir.CODE,
|
||||
repo_dir.FOO,
|
||||
"out",
|
||||
]
|
||||
)
|
||||
== 1
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
not isinstance(threading.current_thread(), threading._MainThread),
|
||||
reason="Not running in the main thread.",
|
||||
)
|
||||
def test_keyboard_interrupt_after_second_signal_call(
|
||||
mocker, repo_dir, dvc_repo
|
||||
):
|
||||
mocker.patch.object(
|
||||
signal, "signal", side_effect=[None, KeyboardInterrupt]
|
||||
)
|
||||
assert (
|
||||
main(
|
||||
[
|
||||
"run",
|
||||
"-d",
|
||||
repo_dir.FOO,
|
||||
"-d",
|
||||
repo_dir.CODE,
|
||||
"-o",
|
||||
"out",
|
||||
"-f",
|
||||
"out.dvc",
|
||||
"python",
|
||||
repo_dir.CODE,
|
||||
repo_dir.FOO,
|
||||
"out",
|
||||
]
|
||||
)
|
||||
== 252
|
||||
)
|
||||
|
||||
|
||||
class TestRunRemoveOuts(TestDvc):
|
||||
def test(self):
|
||||
with open(self.CODE, "w+") as fobj:
|
||||
|
||||
Reference in New Issue
Block a user