Skip to content

Commit 27ad05a

Browse files
committed
tests: Add terminations tests for the 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.
1 parent abc6684 commit 27ad05a

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import os
2+
import subprocess
3+
4+
import pytest
5+
from pytest_mock import MockerFixture
6+
7+
from dangerzone.conversion import errors
8+
from dangerzone.document import Document
9+
from dangerzone.isolation_provider.base import IsolationProvider
10+
from dangerzone.isolation_provider.dummy import Dummy
11+
12+
from .base import IsolationProviderTermination, IsolationProviderTest
13+
14+
15+
class DummyWait(Dummy):
16+
"""Dummy isolation provider that spawns a blocking process."""
17+
18+
def start_doc_to_pixels_proc(self, document: Document) -> subprocess.Popen:
19+
return subprocess.Popen(
20+
["python3"],
21+
stdin=subprocess.PIPE,
22+
stdout=subprocess.PIPE,
23+
stderr=subprocess.PIPE,
24+
)
25+
26+
def terminate_doc_to_pixels_proc(
27+
self, document: Document, p: subprocess.Popen
28+
) -> None:
29+
p.terminate()
30+
31+
32+
@pytest.fixture
33+
def provider_wait() -> DummyWait:
34+
return DummyWait()
35+
36+
37+
@pytest.mark.skipif(
38+
os.environ.get("DUMMY_CONVERSION", False) == False,
39+
reason="can only run for dummy conversions",
40+
)
41+
class TestDummyTermination(IsolationProviderTermination):
42+
43+
def test_failed(
44+
self,
45+
provider_wait: IsolationProvider,
46+
mocker: MockerFixture,
47+
) -> None:
48+
mocker.patch.object(
49+
provider_wait,
50+
"get_proc_exception",
51+
return_value=errors.DocFormatUnsupported(),
52+
)
53+
super().test_failed(provider_wait, mocker)

0 commit comments

Comments
 (0)