|
| 1 | +import os |
1 | 2 | import re
|
2 | 3 | import sys
|
3 | 4 | import textwrap
|
@@ -1147,6 +1148,46 @@ def test_succeed():
|
1147 | 1148 | assert_outcomes(rr, {"passed": 1})
|
1148 | 1149 |
|
1149 | 1150 |
|
| 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 | + |
1150 | 1191 | def test_sigint_for_regular_tests(testdir, cmd_opts):
|
1151 | 1192 | test_file = """
|
1152 | 1193 | import os
|
|
0 commit comments