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:
1 parent
4222f7562b
commit
08fe7c3ece
223 files changed
+6747
-7237
No files matched your search
@@ -18,11 +18,11 @@ class TestLockDemo(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.assertTrue(setup_component(self.hass, lock.DOMAIN, {
|
||||
assert setup_component(self.hass, lock.DOMAIN, {
|
||||
'lock': {
|
||||
'platform': 'demo'
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
"""Stop everything that was started."""
|
||||
@@ -30,10 +30,10 @@ class TestLockDemo(unittest.TestCase):
|
||||
|
||||
def test_is_locked(self):
|
||||
"""Test if lock is locked."""
|
||||
self.assertTrue(lock.is_locked(self.hass, FRONT))
|
||||
assert lock.is_locked(self.hass, FRONT)
|
||||
self.hass.states.is_state(FRONT, 'locked')
|
||||
|
||||
self.assertFalse(lock.is_locked(self.hass, KITCHEN))
|
||||
assert not lock.is_locked(self.hass, KITCHEN)
|
||||
self.hass.states.is_state(KITCHEN, 'unlocked')
|
||||
|
||||
def test_locking(self):
|
||||
@@ -41,18 +41,18 @@ class TestLockDemo(unittest.TestCase):
|
||||
common.lock(self.hass, KITCHEN)
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertTrue(lock.is_locked(self.hass, KITCHEN))
|
||||
assert lock.is_locked(self.hass, KITCHEN)
|
||||
|
||||
def test_unlocking(self):
|
||||
"""Test the unlocking of a lock."""
|
||||
common.unlock(self.hass, FRONT)
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertFalse(lock.is_locked(self.hass, FRONT))
|
||||
assert not lock.is_locked(self.hass, FRONT)
|
||||
|
||||
def test_opening(self):
|
||||
"""Test the opening of a lock."""
|
||||
calls = mock_service(self.hass, lock.DOMAIN, lock.SERVICE_OPEN)
|
||||
common.open_lock(self.hass, OPENABLE_LOCK)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(calls))
|
||||
assert 1 == len(calls)
|
||||
@@ -39,20 +39,20 @@ class TestLockMQTT(unittest.TestCase):
|
||||
})
|
||||
|
||||
state = self.hass.states.get('lock.test')
|
||||
self.assertEqual(STATE_UNLOCKED, state.state)
|
||||
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))
|
||||
assert STATE_UNLOCKED == state.state
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
fire_mqtt_message(self.hass, 'state-topic', 'LOCK')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('lock.test')
|
||||
self.assertEqual(STATE_LOCKED, state.state)
|
||||
assert STATE_LOCKED == state.state
|
||||
|
||||
fire_mqtt_message(self.hass, 'state-topic', 'UNLOCK')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('lock.test')
|
||||
self.assertEqual(STATE_UNLOCKED, state.state)
|
||||
assert STATE_UNLOCKED == state.state
|
||||
|
||||
def test_sending_mqtt_commands_and_optimistic(self):
|
||||
"""Test the sending MQTT commands in optimistic mode."""
|
||||
@@ -68,8 +68,8 @@ class TestLockMQTT(unittest.TestCase):
|
||||
})
|
||||
|
||||
state = self.hass.states.get('lock.test')
|
||||
self.assertEqual(STATE_UNLOCKED, state.state)
|
||||
self.assertTrue(state.attributes.get(ATTR_ASSUMED_STATE))
|
||||
assert STATE_UNLOCKED == state.state
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
common.lock(self.hass, 'lock.test')
|
||||
self.hass.block_till_done()
|
||||
@@ -78,7 +78,7 @@ class TestLockMQTT(unittest.TestCase):
|
||||
'command-topic', 'LOCK', 2, False)
|
||||
self.mock_publish.async_publish.reset_mock()
|
||||
state = self.hass.states.get('lock.test')
|
||||
self.assertEqual(STATE_LOCKED, state.state)
|
||||
assert STATE_LOCKED == state.state
|
||||
|
||||
common.unlock(self.hass, 'lock.test')
|
||||
self.hass.block_till_done()
|
||||
@@ -86,7 +86,7 @@ class TestLockMQTT(unittest.TestCase):
|
||||
self.mock_publish.async_publish.assert_called_once_with(
|
||||
'command-topic', 'UNLOCK', 2, False)
|
||||
state = self.hass.states.get('lock.test')
|
||||
self.assertEqual(STATE_UNLOCKED, state.state)
|
||||
assert STATE_UNLOCKED == state.state
|
||||
|
||||
def test_controlling_state_via_topic_and_json_message(self):
|
||||
"""Test the controlling state via topic and JSON message."""
|
||||
@@ -103,23 +103,23 @@ class TestLockMQTT(unittest.TestCase):
|
||||
})
|
||||
|
||||
state = self.hass.states.get('lock.test')
|
||||
self.assertEqual(STATE_UNLOCKED, state.state)
|
||||
assert STATE_UNLOCKED == state.state
|
||||
|
||||
fire_mqtt_message(self.hass, 'state-topic', '{"val":"LOCK"}')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('lock.test')
|
||||
self.assertEqual(STATE_LOCKED, state.state)
|
||||
assert STATE_LOCKED == state.state
|
||||
|
||||
fire_mqtt_message(self.hass, 'state-topic', '{"val":"UNLOCK"}')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('lock.test')
|
||||
self.assertEqual(STATE_UNLOCKED, state.state)
|
||||
assert STATE_UNLOCKED == state.state
|
||||
|
||||
def test_default_availability_payload(self):
|
||||
"""Test availability by default payload with defined topic."""
|
||||
self.assertTrue(setup_component(self.hass, lock.DOMAIN, {
|
||||
assert setup_component(self.hass, lock.DOMAIN, {
|
||||
lock.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'name': 'test',
|
||||
@@ -129,26 +129,26 @@ class TestLockMQTT(unittest.TestCase):
|
||||
'payload_unlock': 'UNLOCK',
|
||||
'availability_topic': 'availability-topic'
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
state = self.hass.states.get('lock.test')
|
||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
|
||||
fire_mqtt_message(self.hass, 'availability-topic', 'online')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('lock.test')
|
||||
self.assertNotEqual(STATE_UNAVAILABLE, state.state)
|
||||
assert STATE_UNAVAILABLE != state.state
|
||||
|
||||
fire_mqtt_message(self.hass, 'availability-topic', 'offline')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('lock.test')
|
||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
|
||||
def test_custom_availability_payload(self):
|
||||
"""Test availability by custom payload with defined topic."""
|
||||
self.assertTrue(setup_component(self.hass, lock.DOMAIN, {
|
||||
assert setup_component(self.hass, lock.DOMAIN, {
|
||||
lock.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'name': 'test',
|
||||
@@ -160,22 +160,22 @@ class TestLockMQTT(unittest.TestCase):
|
||||
'payload_available': 'good',
|
||||
'payload_not_available': 'nogood'
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
state = self.hass.states.get('lock.test')
|
||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
|
||||
fire_mqtt_message(self.hass, 'availability-topic', 'good')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('lock.test')
|
||||
self.assertNotEqual(STATE_UNAVAILABLE, state.state)
|
||||
assert STATE_UNAVAILABLE != state.state
|
||||
|
||||
fire_mqtt_message(self.hass, 'availability-topic', 'nogood')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('lock.test')
|
||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
|
||||
|
||||
async def test_discovery_removal_lock(hass, mqtt_mock, caplog):
|
||||
|
||||
Reference in new issue
Block a user