Skip to content

Commit 58a3cc2

Browse files
committed
Merge branch 'main' into disable_signal_handlers
2 parents dcd9208 + 36ab2ba commit 58a3cc2

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

testing/test_basic.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import re
23
import sys
34
import textwrap
@@ -1147,6 +1148,46 @@ def test_succeed():
11471148
assert_outcomes(rr, {"passed": 1})
11481149

11491150

1151+
@pytest.mark.parametrize(argnames="kill", argvalues=[False, True])
1152+
@pytest.mark.parametrize(argnames="event", argvalues=["shutdown"])
1153+
@pytest.mark.parametrize(
1154+
argnames="phase",
1155+
argvalues=["before", "during", "after"],
1156+
)
1157+
def test_addSystemEventTrigger(testdir, cmd_opts, kill, event, phase):
1158+
is_win32 = sys.platform == "win32"
1159+
is_qt = os.environ.get("REACTOR", "").startswith("qt")
1160+
is_kill = kill
1161+
1162+
if (is_win32 or is_qt) and is_kill:
1163+
pytest.xfail(reason="Needs handled on Windows and with qt5reactor.")
1164+
1165+
test_string = "1kljgf90u0lkj13l4jjklsfdo89898y24hlkjalkjs38"
1166+
1167+
test_file = """
1168+
import os
1169+
import signal
1170+
1171+
import pytest_twisted
1172+
1173+
def output_stuff():
1174+
print({test_string!r})
1175+
1176+
@pytest_twisted.inlineCallbacks
1177+
def test_succeed():
1178+
from twisted.internet import reactor
1179+
reactor.addSystemEventTrigger({phase!r}, {event!r}, output_stuff)
1180+
1181+
if {kill!r}:
1182+
os.kill(os.getpid(), signal.SIGINT)
1183+
1184+
yield
1185+
""".format(kill=kill, event=event, phase=phase, test_string=test_string)
1186+
testdir.makepyfile(test_file)
1187+
rr = testdir.run(*cmd_opts, timeout=timeout)
1188+
rr.stdout.fnmatch_lines(lines2=[test_string])
1189+
1190+
11501191
def test_sigint_for_regular_tests(testdir, cmd_opts):
11511192
test_file = """
11521193
import os

0 commit comments

Comments
 (0)