Skip to content

Commit

Permalink
fix: walmart sensors crashing (#811)
Browse files Browse the repository at this point in the history
* fix: walmart sensors crashing

* update tests
  • Loading branch information
firstof9 authored Apr 10, 2023
1 parent e8fb676 commit 024d520
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 37 deletions.
8 changes: 0 additions & 8 deletions custom_components/mail_and_packages/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,6 @@
"subject": ["delivery is delayed"],
},
"walmart_tracking": {"patern": ["#[0-9]{7}-[0-9]{7}"]},
"walmart_packages": {},
}

# Sensor definitions
Expand Down Expand Up @@ -874,12 +873,6 @@
icon="mdi:archive-alert",
key="walmart_exception",
),
"walmart_packages": SensorEntityDescription(
name="Mail Walmart Packages",
native_unit_of_measurement="package(s)",
icon="mdi:package-variant-closed",
key="walmart_packages",
),
###
# !!! Insert new sensors above these two !!!
###
Expand Down Expand Up @@ -954,5 +947,4 @@
"bonshaw_distribution_network",
"purolator",
"intelcom",
"walmart",
]
6 changes: 0 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,6 @@ def mock_update_time():
def mock_image():
"""Fixture to mock Image."""
with patch("custom_components.mail_and_packages.helpers.Image") as mock_image:

yield mock_image


Expand Down Expand Up @@ -985,7 +984,6 @@ def mock_resizeimage():
) as mock_resizeimage, patch(
"custom_components.mail_and_packages.helpers.ImageOps"
):

yield mock_resizeimage


Expand All @@ -1001,23 +999,20 @@ def mock_os_path_isfile():
def mock_os_path_join():
"""Fixture to mock join."""
with patch("os.path.join") as mock_path_join:

yield mock_path_join


@pytest.fixture
def mock_os_path_split():
"""Fixture to mock split."""
with patch("os.path.split") as mock_os_path_split:

yield mock_os_path_split


@pytest.fixture
def mock_subprocess_call():
"""Fixture to mock subprocess."""
with patch("subprocess.call") as mock_subprocess_call:

yield mock_subprocess_call


Expand All @@ -1027,7 +1022,6 @@ def mock_copy_overlays():
with patch(
"custom_components.mail_and_packages.helpers.copy_overlays"
) as mock_copy_overlays:

yield mock_copy_overlays


Expand Down
4 changes: 4 additions & 0 deletions tests/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@
"gls_delivered",
"gls_delivering",
"gls_packages",
"walmart_delivered",
"walmart_exception",
],
"scan_interval": 20,
"username": "[email protected]",
Expand Down Expand Up @@ -287,6 +289,8 @@
"usps_delivering",
"usps_mail",
"usps_packages",
"walmart_delivered",
"walmart_exception",
"zpackages_delivered",
"zpackages_transit",
],
Expand Down
17 changes: 0 additions & 17 deletions tests/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ async def test_form(
"custom_components.mail_and_packages.async_setup_entry",
return_value=True,
) as mock_setup_entry:

result2 = await hass.config_entries.flow.async_configure(
result["flow_id"], input_1
)
Expand Down Expand Up @@ -315,7 +314,6 @@ async def test_form_invalid_custom_img_path(
"custom_components.mail_and_packages.async_setup_entry",
return_value=True,
) as mock_setup_entry:

result2 = await hass.config_entries.flow.async_configure(
result["flow_id"], input_1
)
Expand Down Expand Up @@ -374,7 +372,6 @@ async def test_form_connection_error(input_1, step_id_2, hass, mock_imap):
"custom_components.mail_and_packages.async_setup_entry",
return_value=True,
) as mock_setup_entry:

result2 = await hass.config_entries.flow.async_configure(
result["flow_id"], input_1
)
Expand Down Expand Up @@ -502,7 +499,6 @@ async def test_form_invalid_ffmpeg(
"custom_components.mail_and_packages.async_setup_entry",
return_value=True,
) as mock_setup_entry:

result2 = await hass.config_entries.flow.async_configure(
result["flow_id"], input_1
)
Expand Down Expand Up @@ -645,7 +641,6 @@ async def test_form_index_error(
"custom_components.mail_and_packages.async_setup_entry",
return_value=True,
) as mock_setup_entry:

result2 = await hass.config_entries.flow.async_configure(
result["flow_id"], input_1
)
Expand Down Expand Up @@ -792,7 +787,6 @@ async def test_form_index_error_2(
"custom_components.mail_and_packages.async_setup_entry",
return_value=True,
) as mock_setup_entry:

result2 = await hass.config_entries.flow.async_configure(
result["flow_id"], input_1
)
Expand Down Expand Up @@ -938,7 +932,6 @@ async def test_form_mailbox_format2(
"custom_components.mail_and_packages.async_setup_entry",
return_value=True,
) as mock_setup_entry:

result2 = await hass.config_entries.flow.async_configure(
result["flow_id"], input_1
)
Expand Down Expand Up @@ -1141,7 +1134,6 @@ async def test_options_flow(
"custom_components.mail_and_packages.async_setup_entry",
return_value=True,
) as mock_setup_entry:

result2 = await hass.config_entries.options.async_configure(
result["flow_id"], input_1
)
Expand Down Expand Up @@ -1315,7 +1307,6 @@ async def test_options_flow_invalid_custom_img_path(
"custom_components.mail_and_packages.async_setup_entry",
return_value=True,
) as mock_setup_entry:

result2 = await hass.config_entries.options.async_configure(
result["flow_id"], input_1
)
Expand Down Expand Up @@ -1389,7 +1380,6 @@ async def test_options_flow_connection_error(
"custom_components.mail_and_packages.async_setup_entry",
return_value=True,
) as mock_setup_entry:

result2 = await hass.config_entries.options.async_configure(
result["flow_id"], input_1
)
Expand Down Expand Up @@ -1532,7 +1522,6 @@ async def test_options_flow_invalid_ffmpeg(
"custom_components.mail_and_packages.async_setup_entry",
return_value=True,
) as mock_setup_entry:

result2 = await hass.config_entries.options.async_configure(
result["flow_id"], input_1
)
Expand Down Expand Up @@ -1681,7 +1670,6 @@ async def test_options_flow_index_error(
"custom_components.mail_and_packages.async_setup_entry",
return_value=True,
) as mock_setup_entry:

result2 = await hass.config_entries.options.async_configure(
result["flow_id"], input_1
)
Expand Down Expand Up @@ -1831,7 +1819,6 @@ async def test_options_flow_index_error_2(
"custom_components.mail_and_packages.async_setup_entry",
return_value=True,
) as mock_setup_entry:

result2 = await hass.config_entries.options.async_configure(
result["flow_id"], input_1
)
Expand Down Expand Up @@ -1981,7 +1968,6 @@ async def test_options_flow_mailbox_format2(
"custom_components.mail_and_packages.async_setup_entry",
return_value=True,
) as mock_setup_entry:

result2 = await hass.config_entries.options.async_configure(
result["flow_id"], input_1
)
Expand Down Expand Up @@ -2136,7 +2122,6 @@ async def test_options_flow_bad(
"custom_components.mail_and_packages.async_setup_entry",
return_value=True,
) as mock_setup_entry:

result2 = await hass.config_entries.options.async_configure(
result["flow_id"], input_1
)
Expand Down Expand Up @@ -2234,7 +2219,6 @@ async def test_form_amazon_error(
"custom_components.mail_and_packages.async_setup_entry",
return_value=True,
) as mock_setup_entry:

result2 = await hass.config_entries.flow.async_configure(
result["flow_id"], input_1
)
Expand Down Expand Up @@ -2329,7 +2313,6 @@ async def test_form_interval_low(
"custom_components.mail_and_packages.async_setup_entry",
return_value=True,
) as mock_setup_entry:

result2 = await hass.config_entries.flow.async_configure(
result["flow_id"], input_1
)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ async def test_image_filename_oserr(
assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()

assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 43
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 45
assert "Problem accessing file:" in caplog.text


Expand Down Expand Up @@ -446,7 +446,7 @@ async def test_image_getctime_oserr(
assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()

assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 43
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 45
assert "Problem accessing file:" in caplog.text


Expand Down
6 changes: 3 additions & 3 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ async def test_unload_entry(hass, mock_update, mock_copy_overlays):
assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()

assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 43
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 45
entries = hass.config_entries.async_entries(DOMAIN)
assert len(entries) == 1

assert await hass.config_entries.async_unload(entries[0].entry_id)
await hass.async_block_till_done()
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 43
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 45
assert len(hass.states.async_entity_ids(DOMAIN)) == 0

assert await hass.config_entries.async_remove(entries[0].entry_id)
Expand Down Expand Up @@ -67,7 +67,7 @@ async def test_setup_entry(
assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()

assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 43
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 45
entries = hass.config_entries.async_entries(DOMAIN)
assert len(entries) == 1

Expand Down
1 change: 0 additions & 1 deletion tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

@pytest.mark.asyncio
async def test_sensor(hass, mock_update):

entry = MockConfigEntry(
domain=DOMAIN,
title="imap.test.email",
Expand Down

0 comments on commit 024d520

Please sign in to comment.