From d4974b1229d9376ed4952e1929ec615b5f2dace5 Mon Sep 17 00:00:00 2001 From: Alex Pyrgiotis Date: Tue, 9 Apr 2024 14:00:29 +0300 Subject: [PATCH] tests: Add termination tests for Dummy provider Add termination tests for the Dummy provider, so that we can have cross-platform coverage in our Windows/macOS CI runners, which can't use the Container isolation providers. --- tests/isolation_provider/test_dummy.py | 53 ++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/isolation_provider/test_dummy.py diff --git a/tests/isolation_provider/test_dummy.py b/tests/isolation_provider/test_dummy.py new file mode 100644 index 0000000..061eb5a --- /dev/null +++ b/tests/isolation_provider/test_dummy.py @@ -0,0 +1,53 @@ +import os +import subprocess + +import pytest +from pytest_mock import MockerFixture + +from dangerzone.conversion import errors +from dangerzone.document import Document +from dangerzone.isolation_provider.base import IsolationProvider +from dangerzone.isolation_provider.dummy import Dummy + +from .base import IsolationProviderTermination, IsolationProviderTest + + +class DummyWait(Dummy): + """Dummy isolation provider that spawns a blocking process.""" + + def start_doc_to_pixels_proc(self, document: Document) -> subprocess.Popen: + return subprocess.Popen( + ["python3"], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) + + def terminate_doc_to_pixels_proc( + self, document: Document, p: subprocess.Popen + ) -> None: + p.terminate() + + +@pytest.fixture +def provider_wait() -> DummyWait: + return DummyWait() + + +@pytest.mark.skipif( + os.environ.get("DUMMY_CONVERSION", False) == False, + reason="can only run for dummy conversions", +) +class TestDummyTermination(IsolationProviderTermination): + + def test_failed( + self, + provider_wait: IsolationProvider, + mocker: MockerFixture, + ) -> None: + mocker.patch.object( + provider_wait, + "get_proc_exception", + return_value=errors.DocFormatUnsupported(), + ) + super().test_failed(provider_wait, mocker)