Skip to content

Commit c18d5db

Browse files
committed
test: Add test cases for signal dump
Signed-off-by: Arkady Gilinsky <[email protected]>
1 parent b4f3467 commit c18d5db

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

tests/test_process.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,51 @@ def test_module_name(self) -> None:
689689
out = self.run_command("python -m coverage")
690690
assert "Use 'coverage help' for help" in out
691691

692+
@pytest.mark.skipif(env.WINDOWS, reason="This test is not for Windows")
693+
def test_save_signal(self) -> None:
694+
test_file = "dummy_hello.py"
695+
self.assert_doesnt_exist(".coverage")
696+
self.make_file(test_file, """\
697+
import os
698+
import signal
699+
700+
print(f"Sending SIGUSR1 to process {os.getpid()}")
701+
os.kill(os.getpid(), signal.SIGUSR1)
702+
os.kill(os.getpid(), signal.SIGKILL)
703+
704+
print('Done and goodbye')
705+
""")
706+
covered_lines = 4
707+
dummy_prc = self.run_command(f"coverage run --save-signal USR1 {test_file}")
708+
self.assert_exists(".coverage")
709+
data = coverage.CoverageData()
710+
data.read()
711+
assert line_counts(data)[test_file] == covered_lines
712+
out = self.run_command("coverage report")
713+
assert out == textwrap.dedent("""\
714+
Name Stmts Miss Cover
715+
------------------------------------
716+
dummy_hello.py 6 2 67%
717+
------------------------------------
718+
TOTAL 6 2 67%
719+
""")
720+
721+
# Negative test for signal
722+
@pytest.mark.skipif(env.WINDOWS, reason="This test is not for Windows")
723+
def test_save_signal(self) -> None:
724+
test_file = "dummy_hello.py"
725+
self.assert_doesnt_exist(".coverage")
726+
self.make_file(test_file, """\
727+
import os
728+
import signal
729+
730+
os.kill(os.getpid(), signal.SIGKILL)
731+
732+
print('Done and goodbye')
733+
""")
734+
dummy_prc = self.run_command(f"coverage run --save-signal USR1 {test_file}")
735+
self.assert_doesnt_exist(".coverage")
736+
692737

693738
TRY_EXECFILE = os.path.join(os.path.dirname(__file__), "modules/process_test/try_execfile.py")
694739

0 commit comments

Comments
 (0)