|
| 1 | +import os |
1 | 2 | import sys
|
2 | 3 | import textwrap
|
3 | 4 |
|
@@ -1138,3 +1139,43 @@ def test_succeed():
|
1138 | 1139 | testdir.makepyfile(test_file)
|
1139 | 1140 | rr = testdir.run(*cmd_opts, timeout=timeout)
|
1140 | 1141 | assert_outcomes(rr, {"passed": 1})
|
| 1142 | + |
| 1143 | + |
| 1144 | +@pytest.mark.parametrize(argnames="kill", argvalues=[False, True]) |
| 1145 | +@pytest.mark.parametrize(argnames="event", argvalues=["shutdown"]) |
| 1146 | +@pytest.mark.parametrize( |
| 1147 | + argnames="phase", |
| 1148 | + argvalues=["before", "during", "after"], |
| 1149 | +) |
| 1150 | +def test_addSystemEventTrigger(testdir, cmd_opts, kill, event, phase): |
| 1151 | + is_win32 = sys.platform == "win32" |
| 1152 | + is_qt = os.environ.get("REACTOR", "").startswith("qt") |
| 1153 | + is_kill = kill |
| 1154 | + |
| 1155 | + if (is_win32 or is_qt) and is_kill: |
| 1156 | + pytest.xfail(reason="Needs handled on Windows and with qt5reactor.") |
| 1157 | + |
| 1158 | + test_string = "1kljgf90u0lkj13l4jjklsfdo89898y24hlkjalkjs38" |
| 1159 | + |
| 1160 | + test_file = """ |
| 1161 | + import os |
| 1162 | + import signal |
| 1163 | +
|
| 1164 | + import pytest_twisted |
| 1165 | +
|
| 1166 | + def output_stuff(): |
| 1167 | + print({test_string!r}) |
| 1168 | +
|
| 1169 | + @pytest_twisted.inlineCallbacks |
| 1170 | + def test_succeed(): |
| 1171 | + from twisted.internet import reactor |
| 1172 | + reactor.addSystemEventTrigger({phase!r}, {event!r}, output_stuff) |
| 1173 | +
|
| 1174 | + if {kill!r}: |
| 1175 | + os.kill(os.getpid(), signal.SIGINT) |
| 1176 | +
|
| 1177 | + yield |
| 1178 | + """.format(kill=kill, event=event, phase=phase, test_string=test_string) |
| 1179 | + testdir.makepyfile(test_file) |
| 1180 | + rr = testdir.run(*cmd_opts, timeout=timeout) |
| 1181 | + rr.stdout.fnmatch_lines(lines2=[test_string]) |
0 commit comments