Use TestCase.addCleanup (#36560)

This commit is contained in:
Paulus Schoutsen 2020-06-08 12:26:40 -07:00 committed by GitHub
parent 85ba29012f
commit c33edbe5bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
103 changed files with 179 additions and 254 deletions

View file

@ -125,10 +125,7 @@ class TestAlert(unittest.TestCase):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self._setup_notify()
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
def _setup_notify(self):
events = []

View file

@ -30,8 +30,9 @@ class TestApns(unittest.TestCase):
def setUp(self): # pylint: disable=invalid-name
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()

View file

@ -20,8 +20,9 @@ class TestAuroraSensorSetUp(unittest.TestCase):
self.hass.config.latitude = self.lat
self.hass.config.longitude = self.lon
self.entities = []
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()

View file

@ -203,8 +203,9 @@ class TestBlackbirdMediaPlayer(unittest.TestCase):
self.media_player = self.hass.data[DATA_BLACKBIRD]["/dev/ttyUSB0-3"]
self.media_player.hass = self.hass
self.media_player.entity_id = "media_player.zone_3"
self.addCleanup(self.tear_down_cleanup)
def tearDown(self):
def tear_down_cleanup(self):
"""Tear down the test case."""
self.hass.stop()

View file

@ -60,10 +60,7 @@ class TestBOMWeatherSensor(unittest.TestCase):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.config = VALID_CONFIG
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
@patch("requests.get", side_effect=mocked_requests)
def test_setup(self, mock_get):

View file

@ -43,8 +43,9 @@ class TestCanary(unittest.TestCase):
def setUp(self):
"""Initialize values for this test case class."""
self.hass = get_test_home_assistant()
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()

View file

@ -34,10 +34,7 @@ class TestCanarySensorSetup(unittest.TestCase):
"""Initialize values for this testcase class."""
self.hass = get_test_home_assistant()
self.config = copy.deepcopy(VALID_CONFIG)
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
def test_setup_sensors(self):
"""Test the sensor setup."""

View file

@ -23,10 +23,7 @@ class TestCoinMarketCapSensor(unittest.TestCase):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.config = VALID_CONFIG
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
@patch(
"coinmarketcap.Market.ticker",

View file

@ -14,10 +14,7 @@ class TestCommandSensorBinarySensor(unittest.TestCase):
def setUp(self):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
def test_setup(self):
"""Test sensor setup."""

View file

@ -16,8 +16,9 @@ class TestCommandLine(unittest.TestCase):
def setUp(self): # pylint: disable=invalid-name
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop down everything that was started."""
self.hass.stop()

View file

@ -14,10 +14,7 @@ class TestCommandSensorSensor(unittest.TestCase):
def setUp(self):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
def update_side_effect(self, data):
"""Side effect function for mocking CommandSensorData.update()."""

View file

@ -20,10 +20,7 @@ class TestCommandSwitch(unittest.TestCase):
def setUp(self):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
def test_state_none(self):
"""Test with none state."""

View file

@ -15,11 +15,7 @@ class TestConfigurator(unittest.TestCase):
def setUp(self):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
# pylint: disable=invalid-name
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
def test_request_least_info(self):
"""Test request config with least amount of data."""

View file

@ -105,8 +105,9 @@ class TestDarkSkySetup(unittest.TestCase):
self.lat = self.hass.config.latitude = 37.8267
self.lon = self.hass.config.longitude = -122.423
self.entities = []
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()

View file

@ -23,8 +23,9 @@ class TestDarkSky(unittest.TestCase):
self.hass.config.units = METRIC_SYSTEM
self.lat = self.hass.config.latitude = 37.8267
self.lon = self.hass.config.longitude = -122.423
self.addCleanup(self.tear_down_cleanup)
def tearDown(self):
def tear_down_cleanup(self):
"""Stop down everything that was started."""
self.hass.stop()

View file

@ -21,8 +21,9 @@ class TestDatadog(unittest.TestCase):
def setUp(self): # pylint: disable=invalid-name
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()

View file

@ -26,10 +26,7 @@ class TestDemoPlatform(unittest.TestCase):
def setUp(self):
"""Initialize values for this testcase class."""
self.hass = get_test_home_assistant()
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
def test_setup_platform(self):
"""Test setup of demo platform via configuration."""

View file

@ -32,8 +32,9 @@ class TestNotifyDemo(unittest.TestCase):
self.events.append(event)
self.hass.bus.listen(demo.EVENT_NOTIFY, record_event)
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop down everything that was started."""
self.hass.stop()

View file

@ -24,8 +24,9 @@ class TestDemoRemote(unittest.TestCase):
)
self.hass.block_till_done()
# pylint: disable=invalid-name
def tearDown(self):
self.addCleanup(self.tear_down_cleanup)
def tear_down_cleanup(self):
"""Stop down everything that was started."""
self.hass.stop()

View file

@ -17,10 +17,7 @@ class TestDteEnergyBridgeSetup(unittest.TestCase):
def setUp(self):
"""Initialize values for this testcase class."""
self.hass = get_test_home_assistant()
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
def test_setup_with_config(self):
"""Test the platform setup with configuration."""

View file

@ -111,8 +111,9 @@ class DysonTest(unittest.TestCase):
def setUp(self): # pylint: disable=invalid-name
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()

View file

@ -136,8 +136,9 @@ class DysonSetupTest(unittest.TestCase):
def setUp(self): # pylint: disable=invalid-name
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()
@ -173,8 +174,9 @@ class DysonTest(unittest.TestCase):
def setUp(self): # pylint: disable=invalid-name
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()

View file

@ -41,8 +41,9 @@ class DysonTest(unittest.TestCase):
def setUp(self): # pylint: disable=invalid-name
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()

View file

@ -84,8 +84,9 @@ class DysonTest(unittest.TestCase):
def setUp(self): # pylint: disable=invalid-name
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()

View file

@ -70,8 +70,9 @@ class DysonTest(unittest.TestCase):
def setUp(self): # pylint: disable=invalid-name
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()

View file

@ -75,8 +75,9 @@ class TestEfergySensor(unittest.TestCase):
"""Initialize values for this test case class."""
self.hass = get_test_home_assistant()
self.config = ONE_SENSOR_CONFIG
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()

View file

@ -66,10 +66,7 @@ class TestBanSensor(unittest.TestCase):
def setUp(self):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
@patch("os.path.isfile", Mock(return_value=True))
def test_setup(self):

View file

@ -21,8 +21,9 @@ class TestFanEntity(unittest.TestCase):
def setUp(self):
"""Set up test data."""
self.fan = BaseFan()
self.addCleanup(self.tear_down_cleanup)
def tearDown(self):
def tear_down_cleanup(self):
"""Tear down unit test data."""
self.fan = None

View file

@ -42,10 +42,7 @@ class TestFeedreaderComponent(unittest.TestCase):
data_file = self.hass.config.path(f"{feedreader.DOMAIN}.pickle")
if exists(data_file):
remove(data_file)
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
def test_setup_one_feed(self):
"""Test the general setup of this component."""

View file

@ -17,8 +17,9 @@ class TestNotifyFile(unittest.TestCase):
def setUp(self): # pylint: disable=invalid-name
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop down everything that was started."""
self.hass.stop()

View file

@ -42,10 +42,7 @@ class TestGeoRssServiceUpdater(unittest.TestCase):
"""Initialize values for this testcase class."""
self.hass = get_test_home_assistant()
# self.config = VALID_CONFIG_WITHOUT_CATEGORIES
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
@staticmethod
def _generate_mock_feed_entry(

View file

@ -40,10 +40,7 @@ class TestGoogleWifiSetup(unittest.TestCase):
def setUp(self):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
@requests_mock.Mocker()
def test_setup_minimum(self, mock_req):
@ -92,10 +89,7 @@ class TestGoogleWifiSensor(unittest.TestCase):
self.hass = get_test_home_assistant()
with requests_mock.Mocker() as mock_req:
self.setup_api(MOCK_DATA, mock_req)
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
def setup_api(self, data, mock_req):
"""Set up API with fake data."""

View file

@ -28,11 +28,7 @@ class TestComponentsGroup(unittest.TestCase):
def setUp(self):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
# pylint: disable=invalid-name
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
def test_setup_group_with_mixed_groupable_states(self):
"""Try to set up a group with mixed groupable states."""

View file

@ -63,8 +63,9 @@ class TestNotifyGroup(unittest.TestCase):
).result()
assert self.service is not None
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()

View file

@ -87,10 +87,7 @@ class TestHDDTempSensor(unittest.TestCase):
"model": "WDC WD15EARS-00Z5B1",
},
}
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
@patch("telnetlib.Telnet", new=TelnetMock)
def test_hddtemp_min_config(self):

View file

@ -26,8 +26,9 @@ class TestComponentHistory(unittest.TestCase):
def setUp(self): # pylint: disable=invalid-name
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()

View file

@ -23,10 +23,7 @@ class TestHistoryStatsSensor(unittest.TestCase):
def setUp(self):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
def test_setup(self):
"""Test the history statistics sensor setup."""

View file

@ -120,11 +120,7 @@ class TestComponentsCore(unittest.TestCase):
self.hass.states.set("light.Bowl", STATE_ON)
self.hass.states.set("light.Ceiling", STATE_OFF)
# pylint: disable=invalid-name
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
def test_is_on(self):
"""Test is_on method."""

View file

@ -14,8 +14,9 @@ class TestHomematicNotify(unittest.TestCase):
def setUp(self): # pylint: disable=invalid-name
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop down everything that was started."""
self.hass.stop()

View file

@ -37,10 +37,7 @@ class EmailContentSensor(unittest.TestCase):
def setUp(self):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
def test_allowed_sender(self):
"""Test emails from allowed sender."""

View file

@ -29,8 +29,9 @@ class TestInfluxDB(unittest.TestCase):
self.hass = get_test_home_assistant()
self.handler_method = None
self.hass.bus.listen = mock.Mock()
self.addCleanup(self.tear_down_cleanup)
def tearDown(self):
def tear_down_cleanup(self):
"""Clear data."""
self.hass.stop()

View file

@ -45,8 +45,9 @@ class TestKiraSetup(unittest.TestCase):
self._module_patcher.start()
self.work_dir = tempfile.mkdtemp()
self.addCleanup(self.tear_down_cleanup)
def tearDown(self):
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()
self._module_patcher.stop()

View file

@ -30,10 +30,7 @@ class TestKiraSensor(unittest.TestCase):
self.mock_kira = MagicMock()
self.hass.data[kira.DOMAIN] = {kira.CONF_REMOTE: {}}
self.hass.data[kira.DOMAIN][kira.CONF_REMOTE]["kira"] = self.mock_kira
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
def test_service_call(self):
"""Test Kira's ability to send commands."""

View file

@ -28,10 +28,7 @@ class TestKiraSensor(unittest.TestCase):
mock_kira = MagicMock()
self.hass.data[kira.DOMAIN] = {kira.CONF_SENSOR: {}}
self.hass.data[kira.DOMAIN][kira.CONF_SENSOR]["kira"] = mock_kira
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
# pylint: disable=protected-access
def test_kira_sensor_callback(self):

View file

@ -32,9 +32,9 @@ class TestLight(unittest.TestCase):
def setUp(self):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.addCleanup(self.tear_down_cleanup)
# pylint: disable=invalid-name
def tearDown(self):
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()

View file

@ -44,10 +44,7 @@ class TestComponentLogbook(unittest.TestCase):
init_recorder_component(self.hass) # Force an in memory DB
with patch("homeassistant.components.http.start_http_server_and_save_config"):
assert setup_component(self.hass, logbook.DOMAIN, self.EMPTY_CONFIG)
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
def test_service_call_create_logbook_entry(self):
"""Test if service call create log book entry."""

View file

@ -16,8 +16,9 @@ class TestLogentries(unittest.TestCase):
def setUp(self): # pylint: disable=invalid-name
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()

View file

@ -18,10 +18,7 @@ class TestLondonAirSensor(unittest.TestCase):
"""Initialize values for this testcase class."""
self.hass = get_test_home_assistant()
self.config = VALID_CONFIG
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
@requests_mock.Mocker()
def test_setup(self, mock_req):

View file

@ -35,8 +35,9 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
self.hass = get_test_home_assistant()
self.hass.config_entries._async_schedule_save = Mock()
self.mock_publish = mock_mqtt_component(self.hass)
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop down everything that was started."""
self.hass.stop()

View file

@ -146,8 +146,9 @@ class TestAsyncMediaPlayer(unittest.TestCase):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.player = AsyncMediaPlayer(self.hass)
self.addCleanup(self.tear_down_cleanup)
def tearDown(self):
def tear_down_cleanup(self):
"""Shut down test instance."""
self.hass.stop()
@ -207,8 +208,9 @@ class TestSyncMediaPlayer(unittest.TestCase):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.player = SyncMediaPlayer(self.hass)
self.addCleanup(self.tear_down_cleanup)
def tearDown(self):
def tear_down_cleanup(self):
"""Shut down test instance."""
self.hass.stop()

View file

@ -28,10 +28,7 @@ class TestMochadSwitchSetup(unittest.TestCase):
def setUp(self):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
@mock.patch("homeassistant.components.mochad.light.MochadLight")
def test_setup_adds_proper_devices(self, mock_light):

View file

@ -30,10 +30,7 @@ class TestMochadSwitchSetup(unittest.TestCase):
def setUp(self):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
@mock.patch("homeassistant.components.mochad.switch.MochadSwitch")
def test_setup_adds_proper_devices(self, mock_switch):

View file

@ -32,8 +32,9 @@ class TestSensorMoldIndicator(unittest.TestCase):
self.hass.states.set(
"test.indoorhumidity", "50", {ATTR_UNIT_OF_MEASUREMENT: UNIT_PERCENTAGE}
)
self.addCleanup(self.tear_down_cleanup)
def tearDown(self):
def tear_down_cleanup(self):
"""Stop down everything that was started."""
self.hass.stop()

View file

@ -92,8 +92,9 @@ class TestMQTTComponent(unittest.TestCase):
self.hass = get_test_home_assistant()
mock_mqtt_component(self.hass)
self.calls = []
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()
@ -307,8 +308,9 @@ class TestMQTTCallbacks(unittest.TestCase):
self.hass = get_test_home_assistant()
mock_mqtt_client(self.hass)
self.calls = []
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()

View file

@ -79,10 +79,7 @@ class TestNSWFuelStation(unittest.TestCase):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.config = VALID_CONFIG
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
@patch(
"homeassistant.components.nsw_fuel_station.sensor.FuelCheckClient",

View file

@ -36,8 +36,9 @@ class TestNX584SensorSetup(unittest.TestCase):
client = nx584_client.Client.return_value
client.list_zones.return_value = self.fake_zones
client.get_version.return_value = "1.1"
self.addCleanup(self.tear_down_cleanup)
def tearDown(self):
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()
self._mock_client.stop()

View file

@ -21,8 +21,9 @@ class TestOpenHardwareMonitorSetup(unittest.TestCase):
"port": 8085,
}
}
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()

View file

@ -14,10 +14,7 @@ class TestPanelIframe(unittest.TestCase):
def setUp(self):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
def test_wrong_config(self):
"""Test setup with wrong configuration."""

View file

@ -71,8 +71,9 @@ class TestPilight(unittest.TestCase):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.skip_teardown_stop = False
self.addCleanup(self.tear_down_cleanup)
def tearDown(self):
def tear_down_cleanup(self):
"""Stop everything that was started."""
if not self.skip_teardown_stop:
self.hass.stop()
@ -374,10 +375,7 @@ class TestPilightCallrateThrottler(unittest.TestCase):
def setUp(self): # pylint: disable=invalid-name
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
def test_call_rate_delay_throttle_disabled(self):
"""Test that the limiter is a noop if no delay set."""

View file

@ -25,10 +25,7 @@ class TestProximity(unittest.TestCase):
"zoning",
{"name": "work", "latitude": 2.3, "longitude": 1.3, "radius": 10},
)
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
def test_proximities(self):
"""Test a list of proximities."""

View file

@ -18,8 +18,9 @@ class TestPushBullet(unittest.TestCase):
def setUp(self):
"""Initialize values for this test case class."""
self.hass = get_test_home_assistant()
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that we started."""
self.hass.stop()

View file

@ -208,8 +208,9 @@ class TestRadarrSetup(unittest.TestCase):
self.DEVICES = []
self.hass = get_test_home_assistant()
self.hass.config.time_zone = "America/Los_Angeles"
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()

View file

@ -28,8 +28,9 @@ class TestRecorder(unittest.TestCase):
self.hass = get_test_home_assistant()
init_recorder_component(self.hass)
self.hass.start()
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()

View file

@ -88,8 +88,9 @@ class TestRecorderRuns(unittest.TestCase):
session.query(Events).delete()
session.query(States).delete()
session.query(RecorderRuns).delete()
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Clean up."""
self.session.rollback()

View file

@ -21,8 +21,9 @@ class TestRecorderPurge(unittest.TestCase):
self.hass = get_test_home_assistant()
init_recorder_component(self.hass)
self.hass.start()
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()

View file

@ -157,8 +157,9 @@ class TestRedditSetup(unittest.TestCase):
def setUp(self):
"""Initialize values for this testcase class."""
self.hass = get_test_home_assistant()
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()

View file

@ -30,8 +30,9 @@ class TestConfiguration(unittest.TestCase):
}
}
)
self.addCleanup(self.tear_down_cleanup)
def tearDown(self):
def tear_down_cleanup(self):
"""Exit Home Assistant."""
self.hass.stop()

View file

@ -28,11 +28,7 @@ class TestRemote(unittest.TestCase):
def setUp(self):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
# pylint: disable=invalid-name
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
def test_is_on(self):
"""Test is_on."""

View file

@ -33,10 +33,7 @@ class TestRestBinarySensorSetup(unittest.TestCase):
self.hass = get_test_home_assistant()
# Reset for this test.
self.DEVICES = []
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
def test_setup_missing_config(self):
"""Test setup with configuration missing required entries."""
@ -162,10 +159,7 @@ class TestRestBinarySensor(unittest.TestCase):
self.binary_sensor = rest.RestBinarySensor(
self.hass, self.rest, self.name, self.device_class, self.value_template
)
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
def update_side_effect(self, data):
"""Side effect function for mocking RestData.update()."""

View file

@ -25,10 +25,7 @@ class TestRestSensorSetup(unittest.TestCase):
def setUp(self):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
def test_setup_missing_config(self):
"""Test setup with configuration missing required entries."""
@ -237,10 +234,7 @@ class TestRestSensor(unittest.TestCase):
self.resource_template,
self.json_attrs_path,
)
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
def update_side_effect(self, data, headers):
"""Side effect function for mocking RestData.update()."""

View file

@ -18,8 +18,9 @@ class TestCoverRfxtrx(unittest.TestCase):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
mock_component("rfxtrx")
self.addCleanup(self.tear_down_cleanup)
def tearDown(self):
def tear_down_cleanup(self):
"""Stop everything that was started."""
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS = []
rfxtrx_core.RFX_DEVICES = {}

View file

@ -18,8 +18,9 @@ class TestRFXTRX(unittest.TestCase):
def setUp(self):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.addCleanup(self.tear_down_cleanup)
def tearDown(self):
def tear_down_cleanup(self):
"""Stop everything that was started."""
rfxtrx.RECEIVED_EVT_SUBSCRIBERS = []
rfxtrx.RFX_DEVICES = {}

View file

@ -18,8 +18,9 @@ class TestLightRfxtrx(unittest.TestCase):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
mock_component(self.hass, "rfxtrx")
self.addCleanup(self.tear_down_cleanup)
def tearDown(self):
def tear_down_cleanup(self):
"""Stop everything that was started."""
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS = []
rfxtrx_core.RFX_DEVICES = {}

View file

@ -18,8 +18,9 @@ class TestSensorRfxtrx(unittest.TestCase):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
mock_component(self.hass, "rfxtrx")
self.addCleanup(self.tear_down_cleanup)
def tearDown(self):
def tear_down_cleanup(self):
"""Stop everything that was started."""
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS = []
rfxtrx_core.RFX_DEVICES = {}

View file

@ -18,8 +18,9 @@ class TestSwitchRfxtrx(unittest.TestCase):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
mock_component(self.hass, "rfxtrx")
self.addCleanup(self.tear_down_cleanup)
def tearDown(self):
def tear_down_cleanup(self):
"""Stop everything that was started."""
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS = []
rfxtrx_core.RFX_DEVICES = {}

View file

@ -23,8 +23,9 @@ class TestRing(unittest.TestCase):
"""Initialize values for this test case class."""
self.hass = get_test_home_assistant()
self.config = VALID_CONFIG
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()

View file

@ -35,8 +35,9 @@ class TestScene(unittest.TestCase):
assert not self.light_1.is_on
assert not self.light_2.is_on
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()

View file

@ -73,8 +73,9 @@ class TestScriptComponent(unittest.TestCase):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
# pylint: disable=invalid-name
def tearDown(self):
self.addCleanup(self.tear_down_cleanup)
def tear_down_cleanup(self):
"""Stop down everything that was started."""
self.hass.stop()

View file

@ -45,10 +45,7 @@ class TestSeason(unittest.TestCase):
def setUp(self):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
def test_season_should_be_summer_northern_astronomical(self):
"""Test that season should be summer."""

View file

@ -40,8 +40,9 @@ class TestShellCommand(unittest.TestCase):
"""
self.hass = get_test_home_assistant()
asyncio.get_child_watcher().attach_loop(self.hass.loop)
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()

View file

@ -39,10 +39,7 @@ class TestSigfoxSensor(unittest.TestCase):
def setUp(self):
"""Initialize values for this testcase class."""
self.hass = get_test_home_assistant()
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
def test_invalid_credentials(self):
"""Test for invalid credentials."""

View file

@ -28,8 +28,9 @@ class TestSleepIQBinarySensorSetup(unittest.TestCase):
self.password = "bar"
self.config = {"username": self.username, "password": self.password}
self.DEVICES = []
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()

View file

@ -37,8 +37,9 @@ class TestSleepIQ(unittest.TestCase):
self.config = {
"sleepiq": {"username": self.username, "password": self.password}
}
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()

View file

@ -28,8 +28,9 @@ class TestSleepIQSensorSetup(unittest.TestCase):
self.password = "bar"
self.config = {"username": self.username, "password": self.password}
self.DEVICES = []
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()

View file

@ -34,8 +34,9 @@ class TestNotifySmtp(unittest.TestCase):
"Home Assistant",
0,
)
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop down everything that was started."""
self.hass.stop()

View file

@ -19,8 +19,9 @@ class TestSplunk(unittest.TestCase):
def setUp(self): # pylint: disable=invalid-name
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()

View file

@ -19,8 +19,9 @@ class TestStatsd(unittest.TestCase):
def setUp(self): # pylint: disable=invalid-name
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()

View file

@ -22,11 +22,7 @@ class TestSwitch(unittest.TestCase):
platform.init()
# Switch 1 is ON, switch 2 is OFF
self.switch_1, self.switch_2, self.switch_3 = platform.ENTITIES
# pylint: disable=invalid-name
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
def test_methods(self):
"""Test is_on, turn_on, turn_off methods."""

View file

@ -23,8 +23,9 @@ class TestTimeDateSensor(unittest.TestCase):
"""Initialize values for this testcase class."""
self.hass = get_test_home_assistant()
self.DEFAULT_TIME_ZONE = dt_util.DEFAULT_TIME_ZONE
self.addCleanup(self.tear_down_cleanup)
def tearDown(self):
def tear_down_cleanup(self):
"""Stop everything that was started."""
dt_util.set_default_time_zone(self.DEFAULT_TIME_ZONE)
self.hass.stop()

View file

@ -37,10 +37,7 @@ class TestRMVtransportSensor(unittest.TestCase):
def setUp(self):
"""Set up things to run when tests begin."""
self.hass = get_test_home_assistant()
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
@patch("TransportNSW.TransportNSW.get_departures", side_effect=get_departuresMock)
def test_transportnsw_config(self, mock_get_departures):

View file

@ -49,10 +49,7 @@ class TestUkTransportSensor(unittest.TestCase):
"""Initialize values for this testcase class."""
self.hass = get_test_home_assistant()
self.config = VALID_CONFIG
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
@requests_mock.Mocker()
def test_bus(self, mock_req):

View file

@ -220,8 +220,9 @@ class TestMediaPlayer(unittest.TestCase):
"shuffle": self.mock_shuffle_switch_id,
},
}
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop()

View file

@ -16,10 +16,7 @@ class TestUptimeSensor(unittest.TestCase):
def setUp(self):
"""Set up things to run when tests begin."""
self.hass = get_test_home_assistant()
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
def test_uptime_min_config(self):
"""Test minimum uptime configuration."""

View file

@ -21,10 +21,7 @@ class TestUVCSetup(unittest.TestCase):
def setUp(self):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
@mock.patch("uvcclient.nvr.UVCRemote")
@mock.patch.object(uvc, "UnifiVideoCamera")

View file

@ -42,8 +42,9 @@ class TestVultrBinarySensorSetup(unittest.TestCase):
{CONF_SUBSCRIPTION: "123456", CONF_NAME: "Failed Server"},
{CONF_SUBSCRIPTION: "555555", CONF_NAME: vultr.DEFAULT_NAME},
]
self.addCleanup(self.tear_down_cleanup)
def tearDown(self):
def tear_down_cleanup(self):
"""Stop our started services."""
self.hass.stop()

View file

@ -21,8 +21,9 @@ class TestVultr(unittest.TestCase):
"""Initialize values for this test case class."""
self.hass = get_test_home_assistant()
self.config = VALID_CONFIG
self.addCleanup(self.tear_down_cleanup)
def tearDown(self): # pylint: disable=invalid-name
def tear_down_cleanup(self):
"""Stop everything that we started."""
self.hass.stop()

View file

@ -51,10 +51,7 @@ class TestVultrSensorSetup(unittest.TestCase):
CONF_MONITORED_CONDITIONS: ["pending_charges"],
},
]
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
@requests_mock.Mocker()
def test_sensor(self, mock):

View file

@ -42,8 +42,9 @@ class TestVultrSwitchSetup(unittest.TestCase):
{CONF_SUBSCRIPTION: "123456", CONF_NAME: "Failed Server"},
{CONF_SUBSCRIPTION: "555555", CONF_NAME: vultr.DEFAULT_NAME},
]
self.addCleanup(self.tear_down_cleanup)
def tearDown(self):
def tear_down_cleanup(self):
"""Stop our started services."""
self.hass.stop()

View file

@ -35,10 +35,7 @@ class TestWolSwitch(unittest.TestCase):
def setUp(self):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.addCleanup(self.hass.stop)
@patch("wakeonlan.send_magic_packet", new=send_magic_packet)
@patch("subprocess.call", new=call)

View file

@ -33,8 +33,9 @@ class TestWeather(unittest.TestCase):
self.hass, weather.DOMAIN, {"weather": {"platform": "demo"}}
)
self.hass.block_till_done()
self.addCleanup(self.tear_down_cleanup)
def tearDown(self):
def tear_down_cleanup(self):
"""Stop down everything that was started."""
self.hass.stop()

Some files were not shown because too many files have changed in this diff Show more