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:
parent
4222f7562b
commit
08fe7c3ece
223 changed files with 6747 additions and 7237 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue