Pytest tests (#17750)

* Convert core tests

* Convert component tests to use pytest assert

* Lint 🤷‍♂️

* Fix test

* Fix 3 typos in docs
This commit is contained in:
Paulus Schoutsen 2018-10-24 12:10:05 +02:00 committed by GitHub
parent 4222f7562b
commit 08fe7c3ece
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
223 changed files with 6747 additions and 7237 deletions

View file

@ -31,51 +31,48 @@ class TestSwitch(unittest.TestCase):
def test_methods(self):
"""Test is_on, turn_on, turn_off methods."""
self.assertTrue(setup_component(
assert setup_component(
self.hass, switch.DOMAIN, {switch.DOMAIN: {CONF_PLATFORM: 'test'}}
))
self.assertTrue(switch.is_on(self.hass))
self.assertEqual(
STATE_ON,
self.hass.states.get(switch.ENTITY_ID_ALL_SWITCHES).state)
self.assertTrue(switch.is_on(self.hass, self.switch_1.entity_id))
self.assertFalse(switch.is_on(self.hass, self.switch_2.entity_id))
self.assertFalse(switch.is_on(self.hass, self.switch_3.entity_id))
)
assert switch.is_on(self.hass)
assert STATE_ON == \
self.hass.states.get(switch.ENTITY_ID_ALL_SWITCHES).state
assert switch.is_on(self.hass, self.switch_1.entity_id)
assert not switch.is_on(self.hass, self.switch_2.entity_id)
assert not switch.is_on(self.hass, self.switch_3.entity_id)
common.turn_off(self.hass, self.switch_1.entity_id)
common.turn_on(self.hass, self.switch_2.entity_id)
self.hass.block_till_done()
self.assertTrue(switch.is_on(self.hass))
self.assertFalse(switch.is_on(self.hass, self.switch_1.entity_id))
self.assertTrue(switch.is_on(self.hass, self.switch_2.entity_id))
assert switch.is_on(self.hass)
assert not switch.is_on(self.hass, self.switch_1.entity_id)
assert switch.is_on(self.hass, self.switch_2.entity_id)
# Turn all off
common.turn_off(self.hass)
self.hass.block_till_done()
self.assertFalse(switch.is_on(self.hass))
self.assertEqual(
STATE_OFF,
self.hass.states.get(switch.ENTITY_ID_ALL_SWITCHES).state)
self.assertFalse(switch.is_on(self.hass, self.switch_1.entity_id))
self.assertFalse(switch.is_on(self.hass, self.switch_2.entity_id))
self.assertFalse(switch.is_on(self.hass, self.switch_3.entity_id))
assert not switch.is_on(self.hass)
assert STATE_OFF == \
self.hass.states.get(switch.ENTITY_ID_ALL_SWITCHES).state
assert not switch.is_on(self.hass, self.switch_1.entity_id)
assert not switch.is_on(self.hass, self.switch_2.entity_id)
assert not switch.is_on(self.hass, self.switch_3.entity_id)
# Turn all on
common.turn_on(self.hass)
self.hass.block_till_done()
self.assertTrue(switch.is_on(self.hass))
self.assertEqual(
STATE_ON,
self.hass.states.get(switch.ENTITY_ID_ALL_SWITCHES).state)
self.assertTrue(switch.is_on(self.hass, self.switch_1.entity_id))
self.assertTrue(switch.is_on(self.hass, self.switch_2.entity_id))
self.assertTrue(switch.is_on(self.hass, self.switch_3.entity_id))
assert switch.is_on(self.hass)
assert STATE_ON == \
self.hass.states.get(switch.ENTITY_ID_ALL_SWITCHES).state
assert switch.is_on(self.hass, self.switch_1.entity_id)
assert switch.is_on(self.hass, self.switch_2.entity_id)
assert switch.is_on(self.hass, self.switch_3.entity_id)
def test_setup_two_platforms(self):
"""Test with bad configuration."""
@ -86,12 +83,12 @@ class TestSwitch(unittest.TestCase):
loader.set_component(self.hass, 'switch.test2', test_platform)
test_platform.init(False)
self.assertTrue(setup_component(
assert setup_component(
self.hass, switch.DOMAIN, {
switch.DOMAIN: {CONF_PLATFORM: 'test'},
'{} 2'.format(switch.DOMAIN): {CONF_PLATFORM: 'test2'},
}
))
)
async def test_switch_context(hass):