Collection of random (mainly) test improvements (#33733)

This commit is contained in:
Franck Nijhof 2020-04-06 12:51:48 +02:00 committed by GitHub
parent b31284b855
commit 98a2efcbab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
33 changed files with 337 additions and 344 deletions

View File

@ -842,11 +842,7 @@ def async_notify_setup_error(
message = "The following integrations and platforms could not be set up:\n\n"
for name, link in errors.items():
if link:
part = f"[{name}]({link})"
else:
part = name
part = f"[{name}]({link})" if link else name
message += f" - {part}\n"
message += "\nPlease check your config."

View File

@ -917,8 +917,7 @@ class OptionsFlowManager(data_entry_flow.FlowManager):
if entry.domain not in HANDLERS:
raise data_entry_flow.UnknownHandler
flow = cast(OptionsFlow, HANDLERS[entry.domain].async_get_options_flow(entry))
return flow
return cast(OptionsFlow, HANDLERS[entry.domain].async_get_options_flow(entry))
async def async_finish_flow(
self, flow: data_entry_flow.FlowHandler, result: Dict[str, Any]

View File

@ -91,4 +91,4 @@ class TestCommandLine(unittest.TestCase):
assert self.hass.services.call(
"notify", "test", {"message": "error"}, blocking=True
)
assert 1 == mock_error.call_count
assert mock_error.call_count == 1

View File

@ -40,12 +40,12 @@ class TestCommandSensorSensor(unittest.TestCase):
command_line.setup_platform(self.hass, config, add_dev_callback)
assert 1 == len(devices)
assert len(devices) == 1
entity = devices[0]
entity.update()
assert "Test" == entity.name
assert "in" == entity.unit_of_measurement
assert "5" == entity.state
assert entity.name == "Test"
assert entity.unit_of_measurement == "in"
assert entity.state == "5"
def test_template(self):
"""Test command sensor with template."""
@ -61,7 +61,7 @@ class TestCommandSensorSensor(unittest.TestCase):
)
entity.update()
assert 5 == float(entity.state)
assert float(entity.state) == 5
def test_template_render(self):
"""Ensure command with templates get rendered properly."""
@ -71,7 +71,7 @@ class TestCommandSensorSensor(unittest.TestCase):
)
data.update()
assert "Works" == data.value
assert data.value == "Works"
def test_bad_command(self):
"""Test bad command."""
@ -95,11 +95,11 @@ class TestCommandSensorSensor(unittest.TestCase):
self.hass, data, "test", None, None, ["key", "another_key", "key_three"]
)
self.sensor.update()
assert "some_json_value" == self.sensor.device_state_attributes["key"]
assert self.sensor.device_state_attributes["key"] == "some_json_value"
assert (
"another_json_value" == self.sensor.device_state_attributes["another_key"]
self.sensor.device_state_attributes["another_key"] == "another_json_value"
)
assert "value_three" == self.sensor.device_state_attributes["key_three"]
assert self.sensor.device_state_attributes["key_three"] == "value_three"
@patch("homeassistant.components.command_line.sensor._LOGGER")
def test_update_with_json_attrs_no_data(self, mock_logger):
@ -156,12 +156,12 @@ class TestCommandSensorSensor(unittest.TestCase):
["key", "another_key", "key_three", "special_key"],
)
self.sensor.update()
assert "some_json_value" == self.sensor.device_state_attributes["key"]
assert self.sensor.device_state_attributes["key"] == "some_json_value"
assert (
"another_json_value" == self.sensor.device_state_attributes["another_key"]
self.sensor.device_state_attributes["another_key"] == "another_json_value"
)
assert "value_three" == self.sensor.device_state_attributes["key_three"]
assert not ("special_key" in self.sensor.device_state_attributes)
assert self.sensor.device_state_attributes["key_three"] == "value_three"
assert "special_key" not in self.sensor.device_state_attributes
def test_update_with_unnecessary_json_attrs(self):
"""Test attributes get extracted from a JSON result."""
@ -178,8 +178,8 @@ class TestCommandSensorSensor(unittest.TestCase):
self.hass, data, "test", None, None, ["key", "another_key"]
)
self.sensor.update()
assert "some_json_value" == self.sensor.device_state_attributes["key"]
assert self.sensor.device_state_attributes["key"] == "some_json_value"
assert (
"another_json_value" == self.sensor.device_state_attributes["another_key"]
self.sensor.device_state_attributes["another_key"] == "another_json_value"
)
assert not ("key_three" in self.sensor.device_state_attributes)
assert "key_three" not in self.sensor.device_state_attributes

View File

@ -129,7 +129,7 @@ async def test_cover(hass):
await hass.async_block_till_done()
set_callback.assert_called_with("put", "/lights/1/state", json={"bri_inc": 0})
"""Test that a reported cover position of 255 (deconz-rest-api < 2.05.73) is interpreted correctly."""
# Test that a reported cover position of 255 (deconz-rest-api < 2.05.73) is interpreted correctly.
deconz_old_brightness_cover = hass.states.get("cover.deconz_old_brightness_cover")
assert deconz_old_brightness_cover.state == "open"

View File

@ -23,26 +23,26 @@ async def test_state_attributes(hass):
state = hass.states.get(ENTITY_LIGHT)
assert light.is_on(hass, ENTITY_LIGHT)
assert (0.4, 0.4) == state.attributes.get(light.ATTR_XY_COLOR)
assert 25 == state.attributes.get(light.ATTR_BRIGHTNESS)
assert state.attributes.get(light.ATTR_BRIGHTNESS) == 25
assert (255, 234, 164) == state.attributes.get(light.ATTR_RGB_COLOR)
assert "rainbow" == state.attributes.get(light.ATTR_EFFECT)
assert state.attributes.get(light.ATTR_EFFECT) == "rainbow"
await common.async_turn_on(
hass, ENTITY_LIGHT, rgb_color=(251, 253, 255), white_value=254
)
state = hass.states.get(ENTITY_LIGHT)
assert 254 == state.attributes.get(light.ATTR_WHITE_VALUE)
assert state.attributes.get(light.ATTR_WHITE_VALUE) == 254
assert (250, 252, 255) == state.attributes.get(light.ATTR_RGB_COLOR)
assert (0.319, 0.326) == state.attributes.get(light.ATTR_XY_COLOR)
await common.async_turn_on(hass, ENTITY_LIGHT, color_temp=400, effect="none")
state = hass.states.get(ENTITY_LIGHT)
assert 400 == state.attributes.get(light.ATTR_COLOR_TEMP)
assert 153 == state.attributes.get(light.ATTR_MIN_MIREDS)
assert 500 == state.attributes.get(light.ATTR_MAX_MIREDS)
assert "none" == state.attributes.get(light.ATTR_EFFECT)
assert state.attributes.get(light.ATTR_COLOR_TEMP) == 400
assert state.attributes.get(light.ATTR_MIN_MIREDS) == 153
assert state.attributes.get(light.ATTR_MAX_MIREDS) == 500
assert state.attributes.get(light.ATTR_EFFECT) == "none"
await common.async_turn_on(hass, ENTITY_LIGHT, kelvin=3000, brightness_pct=50)
state = hass.states.get(ENTITY_LIGHT)
assert 333 == state.attributes.get(light.ATTR_COLOR_TEMP)
assert 127 == state.attributes.get(light.ATTR_BRIGHTNESS)
assert state.attributes.get(light.ATTR_COLOR_TEMP) == 333
assert state.attributes.get(light.ATTR_BRIGHTNESS) == 127
async def test_turn_off(hass):

View File

@ -167,8 +167,8 @@ async def test_intent_action_incomplete_v1(fixture):
response = await mock_client.post(
f"/api/webhook/{webhook_id}", data=json.dumps(data)
)
assert 200 == response.status
assert "" == await response.text()
assert response.status == 200
assert await response.text() == ""
async def test_intent_action_incomplete_v2(fixture):
@ -180,8 +180,8 @@ async def test_intent_action_incomplete_v2(fixture):
response = await mock_client.post(
f"/api/webhook/{webhook_id}", data=json.dumps(data)
)
assert 200 == response.status
assert "" == await response.text()
assert response.status == 200
assert await response.text() == ""
async def test_intent_slot_filling_v1(fixture):
@ -222,8 +222,8 @@ async def test_intent_slot_filling_v1(fixture):
response = await mock_client.post(
f"/api/webhook/{webhook_id}", data=json.dumps(data)
)
assert 200 == response.status
assert "" == await response.text()
assert response.status == 200
assert await response.text() == ""
async def test_intent_request_with_parameters_v1(fixture):
@ -233,9 +233,9 @@ async def test_intent_request_with_parameters_v1(fixture):
response = await mock_client.post(
f"/api/webhook/{webhook_id}", data=json.dumps(data)
)
assert 200 == response.status
assert response.status == 200
text = (await response.json()).get("speech")
assert "You told us your sign is virgo." == text
assert text == "You told us your sign is virgo."
async def test_intent_request_with_parameters_v2(fixture):
@ -245,9 +245,9 @@ async def test_intent_request_with_parameters_v2(fixture):
response = await mock_client.post(
f"/api/webhook/{webhook_id}", data=json.dumps(data)
)
assert 200 == response.status
assert response.status == 200
text = (await response.json()).get("fulfillmentText")
assert "You told us your sign is virgo." == text
assert text == "You told us your sign is virgo."
async def test_intent_request_with_parameters_but_empty_v1(fixture):
@ -258,9 +258,9 @@ async def test_intent_request_with_parameters_but_empty_v1(fixture):
response = await mock_client.post(
f"/api/webhook/{webhook_id}", data=json.dumps(data)
)
assert 200 == response.status
assert response.status == 200
text = (await response.json()).get("speech")
assert "You told us your sign is ." == text
assert text == "You told us your sign is ."
async def test_intent_request_with_parameters_but_empty_v2(fixture):
@ -271,9 +271,9 @@ async def test_intent_request_with_parameters_but_empty_v2(fixture):
response = await mock_client.post(
f"/api/webhook/{webhook_id}", data=json.dumps(data)
)
assert 200 == response.status
assert response.status == 200
text = (await response.json()).get("fulfillmentText")
assert "You told us your sign is ." == text
assert text == "You told us your sign is ."
async def test_intent_request_without_slots_v1(hass, fixture):
@ -290,10 +290,10 @@ async def test_intent_request_without_slots_v1(hass, fixture):
response = await mock_client.post(
f"/api/webhook/{webhook_id}", data=json.dumps(data)
)
assert 200 == response.status
assert response.status == 200
text = (await response.json()).get("speech")
assert "Anne Therese is at unknown and Paulus is at unknown" == text
assert text == "Anne Therese is at unknown and Paulus is at unknown"
hass.states.async_set("device_tracker.paulus", "home")
hass.states.async_set("device_tracker.anne_therese", "home")
@ -301,9 +301,9 @@ async def test_intent_request_without_slots_v1(hass, fixture):
response = await mock_client.post(
f"/api/webhook/{webhook_id}", data=json.dumps(data)
)
assert 200 == response.status
assert response.status == 200
text = (await response.json()).get("speech")
assert "You are both home, you silly" == text
assert text == "You are both home, you silly"
async def test_intent_request_without_slots_v2(hass, fixture):
@ -320,10 +320,10 @@ async def test_intent_request_without_slots_v2(hass, fixture):
response = await mock_client.post(
f"/api/webhook/{webhook_id}", data=json.dumps(data)
)
assert 200 == response.status
assert response.status == 200
text = (await response.json()).get("fulfillmentText")
assert "Anne Therese is at unknown and Paulus is at unknown" == text
assert text == "Anne Therese is at unknown and Paulus is at unknown"
hass.states.async_set("device_tracker.paulus", "home")
hass.states.async_set("device_tracker.anne_therese", "home")
@ -331,9 +331,9 @@ async def test_intent_request_without_slots_v2(hass, fixture):
response = await mock_client.post(
f"/api/webhook/{webhook_id}", data=json.dumps(data)
)
assert 200 == response.status
assert response.status == 200
text = (await response.json()).get("fulfillmentText")
assert "You are both home, you silly" == text
assert text == "You are both home, you silly"
async def test_intent_request_calling_service_v1(fixture, calls):
@ -349,13 +349,13 @@ async def test_intent_request_calling_service_v1(fixture, calls):
response = await mock_client.post(
f"/api/webhook/{webhook_id}", data=json.dumps(data)
)
assert 200 == response.status
assert call_count + 1 == len(calls)
assert response.status == 200
assert len(calls) == call_count + 1
call = calls[-1]
assert "test" == call.domain
assert "dialogflow" == call.service
assert ["switch.test"] == call.data.get("entity_id")
assert "virgo" == call.data.get("hello")
assert call.domain == "test"
assert call.service == "dialogflow"
assert call.data.get("entity_id") == ["switch.test"]
assert call.data.get("hello") == "virgo"
async def test_intent_request_calling_service_v2(fixture, calls):
@ -371,13 +371,13 @@ async def test_intent_request_calling_service_v2(fixture, calls):
response = await mock_client.post(
f"/api/webhook/{webhook_id}", data=json.dumps(data)
)
assert 200 == response.status
assert call_count + 1 == len(calls)
assert response.status == 200
assert len(calls) == call_count + 1
call = calls[-1]
assert "test" == call.domain
assert "dialogflow" == call.service
assert ["switch.test"] == call.data.get("entity_id")
assert "virgo" == call.data.get("hello")
assert call.domain == "test"
assert call.service == "dialogflow"
assert call.data.get("entity_id") == ["switch.test"]
assert call.data.get("hello") == "virgo"
async def test_intent_with_no_action_v1(fixture):
@ -389,9 +389,9 @@ async def test_intent_with_no_action_v1(fixture):
response = await mock_client.post(
f"/api/webhook/{webhook_id}", data=json.dumps(data)
)
assert 200 == response.status
assert response.status == 200
text = (await response.json()).get("speech")
assert "You have not defined an action in your Dialogflow intent." == text
assert text == "You have not defined an action in your Dialogflow intent."
async def test_intent_with_no_action_v2(fixture):
@ -403,9 +403,9 @@ async def test_intent_with_no_action_v2(fixture):
response = await mock_client.post(
f"/api/webhook/{webhook_id}", data=json.dumps(data)
)
assert 200 == response.status
assert response.status == 200
text = (await response.json()).get("fulfillmentText")
assert "You have not defined an action in your Dialogflow intent." == text
assert text == "You have not defined an action in your Dialogflow intent."
async def test_intent_with_unknown_action_v1(fixture):
@ -416,9 +416,9 @@ async def test_intent_with_unknown_action_v1(fixture):
response = await mock_client.post(
f"/api/webhook/{webhook_id}", data=json.dumps(data)
)
assert 200 == response.status
assert response.status == 200
text = (await response.json()).get("speech")
assert "This intent is not yet configured within Home Assistant." == text
assert text == "This intent is not yet configured within Home Assistant."
async def test_intent_with_unknown_action_v2(fixture):
@ -429,6 +429,6 @@ async def test_intent_with_unknown_action_v2(fixture):
response = await mock_client.post(
f"/api/webhook/{webhook_id}", data=json.dumps(data)
)
assert 200 == response.status
assert response.status == 200
text = (await response.json()).get("fulfillmentText")
assert "This intent is not yet configured within Home Assistant." == text
assert text == "This intent is not yet configured within Home Assistant."

View File

@ -228,7 +228,7 @@ async def test_light_without_brightness_can_be_turned_off(hass_hue, hue_client):
# Verify that SERVICE_TURN_OFF has been called
await hass_hue.async_block_till_done()
assert 1 == len(turn_off_calls)
assert len(turn_off_calls) == 1
call = turn_off_calls[-1]
assert light.DOMAIN == call.domain
@ -536,16 +536,16 @@ async def test_put_light_state_media_player(hass_hue, hue_client):
async def test_close_cover(hass_hue, hue_client):
"""Test opening cover ."""
COVER_ID = "cover.living_room_window"
cover_id = "cover.living_room_window"
# Turn the office light off first
await hass_hue.services.async_call(
cover.DOMAIN,
const.SERVICE_CLOSE_COVER,
{const.ATTR_ENTITY_ID: COVER_ID},
{const.ATTR_ENTITY_ID: cover_id},
blocking=True,
)
cover_test = hass_hue.states.get(COVER_ID)
cover_test = hass_hue.states.get(cover_id)
assert cover_test.state == "closing"
for _ in range(7):
@ -553,12 +553,12 @@ async def test_close_cover(hass_hue, hue_client):
async_fire_time_changed(hass_hue, future)
await hass_hue.async_block_till_done()
cover_test = hass_hue.states.get(COVER_ID)
cover_test = hass_hue.states.get(cover_id)
assert cover_test.state == "closed"
# Go through the API to turn it on
cover_result = await perform_put_light_state(
hass_hue, hue_client, COVER_ID, True, 100
hass_hue, hue_client, cover_id, True, 100
)
assert cover_result.status == 200
@ -574,22 +574,22 @@ async def test_close_cover(hass_hue, hue_client):
assert len(cover_result_json) == 2
# Check to make sure the state changed
cover_test_2 = hass_hue.states.get(COVER_ID)
cover_test_2 = hass_hue.states.get(cover_id)
assert cover_test_2.state == "open"
async def test_set_position_cover(hass_hue, hue_client):
"""Test setting position cover ."""
COVER_ID = "cover.living_room_window"
cover_id = "cover.living_room_window"
# Turn the office light off first
await hass_hue.services.async_call(
cover.DOMAIN,
const.SERVICE_CLOSE_COVER,
{const.ATTR_ENTITY_ID: COVER_ID},
{const.ATTR_ENTITY_ID: cover_id},
blocking=True,
)
cover_test = hass_hue.states.get(COVER_ID)
cover_test = hass_hue.states.get(cover_id)
assert cover_test.state == "closing"
for _ in range(7):
@ -597,7 +597,7 @@ async def test_set_position_cover(hass_hue, hue_client):
async_fire_time_changed(hass_hue, future)
await hass_hue.async_block_till_done()
cover_test = hass_hue.states.get(COVER_ID)
cover_test = hass_hue.states.get(cover_id)
assert cover_test.state == "closed"
level = 20
@ -605,7 +605,7 @@ async def test_set_position_cover(hass_hue, hue_client):
# Go through the API to open
cover_result = await perform_put_light_state(
hass_hue, hue_client, COVER_ID, False, brightness
hass_hue, hue_client, cover_id, False, brightness
)
assert cover_result.status == 200
@ -628,7 +628,7 @@ async def test_set_position_cover(hass_hue, hue_client):
await hass_hue.async_block_till_done()
# Check to make sure the state changed
cover_test_2 = hass_hue.states.get(COVER_ID)
cover_test_2 = hass_hue.states.get(cover_id)
assert cover_test_2.state == "open"
assert cover_test_2.attributes.get("current_position") == level

View File

@ -28,9 +28,9 @@ class TestFanEntity(unittest.TestCase):
def test_fanentity(self):
"""Test fan entity methods."""
assert "off" == self.fan.state
assert 0 == len(self.fan.speed_list)
assert 0 == self.fan.supported_features
assert self.fan.state == "off"
assert len(self.fan.speed_list) == 0
assert self.fan.supported_features == 0
assert {"speed_list": []} == self.fan.capability_attributes
# Test set_speed not required
self.fan.oscillate(True)

View File

@ -189,7 +189,7 @@ class TestTTSGooglePlatform:
self.url_param["total"] = 9
self.url_param["q"] = "I%20person%20is%20on%20front%20of%20your%20door"
self.url_param["textlen"] = 33
for idx in range(0, 9):
for idx in range(9):
self.url_param["idx"] = idx
aioclient_mock.get(
self.url, params=self.url_param, status=200, content=b"test"

View File

@ -212,6 +212,6 @@ class TestGraphite(unittest.TestCase):
mock_queue.get.side_effect = fake_get
self.gf.run()
# Twice for two events, once for the stop
assert 3 == mock_queue.task_done.call_count
assert mock_queue.task_done.call_count == 3
assert mock_r.call_count == 1
assert mock_r.call_args == mock.call("entity", event.data["new_state"])

View File

@ -48,11 +48,9 @@ class TelnetMock:
"""Return sample values."""
if self.host == "alice.local":
raise ConnectionRefusedError
elif self.host == "bob.local":
if self.host == "bob.local":
raise socket.gaierror
else:
return self.sample_data
return None
return self.sample_data
class TestHDDTempSensor(unittest.TestCase):

View File

@ -103,19 +103,19 @@ async def test_set_value(hass):
entity_id = "input_text.test_1"
state = hass.states.get(entity_id)
assert "test" == str(state.state)
assert str(state.state) == "test"
set_value(hass, entity_id, "testing")
await hass.async_block_till_done()
state = hass.states.get(entity_id)
assert "testing" == str(state.state)
assert str(state.state) == "testing"
set_value(hass, entity_id, "testing too long")
await hass.async_block_till_done()
state = hass.states.get(entity_id)
assert "testing" == str(state.state)
assert str(state.state) == "testing"
async def test_mode(hass):
@ -144,15 +144,15 @@ async def test_mode(hass):
state = hass.states.get("input_text.test_default_text")
assert state
assert "text" == state.attributes["mode"]
assert state.attributes["mode"] == "text"
state = hass.states.get("input_text.test_explicit_text")
assert state
assert "text" == state.attributes["mode"]
assert state.attributes["mode"] == "text"
state = hass.states.get("input_text.test_explicit_password")
assert state
assert "password" == state.attributes["mode"]
assert state.attributes["mode"] == "password"
async def test_restore_state(hass):
@ -273,8 +273,8 @@ async def test_reload(hass, hass_admin_user, hass_read_only_user):
assert state_1 is not None
assert state_2 is not None
assert state_3 is None
assert "test 1" == state_1.state
assert "test 2" == state_2.state
assert state_1.state == "test 1"
assert state_2.state == "test 2"
assert state_1.attributes[ATTR_MIN] == 0
assert state_2.attributes[ATTR_MAX] == 100

View File

@ -94,13 +94,13 @@ class TestComponentLogbook(unittest.TestCase):
)
assert len(events) == 1
assert 1 == len(calls)
assert len(calls) == 1
last_call = calls[-1]
assert "Alarm" == last_call.data.get(logbook.ATTR_NAME)
assert "is triggered" == last_call.data.get(logbook.ATTR_MESSAGE)
assert "switch" == last_call.data.get(logbook.ATTR_DOMAIN)
assert "switch.test_switch" == last_call.data.get(logbook.ATTR_ENTITY_ID)
assert last_call.data.get(logbook.ATTR_NAME) == "Alarm"
assert last_call.data.get(logbook.ATTR_MESSAGE) == "is triggered"
assert last_call.data.get(logbook.ATTR_DOMAIN) == "switch"
assert last_call.data.get(logbook.ATTR_ENTITY_ID) == "switch.test_switch"
def test_service_call_create_log_book_entry_no_message(self):
"""Test if service call create log book entry without message."""
@ -121,7 +121,7 @@ class TestComponentLogbook(unittest.TestCase):
# scheduled. This means that they may not have been processed yet.
self.hass.block_till_done()
assert 0 == len(calls)
assert len(calls) == 0
def test_humanify_filter_sensor(self):
"""Test humanify filter too frequent sensor values."""
@ -137,7 +137,7 @@ class TestComponentLogbook(unittest.TestCase):
entries = list(logbook.humanify(self.hass, (eventA, eventB, eventC)))
assert 2 == len(entries)
assert len(entries) == 2
self.assert_entry(
entries[0], pointB, "bla", domain="sensor", entity_id=entity_id
)
@ -155,7 +155,7 @@ class TestComponentLogbook(unittest.TestCase):
entries = list(logbook.humanify(self.hass, (eventA,)))
assert 0 == len(entries)
assert len(entries) == 0
def test_exclude_new_entities(self):
"""Test if events are excluded on first update."""
@ -176,7 +176,7 @@ class TestComponentLogbook(unittest.TestCase):
]
entries = list(logbook.humanify(self.hass, events))
assert 2 == len(entries)
assert len(entries) == 2
self.assert_entry(
entries[0], name="Home Assistant", message="stopped", domain=ha.DOMAIN
)
@ -203,7 +203,7 @@ class TestComponentLogbook(unittest.TestCase):
]
entries = list(logbook.humanify(self.hass, events))
assert 2 == len(entries)
assert len(entries) == 2
self.assert_entry(
entries[0], name="Home Assistant", message="stopped", domain=ha.DOMAIN
)
@ -231,7 +231,7 @@ class TestComponentLogbook(unittest.TestCase):
]
entries = list(logbook.humanify(self.hass, events))
assert 2 == len(entries)
assert len(entries) == 2
self.assert_entry(
entries[0], name="Home Assistant", message="stopped", domain=ha.DOMAIN
)
@ -265,7 +265,7 @@ class TestComponentLogbook(unittest.TestCase):
]
entries = list(logbook.humanify(self.hass, events))
assert 2 == len(entries)
assert len(entries) == 2
self.assert_entry(
entries[0], name="Home Assistant", message="stopped", domain=ha.DOMAIN
)
@ -307,7 +307,7 @@ class TestComponentLogbook(unittest.TestCase):
]
entries = list(logbook.humanify(self.hass, events))
assert 2 == len(entries)
assert len(entries) == 2
self.assert_entry(
entries[0], name="Home Assistant", message="started", domain=ha.DOMAIN
)
@ -348,7 +348,7 @@ class TestComponentLogbook(unittest.TestCase):
]
entries = list(logbook.humanify(self.hass, events))
assert 2 == len(entries)
assert len(entries) == 2
self.assert_entry(
entries[0], name="Home Assistant", message="stopped", domain=ha.DOMAIN
)
@ -387,7 +387,7 @@ class TestComponentLogbook(unittest.TestCase):
]
entries = list(logbook.humanify(self.hass, events))
assert 2 == len(entries)
assert len(entries) == 2
self.assert_entry(
entries[0], name="Home Assistant", message="stopped", domain=ha.DOMAIN
)
@ -419,7 +419,7 @@ class TestComponentLogbook(unittest.TestCase):
]
entries = list(logbook.humanify(self.hass, events))
assert 2 == len(entries)
assert len(entries) == 2
self.assert_entry(
entries[0], name="Home Assistant", message="stopped", domain=ha.DOMAIN
)
@ -475,7 +475,7 @@ class TestComponentLogbook(unittest.TestCase):
]
entries = list(logbook.humanify(self.hass, events))
assert 4 == len(entries)
assert len(entries) == 4
self.assert_entry(
entries[0], name="Home Assistant", message="started", domain=ha.DOMAIN
)
@ -529,7 +529,7 @@ class TestComponentLogbook(unittest.TestCase):
]
entries = list(logbook.humanify(self.hass, events))
assert 5 == len(entries)
assert len(entries) == 5
self.assert_entry(
entries[0], name="Home Assistant", message="started", domain=ha.DOMAIN
)
@ -563,7 +563,7 @@ class TestComponentLogbook(unittest.TestCase):
]
entries = list(logbook.humanify(self.hass, events))
assert 1 == len(entries)
assert len(entries) == 1
self.assert_entry(
entries[0], pointA, "bla", domain="switch", entity_id=entity_id
)
@ -609,7 +609,7 @@ class TestComponentLogbook(unittest.TestCase):
]
entries = list(logbook.humanify(self.hass, events))
assert 1 == len(entries)
assert len(entries) == 1
self.assert_entry(
entries[0], pointB, "kitchen", domain="light", entity_id="light.kitchen"
)
@ -629,7 +629,7 @@ class TestComponentLogbook(unittest.TestCase):
)
)
assert 1 == len(entries)
assert len(entries) == 1
self.assert_entry(
entries[0], name="Home Assistant", message="restarted", domain=ha.DOMAIN
)
@ -649,7 +649,7 @@ class TestComponentLogbook(unittest.TestCase):
)
)
assert 2 == len(entries)
assert len(entries) == 2
self.assert_entry(
entries[0], name="Home Assistant", message="started", domain=ha.DOMAIN
)
@ -668,19 +668,19 @@ class TestComponentLogbook(unittest.TestCase):
eventA = self.create_state_changed_event(pointA, "switch.bla", 10)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "changed to 10" == message
assert message == "changed to 10"
# message for a switch turned on
eventA = self.create_state_changed_event(pointA, "switch.bla", STATE_ON)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "turned on" == message
assert message == "turned on"
# message for a switch turned off
eventA = self.create_state_changed_event(pointA, "switch.bla", STATE_OFF)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "turned off" == message
assert message == "turned off"
def test_entry_message_from_state_device_tracker(self):
"""Test if logbook message is correctly created for device tracker."""
@ -692,13 +692,13 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is away" == message
assert message == "is away"
# message for a device tracker "home" state
eventA = self.create_state_changed_event(pointA, "device_tracker.john", "work")
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is at work" == message
assert message == "is at work"
def test_entry_message_from_state_person(self):
"""Test if logbook message is correctly created for a person."""
@ -708,13 +708,13 @@ class TestComponentLogbook(unittest.TestCase):
eventA = self.create_state_changed_event(pointA, "person.john", STATE_NOT_HOME)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is away" == message
assert message == "is away"
# message for a device tracker "home" state
eventA = self.create_state_changed_event(pointA, "person.john", "work")
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is at work" == message
assert message == "is at work"
def test_entry_message_from_state_sun(self):
"""Test if logbook message is correctly created for sun."""
@ -726,7 +726,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "has risen" == message
assert message == "has risen"
# message for a sun set
eventA = self.create_state_changed_event(
@ -734,7 +734,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "has set" == message
assert message == "has set"
def test_entry_message_from_state_binary_sensor_battery(self):
"""Test if logbook message is correctly created for a binary_sensor."""
@ -747,7 +747,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is low" == message
assert message == "is low"
# message for a binary_sensor battery "normal" state
eventA = self.create_state_changed_event(
@ -755,7 +755,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is normal" == message
assert message == "is normal"
def test_entry_message_from_state_binary_sensor_connectivity(self):
"""Test if logbook message is correctly created for a binary_sensor."""
@ -768,7 +768,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is connected" == message
assert message == "is connected"
# message for a binary_sensor connectivity "disconnected" state
eventA = self.create_state_changed_event(
@ -776,7 +776,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is disconnected" == message
assert message == "is disconnected"
def test_entry_message_from_state_binary_sensor_door(self):
"""Test if logbook message is correctly created for a binary_sensor."""
@ -789,7 +789,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is opened" == message
assert message == "is opened"
# message for a binary_sensor door "closed" state
eventA = self.create_state_changed_event(
@ -797,7 +797,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is closed" == message
assert message == "is closed"
def test_entry_message_from_state_binary_sensor_garage_door(self):
"""Test if logbook message is correctly created for a binary_sensor."""
@ -810,7 +810,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is opened" == message
assert message == "is opened"
# message for a binary_sensor garage_door "closed" state
eventA = self.create_state_changed_event(
@ -818,7 +818,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is closed" == message
assert message == "is closed"
def test_entry_message_from_state_binary_sensor_opening(self):
"""Test if logbook message is correctly created for a binary_sensor."""
@ -831,7 +831,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is opened" == message
assert message == "is opened"
# message for a binary_sensor opening "closed" state
eventA = self.create_state_changed_event(
@ -839,7 +839,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is closed" == message
assert message == "is closed"
def test_entry_message_from_state_binary_sensor_window(self):
"""Test if logbook message is correctly created for a binary_sensor."""
@ -852,7 +852,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is opened" == message
assert message == "is opened"
# message for a binary_sensor window "closed" state
eventA = self.create_state_changed_event(
@ -860,7 +860,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is closed" == message
assert message == "is closed"
def test_entry_message_from_state_binary_sensor_lock(self):
"""Test if logbook message is correctly created for a binary_sensor."""
@ -873,7 +873,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is unlocked" == message
assert message == "is unlocked"
# message for a binary_sensor lock "locked" state
eventA = self.create_state_changed_event(
@ -881,7 +881,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is locked" == message
assert message == "is locked"
def test_entry_message_from_state_binary_sensor_plug(self):
"""Test if logbook message is correctly created for a binary_sensor."""
@ -894,7 +894,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is plugged in" == message
assert message == "is plugged in"
# message for a binary_sensor plug "pluged" state
eventA = self.create_state_changed_event(
@ -902,7 +902,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is unplugged" == message
assert message == "is unplugged"
def test_entry_message_from_state_binary_sensor_presence(self):
"""Test if logbook message is correctly created for a binary_sensor."""
@ -915,7 +915,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is at home" == message
assert message == "is at home"
# message for a binary_sensor presence "away" state
eventA = self.create_state_changed_event(
@ -923,7 +923,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is away" == message
assert message == "is away"
def test_entry_message_from_state_binary_sensor_safety(self):
"""Test if logbook message is correctly created for a binary_sensor."""
@ -936,7 +936,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is unsafe" == message
assert message == "is unsafe"
# message for a binary_sensor safety "safe" state
eventA = self.create_state_changed_event(
@ -944,7 +944,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "is safe" == message
assert message == "is safe"
def test_entry_message_from_state_binary_sensor_cold(self):
"""Test if logbook message is correctly created for a binary_sensor."""
@ -957,7 +957,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "detected cold" == message
assert message == "detected cold"
# message for a binary_sensori cold "cleared" state
eventA = self.create_state_changed_event(
@ -965,7 +965,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "cleared (no cold detected)" == message
assert message == "cleared (no cold detected)"
def test_entry_message_from_state_binary_sensor_gas(self):
"""Test if logbook message is correctly created for a binary_sensor."""
@ -978,7 +978,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "detected gas" == message
assert message == "detected gas"
# message for a binary_sensori gas "cleared" state
eventA = self.create_state_changed_event(
@ -986,7 +986,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "cleared (no gas detected)" == message
assert message == "cleared (no gas detected)"
def test_entry_message_from_state_binary_sensor_heat(self):
"""Test if logbook message is correctly created for a binary_sensor."""
@ -999,7 +999,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "detected heat" == message
assert message == "detected heat"
# message for a binary_sensori heat "cleared" state
eventA = self.create_state_changed_event(
@ -1007,7 +1007,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "cleared (no heat detected)" == message
assert message == "cleared (no heat detected)"
def test_entry_message_from_state_binary_sensor_light(self):
"""Test if logbook message is correctly created for a binary_sensor."""
@ -1020,7 +1020,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "detected light" == message
assert message == "detected light"
# message for a binary_sensori light "cleared" state
eventA = self.create_state_changed_event(
@ -1028,7 +1028,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "cleared (no light detected)" == message
assert message == "cleared (no light detected)"
def test_entry_message_from_state_binary_sensor_moisture(self):
"""Test if logbook message is correctly created for a binary_sensor."""
@ -1041,7 +1041,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "detected moisture" == message
assert message == "detected moisture"
# message for a binary_sensori moisture "cleared" state
eventA = self.create_state_changed_event(
@ -1049,7 +1049,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "cleared (no moisture detected)" == message
assert message == "cleared (no moisture detected)"
def test_entry_message_from_state_binary_sensor_motion(self):
"""Test if logbook message is correctly created for a binary_sensor."""
@ -1062,7 +1062,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "detected motion" == message
assert message == "detected motion"
# message for a binary_sensori motion "cleared" state
eventA = self.create_state_changed_event(
@ -1070,7 +1070,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "cleared (no motion detected)" == message
assert message == "cleared (no motion detected)"
def test_entry_message_from_state_binary_sensor_occupancy(self):
"""Test if logbook message is correctly created for a binary_sensor."""
@ -1083,7 +1083,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "detected occupancy" == message
assert message == "detected occupancy"
# message for a binary_sensori occupancy "cleared" state
eventA = self.create_state_changed_event(
@ -1091,7 +1091,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "cleared (no occupancy detected)" == message
assert message == "cleared (no occupancy detected)"
def test_entry_message_from_state_binary_sensor_power(self):
"""Test if logbook message is correctly created for a binary_sensor."""
@ -1104,7 +1104,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "detected power" == message
assert message == "detected power"
# message for a binary_sensori power "cleared" state
eventA = self.create_state_changed_event(
@ -1112,7 +1112,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "cleared (no power detected)" == message
assert message == "cleared (no power detected)"
def test_entry_message_from_state_binary_sensor_problem(self):
"""Test if logbook message is correctly created for a binary_sensor."""
@ -1125,7 +1125,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "detected problem" == message
assert message == "detected problem"
# message for a binary_sensori problem "cleared" state
eventA = self.create_state_changed_event(
@ -1133,7 +1133,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "cleared (no problem detected)" == message
assert message == "cleared (no problem detected)"
def test_entry_message_from_state_binary_sensor_smoke(self):
"""Test if logbook message is correctly created for a binary_sensor."""
@ -1146,7 +1146,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "detected smoke" == message
assert message == "detected smoke"
# message for a binary_sensori smoke "cleared" state
eventA = self.create_state_changed_event(
@ -1154,7 +1154,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "cleared (no smoke detected)" == message
assert message == "cleared (no smoke detected)"
def test_entry_message_from_state_binary_sensor_sound(self):
"""Test if logbook message is correctly created for a binary_sensor."""
@ -1167,7 +1167,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "detected sound" == message
assert message == "detected sound"
# message for a binary_sensori sound "cleared" state
eventA = self.create_state_changed_event(
@ -1175,7 +1175,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "cleared (no sound detected)" == message
assert message == "cleared (no sound detected)"
def test_entry_message_from_state_binary_sensor_vibration(self):
"""Test if logbook message is correctly created for a binary_sensor."""
@ -1188,7 +1188,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "detected vibration" == message
assert message == "detected vibration"
# message for a binary_sensori vibration "cleared" state
eventA = self.create_state_changed_event(
@ -1196,7 +1196,7 @@ class TestComponentLogbook(unittest.TestCase):
)
to_state = ha.State.from_dict(eventA.data.get("new_state"))
message = logbook._entry_message_from_state(to_state.domain, to_state)
assert "cleared (no vibration detected)" == message
assert message == "cleared (no vibration detected)"
def test_process_custom_logbook_entries(self):
"""Test if custom log book entries get added as an entry."""
@ -1220,7 +1220,7 @@ class TestComponentLogbook(unittest.TestCase):
)
)
assert 1 == len(entries)
assert len(entries) == 1
self.assert_entry(
entries[0], name=name, message=message, domain="sun", entity_id=entity_id
)

View File

@ -57,7 +57,7 @@ class TestMHZ19Sensor(unittest.TestCase):
},
mock_add,
)
assert 1 == mock_add.call_count
assert mock_add.call_count == 1
@patch(
"pmsensor.co2sensor.read_mh_z19_with_temperature",
@ -98,11 +98,11 @@ class TestMHZ19Sensor(unittest.TestCase):
sensor = mhz19.MHZ19Sensor(client, mhz19.SENSOR_CO2, None, "name")
sensor.update()
assert "name: CO2" == sensor.name
assert 1000 == sensor.state
assert CONCENTRATION_PARTS_PER_MILLION == sensor.unit_of_measurement
assert sensor.name == "name: CO2"
assert sensor.state == 1000
assert sensor.unit_of_measurement == CONCENTRATION_PARTS_PER_MILLION
assert sensor.should_poll
assert {"temperature": 24} == sensor.device_state_attributes
assert sensor.device_state_attributes == {"temperature": 24}
@patch("pmsensor.co2sensor.read_mh_z19_with_temperature", return_value=(1000, 24))
def test_temperature_sensor(self, mock_function):
@ -113,11 +113,11 @@ class TestMHZ19Sensor(unittest.TestCase):
sensor = mhz19.MHZ19Sensor(client, mhz19.SENSOR_TEMPERATURE, None, "name")
sensor.update()
assert "name: Temperature" == sensor.name
assert 24 == sensor.state
assert "°C" == sensor.unit_of_measurement
assert sensor.name == "name: Temperature"
assert sensor.state == 24
assert sensor.unit_of_measurement == "°C"
assert sensor.should_poll
assert {"co2_concentration": 1000} == sensor.device_state_attributes
assert sensor.device_state_attributes == {"co2_concentration": 1000}
@patch("pmsensor.co2sensor.read_mh_z19_with_temperature", return_value=(1000, 24))
def test_temperature_sensor_f(self, mock_function):
@ -130,4 +130,4 @@ class TestMHZ19Sensor(unittest.TestCase):
)
sensor.update()
assert 75.2 == sensor.state
assert sensor.state == 75.2

View File

@ -221,7 +221,7 @@ class TestMinMaxSensor(unittest.TestCase):
state = self.hass.states.get("sensor.test")
assert str(float(self.values[0])) == state.state
assert "°C" == state.attributes.get("unit_of_measurement")
assert state.attributes.get("unit_of_measurement") == "°C"
self.hass.states.set(
entity_ids[1], self.values[1], {ATTR_UNIT_OF_MEASUREMENT: TEMP_FAHRENHEIT}
@ -231,7 +231,7 @@ class TestMinMaxSensor(unittest.TestCase):
state = self.hass.states.get("sensor.test")
assert STATE_UNKNOWN == state.state
assert "ERR" == state.attributes.get("unit_of_measurement")
assert state.attributes.get("unit_of_measurement") == "ERR"
self.hass.states.set(
entity_ids[2], self.values[2], {ATTR_UNIT_OF_MEASUREMENT: UNIT_PERCENTAGE}
@ -241,7 +241,7 @@ class TestMinMaxSensor(unittest.TestCase):
state = self.hass.states.get("sensor.test")
assert STATE_UNKNOWN == state.state
assert "ERR" == state.attributes.get("unit_of_measurement")
assert state.attributes.get("unit_of_measurement") == "ERR"
def test_last_sensor(self):
"""Test the last sensor."""

View File

@ -179,8 +179,8 @@ async def test_service_calls_with_entity_id(hass):
# Checking that values were not (!) restored
state = hass.states.get(ZONE_1_ID)
assert 1.0 == state.attributes[ATTR_MEDIA_VOLUME_LEVEL]
assert "three" == state.attributes[ATTR_INPUT_SOURCE]
assert state.attributes[ATTR_MEDIA_VOLUME_LEVEL] == 1.0
assert state.attributes[ATTR_INPUT_SOURCE] == "three"
# Restoring media player to its previous state
await _call_monoprice_service(hass, SERVICE_RESTORE, {"entity_id": ZONE_1_ID})
@ -188,8 +188,8 @@ async def test_service_calls_with_entity_id(hass):
state = hass.states.get(ZONE_1_ID)
assert 0.0 == state.attributes[ATTR_MEDIA_VOLUME_LEVEL]
assert "one" == state.attributes[ATTR_INPUT_SOURCE]
assert state.attributes[ATTR_MEDIA_VOLUME_LEVEL] == 0.0
assert state.attributes[ATTR_INPUT_SOURCE] == "one"
async def test_service_calls_with_all_entities(hass):
@ -221,8 +221,8 @@ async def test_service_calls_with_all_entities(hass):
state = hass.states.get(ZONE_1_ID)
assert 0.0 == state.attributes[ATTR_MEDIA_VOLUME_LEVEL]
assert "one" == state.attributes[ATTR_INPUT_SOURCE]
assert state.attributes[ATTR_MEDIA_VOLUME_LEVEL] == 0.0
assert state.attributes[ATTR_INPUT_SOURCE] == "one"
async def test_service_calls_without_relevant_entities(hass):
@ -254,8 +254,8 @@ async def test_service_calls_without_relevant_entities(hass):
state = hass.states.get(ZONE_1_ID)
assert 1.0 == state.attributes[ATTR_MEDIA_VOLUME_LEVEL]
assert "three" == state.attributes[ATTR_INPUT_SOURCE]
assert state.attributes[ATTR_MEDIA_VOLUME_LEVEL] == 1.0
assert state.attributes[ATTR_INPUT_SOURCE] == "three"
async def test_restore_without_snapshort(hass):
@ -290,8 +290,8 @@ async def test_update(hass):
state = hass.states.get(ZONE_1_ID)
assert 1.0 == state.attributes[ATTR_MEDIA_VOLUME_LEVEL]
assert "three" == state.attributes[ATTR_INPUT_SOURCE]
assert state.attributes[ATTR_MEDIA_VOLUME_LEVEL] == 1.0
assert state.attributes[ATTR_INPUT_SOURCE] == "three"
async def test_supported_features(hass):
@ -316,7 +316,7 @@ async def test_source_list(hass):
state = hass.states.get(ZONE_1_ID)
# Note, the list is sorted!
assert ["one", "three"] == state.attributes[ATTR_INPUT_SOURCE_LIST]
assert state.attributes[ATTR_INPUT_SOURCE_LIST] == ["one", "three"]
async def test_source_list_with_options(hass):
@ -325,7 +325,7 @@ async def test_source_list_with_options(hass):
state = hass.states.get(ZONE_1_ID)
# Note, the list is sorted!
assert ["two", "four"] == state.attributes[ATTR_INPUT_SOURCE_LIST]
assert state.attributes[ATTR_INPUT_SOURCE_LIST] == ["two", "four"]
async def test_select_source(hass):
@ -338,7 +338,7 @@ async def test_select_source(hass):
SERVICE_SELECT_SOURCE,
{"entity_id": ZONE_1_ID, ATTR_INPUT_SOURCE: "three"},
)
assert 3 == monoprice.zones[11].source
assert monoprice.zones[11].source == 3
# Trying to set unknown source
await _call_media_player_service(
@ -346,7 +346,7 @@ async def test_select_source(hass):
SERVICE_SELECT_SOURCE,
{"entity_id": ZONE_1_ID, ATTR_INPUT_SOURCE: "no name"},
)
assert 3 == monoprice.zones[11].source
assert monoprice.zones[11].source == 3
async def test_unknown_source(hass):
@ -403,27 +403,27 @@ async def test_volume_up_down(hass):
await _call_media_player_service(
hass, SERVICE_VOLUME_SET, {"entity_id": ZONE_1_ID, "volume_level": 0.0}
)
assert 0 == monoprice.zones[11].volume
assert monoprice.zones[11].volume == 0
await _call_media_player_service(
hass, SERVICE_VOLUME_DOWN, {"entity_id": ZONE_1_ID}
)
# should not go below zero
assert 0 == monoprice.zones[11].volume
assert monoprice.zones[11].volume == 0
await _call_media_player_service(hass, SERVICE_VOLUME_UP, {"entity_id": ZONE_1_ID})
assert 1 == monoprice.zones[11].volume
assert monoprice.zones[11].volume == 1
await _call_media_player_service(
hass, SERVICE_VOLUME_SET, {"entity_id": ZONE_1_ID, "volume_level": 1.0}
)
assert 38 == monoprice.zones[11].volume
assert monoprice.zones[11].volume == 38
await _call_media_player_service(hass, SERVICE_VOLUME_UP, {"entity_id": ZONE_1_ID})
# should not go above 38
assert 38 == monoprice.zones[11].volume
assert monoprice.zones[11].volume == 38
await _call_media_player_service(
hass, SERVICE_VOLUME_DOWN, {"entity_id": ZONE_1_ID}
)
assert 37 == monoprice.zones[11].volume
assert monoprice.zones[11].volume == 37

View File

@ -53,12 +53,12 @@ def entity_reg(hass):
@pytest.fixture
def mock_MQTT():
def mock_mqtt():
"""Make sure connection is established."""
with mock.patch("homeassistant.components.mqtt.MQTT") as mock_MQTT:
mock_MQTT.return_value.async_connect.return_value = mock_coro(True)
mock_MQTT.return_value.async_disconnect.return_value = mock_coro(True)
yield mock_MQTT
with mock.patch("homeassistant.components.mqtt.MQTT") as mock_mqtt:
mock_mqtt.return_value.async_connect.return_value = mock_coro(True)
mock_mqtt.return_value.async_disconnect.return_value = mock_coro(True)
yield mock_mqtt
async def async_mock_mqtt_client(hass, config=None):
@ -716,7 +716,7 @@ async def test_setup_raises_ConfigEntryNotReady_if_no_connect_broker(hass):
await mqtt.async_setup_entry(hass, entry)
async def test_setup_uses_certificate_on_certificate_set_to_auto(hass, mock_MQTT):
async def test_setup_uses_certificate_on_certificate_set_to_auto(hass, mock_mqtt):
"""Test setup uses bundled certs when certificate is set to auto."""
entry = MockConfigEntry(
domain=mqtt.DOMAIN,
@ -725,15 +725,15 @@ async def test_setup_uses_certificate_on_certificate_set_to_auto(hass, mock_MQTT
assert await mqtt.async_setup_entry(hass, entry)
assert mock_MQTT.called
assert mock_mqtt.called
import requests.certs
expectedCertificate = requests.certs.where()
assert mock_MQTT.mock_calls[0][2]["certificate"] == expectedCertificate
assert mock_mqtt.mock_calls[0][2]["certificate"] == expectedCertificate
async def test_setup_does_not_use_certificate_on_mqtts_port(hass, mock_MQTT):
async def test_setup_does_not_use_certificate_on_mqtts_port(hass, mock_mqtt):
"""Test setup doesn't use bundled certs when ssl set."""
entry = MockConfigEntry(
domain=mqtt.DOMAIN, data={mqtt.CONF_BROKER: "test-broker", "port": 8883}
@ -741,22 +741,22 @@ async def test_setup_does_not_use_certificate_on_mqtts_port(hass, mock_MQTT):
assert await mqtt.async_setup_entry(hass, entry)
assert mock_MQTT.called
assert mock_MQTT.mock_calls[0][2]["port"] == 8883
assert mock_mqtt.called
assert mock_mqtt.mock_calls[0][2]["port"] == 8883
import requests.certs
mqttsCertificateBundle = requests.certs.where()
assert mock_MQTT.mock_calls[0][2]["port"] != mqttsCertificateBundle
assert mock_mqtt.mock_calls[0][2]["port"] != mqttsCertificateBundle
async def test_setup_without_tls_config_uses_tlsv1_under_python36(hass, mock_MQTT):
async def test_setup_without_tls_config_uses_tlsv1_under_python36(hass, mock_mqtt):
"""Test setup defaults to TLSv1 under python3.6."""
entry = MockConfigEntry(domain=mqtt.DOMAIN, data={mqtt.CONF_BROKER: "test-broker"})
assert await mqtt.async_setup_entry(hass, entry)
assert mock_MQTT.called
assert mock_mqtt.called
import sys
@ -765,10 +765,10 @@ async def test_setup_without_tls_config_uses_tlsv1_under_python36(hass, mock_MQT
else:
expectedTlsVersion = ssl.PROTOCOL_TLSv1
assert mock_MQTT.mock_calls[0][2]["tls_version"] == expectedTlsVersion
assert mock_mqtt.mock_calls[0][2]["tls_version"] == expectedTlsVersion
async def test_setup_with_tls_config_uses_tls_version1_2(hass, mock_MQTT):
async def test_setup_with_tls_config_uses_tls_version1_2(hass, mock_mqtt):
"""Test setup uses specified TLS version."""
entry = MockConfigEntry(
domain=mqtt.DOMAIN, data={mqtt.CONF_BROKER: "test-broker", "tls_version": "1.2"}
@ -776,12 +776,12 @@ async def test_setup_with_tls_config_uses_tls_version1_2(hass, mock_MQTT):
assert await mqtt.async_setup_entry(hass, entry)
assert mock_MQTT.called
assert mock_mqtt.called
assert mock_MQTT.mock_calls[0][2]["tls_version"] == ssl.PROTOCOL_TLSv1_2
assert mock_mqtt.mock_calls[0][2]["tls_version"] == ssl.PROTOCOL_TLSv1_2
async def test_setup_with_tls_config_of_v1_under_python36_only_uses_v1(hass, mock_MQTT):
async def test_setup_with_tls_config_of_v1_under_python36_only_uses_v1(hass, mock_mqtt):
"""Test setup uses TLSv1.0 if explicitly chosen."""
entry = MockConfigEntry(
domain=mqtt.DOMAIN, data={mqtt.CONF_BROKER: "test-broker", "tls_version": "1.0"}
@ -789,8 +789,8 @@ async def test_setup_with_tls_config_of_v1_under_python36_only_uses_v1(hass, moc
assert await mqtt.async_setup_entry(hass, entry)
assert mock_MQTT.called
assert mock_MQTT.mock_calls[0][2]["tls_version"] == ssl.PROTOCOL_TLSv1
assert mock_mqtt.called
assert mock_mqtt.mock_calls[0][2]["tls_version"] == ssl.PROTOCOL_TLSv1
async def test_birth_message(hass):

View File

@ -23,9 +23,9 @@ async def async_init_integration(
def _handle_mock_api_request(method, endpoint, **kwargs):
if endpoint == "Login":
return {"SecurityToken": 1234}
elif endpoint == "My":
if endpoint == "My":
return {"Account": {"Id": 1}}
elif endpoint == "Accounts/1/Devices":
if endpoint == "Accounts/1/Devices":
return devices_dict
return {}

View File

@ -154,7 +154,7 @@ class TestNX584Watcher(unittest.TestCase):
watcher = nx584.NX584Watcher(None, zones)
watcher._process_zone_event({"zone": 1, "zone_state": False})
assert not zone1["state"]
assert 1 == mock_update.call_count
assert mock_update.call_count == 1
@mock.patch.object(nx584.NX584ZoneSensor, "schedule_update_ha_state")
def test_process_zone_event_missing_zone(self, mock_update):
@ -204,8 +204,7 @@ class TestNX584Watcher(unittest.TestCase):
if empty_me:
empty_me.pop()
raise requests.exceptions.ConnectionError()
else:
raise StopMe()
raise StopMe()
watcher = nx584.NX584Watcher(None, {})
with mock.patch.object(watcher, "_run") as mock_inner:

View File

@ -37,11 +37,10 @@ class PilightDaemonSim:
def __init__(self, host, port):
"""Init pilight client, ignore parameters."""
pass
def send_code(self, call): # pylint: disable=no-self-use
"""Handle pilight.send service callback."""
_LOGGER.error("PilightDaemonSim payload: " + str(call))
_LOGGER.error("PilightDaemonSim payload: %s", call)
def start(self):
"""Handle homeassistant.start callback.
@ -61,7 +60,7 @@ class PilightDaemonSim:
def set_callback(self, function):
"""Handle pilight.pilight_received event callback."""
self.callback = function
_LOGGER.error("PilightDaemonSim callback: " + str(function))
_LOGGER.error("PilightDaemonSim callback: %s", function)
@pytest.mark.skip("Flaky")
@ -91,7 +90,7 @@ class TestPilight(unittest.TestCase):
mock_client.assert_called_once_with(
host=pilight.DEFAULT_HOST, port=pilight.DEFAULT_PORT
)
assert 1 == mock_error.call_count
assert mock_error.call_count == 1
@patch("homeassistant.components.pilight._LOGGER.error")
def test_connection_timeout_error(self, mock_error):
@ -106,7 +105,7 @@ class TestPilight(unittest.TestCase):
mock_client.assert_called_once_with(
host=pilight.DEFAULT_HOST, port=pilight.DEFAULT_PORT
)
assert 1 == mock_error.call_count
assert mock_error.call_count == 1
@patch("pilight.pilight.Client", PilightDaemonSim)
@patch("homeassistant.core._LOGGER.error")

View File

@ -4,7 +4,7 @@ import unittest
import pytest
from homeassistant.components import rfxtrx as rfxtrx
from homeassistant.components import rfxtrx
from homeassistant.core import callback
from homeassistant.setup import setup_component

View File

@ -72,41 +72,41 @@ class TestVultrSwitchSetup(unittest.TestCase):
for device in self.DEVICES:
if device.subscription == "555555":
assert "Vultr {}" == device.name
assert device.name == "Vultr {}"
tested += 1
device.update()
device_attrs = device.device_state_attributes
if device.subscription == "555555":
assert "Vultr Another Server" == device.name
assert device.name == "Vultr Another Server"
tested += 1
if device.name == "A Server":
assert device.is_on is True
assert "on" == device.state
assert "mdi:server" == device.icon
assert "1000" == device_attrs[ATTR_ALLOWED_BANDWIDTH]
assert "yes" == device_attrs[ATTR_AUTO_BACKUPS]
assert "123.123.123.123" == device_attrs[ATTR_IPV4_ADDRESS]
assert "10.05" == device_attrs[ATTR_COST_PER_MONTH]
assert "2013-12-19 14:45:41" == device_attrs[ATTR_CREATED_AT]
assert "576965" == device_attrs[ATTR_SUBSCRIPTION_ID]
assert device.state == "on"
assert device.icon == "mdi:server"
assert device_attrs[ATTR_ALLOWED_BANDWIDTH] == "1000"
assert device_attrs[ATTR_AUTO_BACKUPS] == "yes"
assert device_attrs[ATTR_IPV4_ADDRESS] == "123.123.123.123"
assert device_attrs[ATTR_COST_PER_MONTH] == "10.05"
assert device_attrs[ATTR_CREATED_AT] == "2013-12-19 14:45:41"
assert device_attrs[ATTR_SUBSCRIPTION_ID] == "576965"
tested += 1
elif device.name == "Failed Server":
assert device.is_on is False
assert "off" == device.state
assert "mdi:server-off" == device.icon
assert "1000" == device_attrs[ATTR_ALLOWED_BANDWIDTH]
assert "no" == device_attrs[ATTR_AUTO_BACKUPS]
assert "192.168.100.50" == device_attrs[ATTR_IPV4_ADDRESS]
assert "73.25" == device_attrs[ATTR_COST_PER_MONTH]
assert "2014-10-13 14:45:41" == device_attrs[ATTR_CREATED_AT]
assert "123456" == device_attrs[ATTR_SUBSCRIPTION_ID]
assert device.state == "off"
assert device.icon == "mdi:server-off"
assert device_attrs[ATTR_ALLOWED_BANDWIDTH] == "1000"
assert device_attrs[ATTR_AUTO_BACKUPS] == "no"
assert device_attrs[ATTR_IPV4_ADDRESS] == "192.168.100.50"
assert device_attrs[ATTR_COST_PER_MONTH] == "73.25"
assert device_attrs[ATTR_CREATED_AT] == "2014-10-13 14:45:41"
assert device_attrs[ATTR_SUBSCRIPTION_ID] == "123456"
tested += 1
assert 4 == tested
assert tested == 4
@requests_mock.Mocker()
def test_turn_on(self, mock):
@ -120,7 +120,7 @@ class TestVultrSwitchSetup(unittest.TestCase):
device.turn_on()
# Turn on
assert 1 == mock_start.call_count
assert mock_start.call_count == 1
@requests_mock.Mocker()
def test_turn_off(self, mock):
@ -134,7 +134,7 @@ class TestVultrSwitchSetup(unittest.TestCase):
device.turn_off()
# Turn off
assert 1 == mock_halt.call_count
assert mock_halt.call_count == 1
def test_invalid_switch_config(self):
"""Test config type failures."""

View File

@ -11,7 +11,9 @@ import homeassistant.components.tts as tts
from homeassistant.setup import setup_component
from tests.common import assert_setup_component, get_test_home_assistant, mock_service
from tests.components.tts.test_init import mutagen_mock # noqa: F401
from tests.components.tts.test_init import ( # noqa: F401, pylint: disable=unused-import
mutagen_mock,
)
class TestTTSYandexPlatform:

View File

@ -853,7 +853,6 @@ def test_fan_action_value_changed(device):
def test_aux_heat_unsupported_set(device):
"""Test aux heat for climate device."""
device = device
assert device.values.primary.data == HVAC_MODE_HEAT
device.turn_aux_heat_on()
assert device.values.primary.data == HVAC_MODE_HEAT
@ -863,7 +862,6 @@ def test_aux_heat_unsupported_set(device):
def test_aux_heat_unsupported_value_changed(device):
"""Test aux heat for climate device."""
device = device
assert device.is_aux_heat is None
device.values.primary.data = HVAC_MODE_HEAT
value_changed(device.values.primary)

View File

@ -615,7 +615,7 @@ class TestZWaveNodeEntity(unittest.TestCase):
def test_name(self):
"""Test name property."""
assert "Mock Node" == self.entity.name
assert self.entity.name == "Mock Node"
def test_state_before_update(self):
"""Test state before update was called."""
@ -625,33 +625,33 @@ class TestZWaveNodeEntity(unittest.TestCase):
"""Test state property."""
self.node.is_ready = False
self.entity.node_changed()
assert "initializing" == self.entity.state
assert self.entity.state == "initializing"
self.node.is_failed = True
self.node.query_stage = "Complete"
self.entity.node_changed()
assert "dead" == self.entity.state
assert self.entity.state == "dead"
self.node.is_failed = False
self.node.is_awake = False
self.entity.node_changed()
assert "sleeping" == self.entity.state
assert self.entity.state == "sleeping"
def test_state_ready(self):
"""Test state property."""
self.node.query_stage = "Complete"
self.node.is_ready = True
self.entity.node_changed()
assert "ready" == self.entity.state
assert self.entity.state == "ready"
self.node.is_failed = True
self.entity.node_changed()
assert "dead" == self.entity.state
assert self.entity.state == "dead"
self.node.is_failed = False
self.node.is_awake = False
self.entity.node_changed()
assert "sleeping" == self.entity.state
assert self.entity.state == "sleeping"
def test_not_polled(self):
"""Test should_poll property."""
@ -659,7 +659,7 @@ class TestZWaveNodeEntity(unittest.TestCase):
def test_unique_id(self):
"""Test unique_id."""
assert "node-567" == self.entity.unique_id
assert self.entity.unique_id == "node-567"
def test_unique_id_missing_data(self):
"""Test unique_id."""

View File

@ -128,7 +128,7 @@ async def test_bootstrap_error(hass, loop):
res = await async_check_ha_config_file(hass)
log_ha_config(res)
res.errors[0].domain is None
assert res.errors[0].domain is None
# Only 1 error expected
res.errors.pop(0)

View File

@ -180,7 +180,7 @@ async def test_if_numeric_state_not_raise_on_unavailable(hass):
async def test_extract_entities():
"""Test extracting entities."""
condition.async_extract_entities(
assert condition.async_extract_entities(
{
"condition": "and",
"conditions": [
@ -201,7 +201,7 @@ async def test_extract_entities():
async def test_extract_devices():
"""Test extracting devices."""
condition.async_extract_devices(
assert condition.async_extract_devices(
{
"condition": "and",
"conditions": [

View File

@ -621,11 +621,11 @@ def test_deprecated_with_invalidation_version(caplog, schema, version):
test_data = {"mars": True}
with pytest.raises(vol.MultipleInvalid) as exc_info:
invalidated_schema(test_data)
assert (
assert str(exc_info.value) == (
"The 'mars' option (with value 'True') is deprecated, "
"please remove it from your configuration. This option will "
"become invalid in version 0.1.0"
) == str(exc_info.value)
)
def test_deprecated_with_replacement_key_and_invalidation_version(
@ -681,11 +681,11 @@ def test_deprecated_with_replacement_key_and_invalidation_version(
test_data = {"mars": True}
with pytest.raises(vol.MultipleInvalid) as exc_info:
invalidated_schema(test_data)
assert (
assert str(exc_info.value) == (
"The 'mars' option (with value 'True') is deprecated, "
"please replace it with 'jupiter'. This option will become "
"invalid in version 0.1.0"
) == str(exc_info.value)
)
def test_deprecated_with_default(caplog, schema):
@ -833,11 +833,11 @@ def test_deprecated_with_replacement_key_invalidation_version_default(
test_data = {"mars": True}
with pytest.raises(vol.MultipleInvalid) as exc_info:
invalidated_schema(test_data)
assert (
assert str(exc_info.value) == (
"The 'mars' option (with value 'True') is deprecated, "
"please replace it with 'jupiter'. This option will become "
"invalid in version 0.1.0"
) == str(exc_info.value)
)
def test_deprecated_cant_find_module():

View File

@ -11,7 +11,7 @@ import voluptuous as vol
# To prevent circular import when running just this file
from homeassistant import core as ha, exceptions
from homeassistant.auth.permissions import PolicyPermissions
import homeassistant.components # noqa: F401
import homeassistant.components # noqa: F401, pylint: disable=unused-import
from homeassistant.const import (
ATTR_ENTITY_ID,
ENTITY_MATCH_ALL,
@ -144,10 +144,10 @@ class TestServiceHelpers(unittest.TestCase):
service.call_from_config(self.hass, config)
self.hass.block_till_done()
assert "goodbye" == self.calls[0].data["hello"]
assert "complex" == self.calls[0].data["data"]["value"]
assert "simple" == self.calls[0].data["data"]["simple"]
assert "list" == self.calls[0].data["list"][0]
assert self.calls[0].data["hello"] == "goodbye"
assert self.calls[0].data["data"]["value"] == "complex"
assert self.calls[0].data["data"]["simple"] == "simple"
assert self.calls[0].data["list"][0] == "list"
def test_passing_variables_to_templates(self):
"""Test passing variables to templates."""
@ -167,7 +167,7 @@ class TestServiceHelpers(unittest.TestCase):
)
self.hass.block_till_done()
assert "goodbye" == self.calls[0].data["hello"]
assert self.calls[0].data["hello"] == "goodbye"
def test_bad_template(self):
"""Test passing bad template."""
@ -223,13 +223,13 @@ class TestServiceHelpers(unittest.TestCase):
def test_fail_silently_if_no_service(self, mock_log):
"""Test failing if service is missing."""
service.call_from_config(self.hass, None)
assert 1 == mock_log.call_count
assert mock_log.call_count == 1
service.call_from_config(self.hass, {})
assert 2 == mock_log.call_count
assert mock_log.call_count == 2
service.call_from_config(self.hass, {"service": "invalid"})
assert 3 == mock_log.call_count
assert mock_log.call_count == 3
async def test_extract_entity_ids(hass):

View File

@ -129,8 +129,8 @@ async def test_reproduce_turn_on(hass):
assert len(calls) > 0
last_call = calls[-1]
assert last_call.domain == "light"
assert SERVICE_TURN_ON == last_call.service
assert "light.test" == last_call.data.get("entity_id")
assert last_call.service == SERVICE_TURN_ON
assert last_call.data.get("entity_id") == "light.test"
async def test_reproduce_turn_off(hass):
@ -146,8 +146,8 @@ async def test_reproduce_turn_off(hass):
assert len(calls) > 0
last_call = calls[-1]
assert last_call.domain == "light"
assert SERVICE_TURN_OFF == last_call.service
assert "light.test" == last_call.data.get("entity_id")
assert last_call.service == SERVICE_TURN_OFF
assert last_call.data.get("entity_id") == "light.test"
async def test_reproduce_complex_data(hass):
@ -167,8 +167,8 @@ async def test_reproduce_complex_data(hass):
assert len(calls) > 0
last_call = calls[-1]
assert last_call.domain == "light"
assert SERVICE_TURN_ON == last_call.service
assert complex_data == last_call.data.get("rgb_color")
assert last_call.service == SERVICE_TURN_ON
assert last_call.data.get("rgb_color") == complex_data
async def test_reproduce_bad_state(hass):

View File

@ -111,8 +111,8 @@ async def test_ensure_config_exists_uses_existing_config(hass):
create_file(YAML_PATH)
await config_util.async_ensure_config_exists(hass)
with open(YAML_PATH) as f:
content = f.read()
with open(YAML_PATH) as fp:
content = fp.read()
# File created with create_file are empty
assert content == ""
@ -127,8 +127,8 @@ def test_load_yaml_config_converts_empty_files_to_dict():
def test_load_yaml_config_raises_error_if_not_dict():
"""Test error raised when YAML file is not a dict."""
with open(YAML_PATH, "w") as f:
f.write("5")
with open(YAML_PATH, "w") as fp:
fp.write("5")
with pytest.raises(HomeAssistantError):
config_util.load_yaml_config_file(YAML_PATH)
@ -136,8 +136,8 @@ def test_load_yaml_config_raises_error_if_not_dict():
def test_load_yaml_config_raises_error_if_malformed_yaml():
"""Test error raised if invalid YAML."""
with open(YAML_PATH, "w") as f:
f.write(":")
with open(YAML_PATH, "w") as fp:
fp.write(":")
with pytest.raises(HomeAssistantError):
config_util.load_yaml_config_file(YAML_PATH)
@ -145,8 +145,8 @@ def test_load_yaml_config_raises_error_if_malformed_yaml():
def test_load_yaml_config_raises_error_if_unsafe_yaml():
"""Test error raised if unsafe YAML."""
with open(YAML_PATH, "w") as f:
f.write("hello: !!python/object/apply:os.system")
with open(YAML_PATH, "w") as fp:
fp.write("hello: !!python/object/apply:os.system")
with pytest.raises(HomeAssistantError):
config_util.load_yaml_config_file(YAML_PATH)
@ -154,9 +154,9 @@ def test_load_yaml_config_raises_error_if_unsafe_yaml():
def test_load_yaml_config_preserves_key_order():
"""Test removal of library."""
with open(YAML_PATH, "w") as f:
f.write("hello: 2\n")
f.write("world: 1\n")
with open(YAML_PATH, "w") as fp:
fp.write("hello: 2\n")
fp.write("world: 1\n")
assert [("hello", 2), ("world", 1)] == list(
config_util.load_yaml_config_file(YAML_PATH).items()

View File

@ -304,10 +304,11 @@ class TestEvent(unittest.TestCase):
def test_repr(self):
"""Test that repr method works."""
assert "<Event TestEvent[L]>" == str(ha.Event("TestEvent"))
assert str(ha.Event("TestEvent")) == "<Event TestEvent[L]>"
assert "<Event TestEvent[R]: beer=nice>" == str(
ha.Event("TestEvent", {"beer": "nice"}, ha.EventOrigin.remote)
assert (
str(ha.Event("TestEvent", {"beer": "nice"}, ha.EventOrigin.remote))
== "<Event TestEvent[R]: beer=nice>"
)
def test_as_dict(self):
@ -402,7 +403,7 @@ class TestEventBus(unittest.TestCase):
self.bus.fire("test_event")
self.hass.block_till_done()
assert 1 == len(runs)
assert len(runs) == 1
def test_listen_once_event_with_coroutine(self):
"""Test listen_once_event method."""
@ -419,7 +420,7 @@ class TestEventBus(unittest.TestCase):
self.bus.fire("test_event")
self.hass.block_till_done()
assert 1 == len(runs)
assert len(runs) == 1
def test_listen_once_event_with_thread(self):
"""Test listen_once_event method."""
@ -435,7 +436,7 @@ class TestEventBus(unittest.TestCase):
self.bus.fire("test_event")
self.hass.block_till_done()
assert 1 == len(runs)
assert len(runs) == 1
def test_thread_event_listener(self):
"""Test thread event listener."""
@ -488,26 +489,26 @@ def test_state_init():
def test_state_domain():
"""Test domain."""
state = ha.State("some_domain.hello", "world")
assert "some_domain" == state.domain
assert state.domain == "some_domain"
def test_state_object_id():
"""Test object ID."""
state = ha.State("domain.hello", "world")
assert "hello" == state.object_id
assert state.object_id == "hello"
def test_state_name_if_no_friendly_name_attr():
"""Test if there is no friendly name."""
state = ha.State("domain.hello_world", "world")
assert "hello world" == state.name
assert state.name == "hello world"
def test_state_name_if_friendly_name_attr():
"""Test if there is a friendly name."""
name = "Some Unique Name"
state = ha.State("domain.hello_world", "world", {ATTR_FRIENDLY_NAME: name})
assert name == state.name
assert state.name == name
def test_state_dict_conversion():
@ -535,14 +536,13 @@ def test_state_dict_conversion_with_wrong_data():
def test_state_repr():
"""Test state.repr."""
assert "<state happy.happy=on @ 1984-12-08T12:00:00+00:00>" == str(
ha.State("happy.happy", "on", last_changed=datetime(1984, 12, 8, 12, 0, 0))
assert (
str(ha.State("happy.happy", "on", last_changed=datetime(1984, 12, 8, 12, 0, 0)))
== "<state happy.happy=on @ 1984-12-08T12:00:00+00:00>"
)
assert (
"<state happy.happy=on; brightness=144 @ "
"1984-12-08T12:00:00+00:00>"
== str(
str(
ha.State(
"happy.happy",
"on",
@ -550,6 +550,8 @@ def test_state_repr():
datetime(1984, 12, 8, 12, 0, 0),
)
)
== "<state happy.happy=on; brightness=144 @ "
"1984-12-08T12:00:00+00:00>"
)
@ -578,12 +580,12 @@ class TestStateMachine(unittest.TestCase):
def test_entity_ids(self):
"""Test get_entity_ids method."""
ent_ids = self.states.entity_ids()
assert 2 == len(ent_ids)
assert len(ent_ids) == 2
assert "light.bowl" in ent_ids
assert "switch.ac" in ent_ids
ent_ids = self.states.entity_ids("light")
assert 1 == len(ent_ids)
assert len(ent_ids) == 1
assert "light.bowl" in ent_ids
def test_all(self):
@ -606,16 +608,16 @@ class TestStateMachine(unittest.TestCase):
self.hass.block_till_done()
assert "light.bowl" not in self.states.entity_ids()
assert 1 == len(events)
assert "light.bowl" == events[0].data.get("entity_id")
assert len(events) == 1
assert events[0].data.get("entity_id") == "light.bowl"
assert events[0].data.get("old_state") is not None
assert "light.bowl" == events[0].data["old_state"].entity_id
assert events[0].data["old_state"].entity_id == "light.bowl"
assert events[0].data.get("new_state") is None
# If it does not exist, we should get False
assert not self.states.remove("light.Bowl")
self.hass.block_till_done()
assert 1 == len(events)
assert len(events) == 1
def test_case_insensitivty(self):
"""Test insensitivty."""
@ -631,7 +633,7 @@ class TestStateMachine(unittest.TestCase):
self.hass.block_till_done()
assert self.states.is_state("light.bowl", "off")
assert 1 == len(runs)
assert len(runs) == 1
def test_last_changed_not_updated_on_same_state(self):
"""Test to not update the existing, same state."""
@ -659,11 +661,11 @@ class TestStateMachine(unittest.TestCase):
self.states.set("light.bowl", "on")
self.hass.block_till_done()
assert 0 == len(events)
assert len(events) == 0
self.states.set("light.bowl", "on", None, True)
self.hass.block_till_done()
assert 1 == len(events)
assert len(events) == 1
def test_service_call_repr():
@ -734,7 +736,7 @@ class TestServiceRegistry(unittest.TestCase):
assert self.calls_register[-1].data["service"] == "register_calls"
assert self.services.call("test_domain", "REGISTER_CALLS", blocking=True)
assert 1 == len(calls)
assert len(calls) == 1
def test_call_non_existing_with_blocking(self):
"""Test non-existing with blocking."""
@ -758,7 +760,7 @@ class TestServiceRegistry(unittest.TestCase):
assert self.services.call("test_domain", "REGISTER_CALLS", blocking=True)
self.hass.block_till_done()
assert 1 == len(calls)
assert len(calls) == 1
def test_async_service_partial(self):
"""Test registering and calling an wrapped async service."""
@ -799,7 +801,7 @@ class TestServiceRegistry(unittest.TestCase):
assert self.services.call("test_domain", "REGISTER_CALLS", blocking=True)
self.hass.block_till_done()
assert 1 == len(calls)
assert len(calls) == 1
def test_remove_service(self):
"""Test remove service."""
@ -888,12 +890,12 @@ class TestConfig(unittest.TestCase):
def test_path_with_file(self):
"""Test get_config_path method."""
self.config.config_dir = "/test/ha-config"
assert "/test/ha-config/test.conf" == self.config.path("test.conf")
assert self.config.path("test.conf") == "/test/ha-config/test.conf"
def test_path_with_dir_and_file(self):
"""Test get_config_path method."""
self.config.config_dir = "/test/ha-config"
assert "/test/ha-config/dir/test.conf" == self.config.path("dir", "test.conf")
assert self.config.path("dir", "test.conf") == "/test/ha-config/dir/test.conf"
def test_as_dict(self):
"""Test as dict."""
@ -1056,7 +1058,7 @@ def test_timer_out_of_sync(mock_monotonic, loop):
assert abs(event_data[ATTR_SECONDS] - 2.433333) < 0.001
assert len(funcs) == 2
fire_time_event, stop_timer = funcs
fire_time_event, _ = funcs
assert len(hass.loop.call_later.mock_calls) == 2