Revised HASS Core test

Changed the HASS Core test that tested KeyboardInterrupt handling to
now test SIGTERM handling. KeyboardInterrupts are no longer handled in
the HASS application process as they are handled in the HASS parent
process. SIGTERM is the proper way to now stop HASS.
This commit is contained in:
Ryan Kraus 2016-01-29 22:42:39 -05:00
parent b56369855a
commit 106c53abf1

View File

@ -7,6 +7,7 @@ Provides tests to verify that Home Assistant core works.
# pylint: disable=protected-access,too-many-public-methods # pylint: disable=protected-access,too-many-public-methods
# pylint: disable=too-few-public-methods # pylint: disable=too-few-public-methods
import os import os
import signal
import unittest import unittest
from unittest.mock import patch from unittest.mock import patch
import time import time
@ -79,15 +80,15 @@ class TestHomeAssistant(unittest.TestCase):
self.assertFalse(blocking_thread.is_alive()) self.assertFalse(blocking_thread.is_alive())
def test_stopping_with_keyboardinterrupt(self): def test_stopping_with_sigterm(self):
calls = [] calls = []
self.hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, self.hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP,
lambda event: calls.append(1)) lambda event: calls.append(1))
def raise_keyboardinterrupt(length): def send_sigterm(length):
raise KeyboardInterrupt os.kill(os.getpid(), signal.SIGTERM)
with patch('homeassistant.core.time.sleep', raise_keyboardinterrupt): with patch('homeassistant.core.time.sleep', send_sigterm):
self.hass.block_till_stopped() self.hass.block_till_stopped()
self.assertEqual(1, len(calls)) self.assertEqual(1, len(calls))