File: test_signal_handler.py

package info (click to toggle)
cloud-init 25.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,412 kB
  • sloc: python: 135,894; sh: 3,883; makefile: 141; javascript: 30; xml: 22
file content (31 lines) | stat: -rw-r--r-- 857 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""cloudinit.signal_handler tests"""

import re
import signal
import sys

from cloudinit.signal_handler import _handle_exit


class TestSignalHandler:
    """Test signal_handler.py"""

    def test_handle_exit(self, mocker, caplog):
        """Test handle_exit()"""
        mocker.patch("cloudinit.signal_handler.sys.exit")
        mocker.patch("cloudinit.log.log_util.write_to_console")

        frame = sys._getframe()
        _handle_exit(signal.Signals.SIGHUP, frame)

        record = caplog.records[0]
        assert record.levelname == "INFO"
        assert re.match(
            (
                r"Received signal SIGHUP resulting in exit. Cause:\n"
                r"  Filename:.*test_signal_handler.py\n"
                r"  Function: test_handle_exit\n"
                r"  Line number: \d+"
            ),
            record.message,
        )