Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: run: refactor signal handler tests #2407

Merged
merged 1 commit into from
Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 0 additions & 63 deletions tests/func/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
import mock
import shutil
import filecmp
import subprocess
import signal
import threading
import pytest

from dvc.main import main
Expand Down Expand Up @@ -272,66 +269,6 @@ def test_not_found(self):
)


@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:
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/test_stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
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
Expand Down Expand Up @@ -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