mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 17:57:55 +00:00
Tweak logging statements in tests (#119664)
This commit is contained in:
parent
e6b7301367
commit
4b29c35453
@ -72,10 +72,10 @@ async def simulate_time(hass, mock_litejet, delta):
|
||||
"homeassistant.helpers.condition.dt_util.utcnow",
|
||||
return_value=mock_litejet.start_time + delta,
|
||||
):
|
||||
_LOGGER.info("now=%s", dt_util.utcnow())
|
||||
_LOGGER.info("*** now=%s", dt_util.utcnow())
|
||||
async_fire_time_changed_exact(hass, mock_litejet.start_time + delta)
|
||||
await hass.async_block_till_done()
|
||||
_LOGGER.info("done with now=%s", dt_util.utcnow())
|
||||
_LOGGER.info("*** done with now=%s", dt_util.utcnow())
|
||||
|
||||
|
||||
async def setup_automation(hass, trigger):
|
||||
|
@ -109,7 +109,7 @@ async def test_normal_logs(
|
||||
await async_setup_component(hass, system_log.DOMAIN, BASIC_CONFIG)
|
||||
await hass.async_block_till_done()
|
||||
_LOGGER.debug("debug")
|
||||
_LOGGER.info("info")
|
||||
_LOGGER.info("Info")
|
||||
|
||||
# Assert done by get_error_log
|
||||
logs = await get_error_log(hass_ws_client)
|
||||
@ -133,10 +133,10 @@ async def test_warning(hass: HomeAssistant, hass_ws_client: WebSocketGenerator)
|
||||
"""Test that warning are logged and retrieved correctly."""
|
||||
await async_setup_component(hass, system_log.DOMAIN, BASIC_CONFIG)
|
||||
await hass.async_block_till_done()
|
||||
_LOGGER.warning("warning message")
|
||||
_LOGGER.warning("Warning message")
|
||||
|
||||
log = find_log(await get_error_log(hass_ws_client), "WARNING")
|
||||
assert_log(log, "", "warning message", "WARNING")
|
||||
assert_log(log, "", "Warning message", "WARNING")
|
||||
|
||||
|
||||
async def test_warning_good_format(
|
||||
@ -145,11 +145,11 @@ async def test_warning_good_format(
|
||||
"""Test that warning with good format arguments are logged and retrieved correctly."""
|
||||
await async_setup_component(hass, system_log.DOMAIN, BASIC_CONFIG)
|
||||
await hass.async_block_till_done()
|
||||
_LOGGER.warning("warning message: %s", "test")
|
||||
_LOGGER.warning("Warning message: %s", "test")
|
||||
await hass.async_block_till_done()
|
||||
|
||||
log = find_log(await get_error_log(hass_ws_client), "WARNING")
|
||||
assert_log(log, "", "warning message: test", "WARNING")
|
||||
assert_log(log, "", "Warning message: test", "WARNING")
|
||||
|
||||
|
||||
async def test_warning_missing_format_args(
|
||||
@ -158,11 +158,11 @@ async def test_warning_missing_format_args(
|
||||
"""Test that warning with missing format arguments are logged and retrieved correctly."""
|
||||
await async_setup_component(hass, system_log.DOMAIN, BASIC_CONFIG)
|
||||
await hass.async_block_till_done()
|
||||
_LOGGER.warning("warning message missing a format arg %s")
|
||||
_LOGGER.warning("Warning message missing a format arg %s")
|
||||
await hass.async_block_till_done()
|
||||
|
||||
log = find_log(await get_error_log(hass_ws_client), "WARNING")
|
||||
assert_log(log, "", ["warning message missing a format arg %s"], "WARNING")
|
||||
assert_log(log, "", ["Warning message missing a format arg %s"], "WARNING")
|
||||
|
||||
|
||||
async def test_error(hass: HomeAssistant, hass_ws_client: WebSocketGenerator) -> None:
|
||||
@ -170,10 +170,10 @@ async def test_error(hass: HomeAssistant, hass_ws_client: WebSocketGenerator) ->
|
||||
await async_setup_component(hass, system_log.DOMAIN, BASIC_CONFIG)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
_LOGGER.error("error message")
|
||||
_LOGGER.error("Error message")
|
||||
|
||||
log = find_log(await get_error_log(hass_ws_client), "ERROR")
|
||||
assert_log(log, "", "error message", "ERROR")
|
||||
assert_log(log, "", "Error message", "ERROR")
|
||||
|
||||
|
||||
async def test_config_not_fire_event(hass: HomeAssistant) -> None:
|
||||
@ -200,17 +200,17 @@ async def test_error_posted_as_event(hass: HomeAssistant) -> None:
|
||||
watcher = await async_setup_system_log(
|
||||
hass, {"system_log": {"max_entries": 2, "fire_event": True}}
|
||||
)
|
||||
wait_empty = watcher.add_watcher("error message")
|
||||
wait_empty = watcher.add_watcher("Error message")
|
||||
|
||||
events = async_capture_events(hass, system_log.EVENT_SYSTEM_LOG)
|
||||
|
||||
_LOGGER.error("error message")
|
||||
_LOGGER.error("Error message")
|
||||
await wait_empty
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(events) == 1
|
||||
assert_log(events[0].data, "", "error message", "ERROR")
|
||||
assert_log(events[0].data, "", "Error message", "ERROR")
|
||||
|
||||
|
||||
async def test_critical(
|
||||
@ -220,10 +220,10 @@ async def test_critical(
|
||||
await async_setup_component(hass, system_log.DOMAIN, BASIC_CONFIG)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
_LOGGER.critical("critical message")
|
||||
_LOGGER.critical("Critical message")
|
||||
|
||||
log = find_log(await get_error_log(hass_ws_client), "CRITICAL")
|
||||
assert_log(log, "", "critical message", "CRITICAL")
|
||||
assert_log(log, "", "Critical message", "CRITICAL")
|
||||
|
||||
|
||||
async def test_remove_older_logs(
|
||||
@ -232,18 +232,18 @@ async def test_remove_older_logs(
|
||||
"""Test that older logs are rotated out."""
|
||||
await async_setup_component(hass, system_log.DOMAIN, BASIC_CONFIG)
|
||||
await hass.async_block_till_done()
|
||||
_LOGGER.error("error message 1")
|
||||
_LOGGER.error("error message 2")
|
||||
_LOGGER.error("error message 3")
|
||||
_LOGGER.error("Error message 1")
|
||||
_LOGGER.error("Error message 2")
|
||||
_LOGGER.error("Error message 3")
|
||||
await hass.async_block_till_done()
|
||||
log = await get_error_log(hass_ws_client)
|
||||
assert_log(log[0], "", "error message 3", "ERROR")
|
||||
assert_log(log[1], "", "error message 2", "ERROR")
|
||||
assert_log(log[0], "", "Error message 3", "ERROR")
|
||||
assert_log(log[1], "", "Error message 2", "ERROR")
|
||||
|
||||
|
||||
def log_msg(nr=2):
|
||||
"""Log an error at same line."""
|
||||
_LOGGER.error("error message %s", nr)
|
||||
_LOGGER.error("Error message %s", nr)
|
||||
|
||||
|
||||
async def test_dedupe_logs(
|
||||
@ -252,19 +252,19 @@ async def test_dedupe_logs(
|
||||
"""Test that duplicate log entries are dedupe."""
|
||||
await async_setup_component(hass, system_log.DOMAIN, BASIC_CONFIG)
|
||||
await hass.async_block_till_done()
|
||||
_LOGGER.error("error message 1")
|
||||
_LOGGER.error("Error message 1")
|
||||
log_msg()
|
||||
log_msg("2-2")
|
||||
_LOGGER.error("error message 3")
|
||||
_LOGGER.error("Error message 3")
|
||||
|
||||
log = await get_error_log(hass_ws_client)
|
||||
assert_log(log[0], "", "error message 3", "ERROR")
|
||||
assert_log(log[0], "", "Error message 3", "ERROR")
|
||||
assert log[1]["count"] == 2
|
||||
assert_log(log[1], "", ["error message 2", "error message 2-2"], "ERROR")
|
||||
assert_log(log[1], "", ["Error message 2", "Error message 2-2"], "ERROR")
|
||||
|
||||
log_msg()
|
||||
log = await get_error_log(hass_ws_client)
|
||||
assert_log(log[0], "", ["error message 2", "error message 2-2"], "ERROR")
|
||||
assert_log(log[0], "", ["Error message 2", "Error message 2-2"], "ERROR")
|
||||
assert log[0]["timestamp"] > log[0]["first_occurred"]
|
||||
|
||||
log_msg("2-3")
|
||||
@ -277,11 +277,11 @@ async def test_dedupe_logs(
|
||||
log[0],
|
||||
"",
|
||||
[
|
||||
"error message 2-2",
|
||||
"error message 2-3",
|
||||
"error message 2-4",
|
||||
"error message 2-5",
|
||||
"error message 2-6",
|
||||
"Error message 2-2",
|
||||
"Error message 2-3",
|
||||
"Error message 2-4",
|
||||
"Error message 2-5",
|
||||
"Error message 2-6",
|
||||
],
|
||||
"ERROR",
|
||||
)
|
||||
@ -293,7 +293,7 @@ async def test_clear_logs(
|
||||
"""Test that the log can be cleared via a service call."""
|
||||
await async_setup_component(hass, system_log.DOMAIN, BASIC_CONFIG)
|
||||
await hass.async_block_till_done()
|
||||
_LOGGER.error("error message")
|
||||
_LOGGER.error("Error message")
|
||||
|
||||
await hass.services.async_call(system_log.DOMAIN, system_log.SERVICE_CLEAR, {})
|
||||
await hass.async_block_till_done()
|
||||
@ -354,7 +354,7 @@ async def test_unknown_path(
|
||||
await async_setup_component(hass, system_log.DOMAIN, BASIC_CONFIG)
|
||||
await hass.async_block_till_done()
|
||||
_LOGGER.findCaller = MagicMock(return_value=("unknown_path", 0, None, None))
|
||||
_LOGGER.error("error message")
|
||||
_LOGGER.error("Error message")
|
||||
log = (await get_error_log(hass_ws_client))[0]
|
||||
assert log["source"] == ["unknown_path", 0]
|
||||
|
||||
@ -385,8 +385,8 @@ async def async_log_error_from_test_path(hass, path, watcher):
|
||||
return_value=logger_frame,
|
||||
),
|
||||
):
|
||||
wait_empty = watcher.add_watcher("error message")
|
||||
_LOGGER.error("error message")
|
||||
wait_empty = watcher.add_watcher("Error message")
|
||||
_LOGGER.error("Error message")
|
||||
await wait_empty
|
||||
|
||||
|
||||
@ -444,7 +444,7 @@ async def test_raise_during_log_capture(
|
||||
|
||||
raise_during_repr = RaisesDuringRepr()
|
||||
|
||||
_LOGGER.error("raise during repr: %s", raise_during_repr)
|
||||
_LOGGER.error("Raise during repr: %s", raise_during_repr)
|
||||
log = find_log(await get_error_log(hass_ws_client), "ERROR")
|
||||
assert log is not None
|
||||
assert_log(log, "", "Bad logger message: repr error", "ERROR")
|
||||
|
Loading…
x
Reference in New Issue
Block a user