Skip to content

Commit

Permalink
Check and fix test suite leaving files behind (home-assistant#25981)
Browse files Browse the repository at this point in the history
* azure: run check_dirty at end of tests

* Fix ps4 media player tests to not write to files

* .gitignore coverage.xml and test-results.xml
  • Loading branch information
scop authored Aug 21, 2019
1 parent e033e46 commit 9b1315d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ pip-log.txt
# Unit test / coverage reports
.coverage
.tox
coverage.xml
nosetests.xml
htmlcov/
test-reports/
test-results.xml

# Translations
*.mo
Expand Down
2 changes: 2 additions & 0 deletions azure-pipelines-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ stages:
- script: |
. venv/bin/activate
pytest --timeout=9 --durations=10 --junitxml=test-results.xml -qq -o console_output_style=count -p no:sugar tests
script/check_dirty
displayName: 'Run pytest for python $(python.container)'
condition: and(succeeded(), ne(variables['python.container'], variables['PythonMain']))
- script: |
Expand All @@ -122,6 +123,7 @@ stages:
. venv/bin/activate
pytest --timeout=9 --durations=10 --junitxml=test-results.xml --cov --cov-report=xml -qq -o console_output_style=count -p no:sugar tests
codecov --token $(codecovToken)
script/check_dirty
displayName: 'Run pytest for python $(python.container) / coverage'
condition: and(succeeded(), eq(variables['python.container'], variables['PythonMain']))
- task: PublishTestResults@2
Expand Down
47 changes: 34 additions & 13 deletions tests/components/ps4/test_media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ async def test_state_off_is_set(hass):
"""Test that state is set to off."""
mock_entity_id = await setup_mock_component(hass)

await mock_ddp_response(hass, MOCK_STATUS_OFF)
with patch(MOCK_SAVE, side_effect=MagicMock()):
await mock_ddp_response(hass, MOCK_STATUS_OFF)

assert hass.states.get(mock_entity_id).state == STATE_OFF

Expand All @@ -217,7 +218,8 @@ async def test_state_idle_is_set(hass):
"""Test that state is set to idle."""
mock_entity_id = await setup_mock_component(hass)

await mock_ddp_response(hass, MOCK_STATUS_IDLE)
with patch(MOCK_SAVE, side_effect=MagicMock()):
await mock_ddp_response(hass, MOCK_STATUS_IDLE)

assert hass.states.get(mock_entity_id).state == STATE_IDLE

Expand Down Expand Up @@ -246,7 +248,6 @@ async def test_media_attributes_are_fetched(hass):
with patch(mock_func, return_value=mock_coro(mock_result)) as mock_fetch, patch(
MOCK_SAVE, side_effect=MagicMock()
):

await mock_ddp_response(hass, MOCK_STATUS_PLAYING)

mock_state = hass.states.get(mock_entity_id)
Expand All @@ -271,7 +272,9 @@ async def test_media_attributes_are_loaded(hass):
"pyps4.Ps4Async.async_get_ps_store_data",
)

with patch(mock_func, return_value=mock_coro(None)) as mock_fetch:
with patch(mock_func, return_value=mock_coro(None)) as mock_fetch, patch(
MOCK_SAVE, side_effect=MagicMock()
):
await mock_ddp_response(hass, MOCK_STATUS_PLAYING, mock_data)

mock_state = hass.states.get(mock_entity_id)
Expand All @@ -292,7 +295,9 @@ async def test_media_attributes_are_loaded(hass):
async def test_device_info_is_set_from_status_correctly(hass):
"""Test that device info is set correctly from status update."""
mock_d_registry = mock_device_registry(hass)
with patch("pyps4_homeassistant.ps4.get_status", return_value=MOCK_STATUS_OFF):
with patch(
"pyps4_homeassistant.ps4.get_status", return_value=MOCK_STATUS_OFF
), patch(MOCK_SAVE, side_effect=MagicMock()):
mock_entity_id = await setup_mock_component(hass)

await hass.async_block_till_done()
Expand Down Expand Up @@ -374,7 +379,9 @@ async def test_turn_on(hass):
"homeassistant.components.ps4.media_player.", "pyps4.Ps4Async.wakeup"
)

with patch(mock_func, return_value=MagicMock()) as mock_call:
with patch(mock_func, return_value=MagicMock()) as mock_call, patch(
MOCK_SAVE, side_effect=MagicMock()
):
await hass.services.async_call(
"media_player", "turn_on", {ATTR_ENTITY_ID: mock_entity_id}
)
Expand All @@ -390,7 +397,9 @@ async def test_turn_off(hass):
"homeassistant.components.ps4.media_player.", "pyps4.Ps4Async.standby"
)

with patch(mock_func, return_value=MagicMock()) as mock_call:
with patch(mock_func, return_value=MagicMock()) as mock_call, patch(
MOCK_SAVE, side_effect=MagicMock()
):
await hass.services.async_call(
"media_player", "turn_off", {ATTR_ENTITY_ID: mock_entity_id}
)
Expand All @@ -406,7 +415,9 @@ async def test_media_pause(hass):
"homeassistant.components.ps4.media_player.", "pyps4.Ps4Async.remote_control"
)

with patch(mock_func, return_value=MagicMock()) as mock_call:
with patch(mock_func, return_value=MagicMock()) as mock_call, patch(
MOCK_SAVE, side_effect=MagicMock()
):
await hass.services.async_call(
"media_player", "media_pause", {ATTR_ENTITY_ID: mock_entity_id}
)
Expand All @@ -422,7 +433,9 @@ async def test_media_stop(hass):
"homeassistant.components.ps4.media_player.", "pyps4.Ps4Async.remote_control"
)

with patch(mock_func, return_value=MagicMock()) as mock_call:
with patch(mock_func, return_value=MagicMock()) as mock_call, patch(
MOCK_SAVE, side_effect=MagicMock()
):
await hass.services.async_call(
"media_player", "media_stop", {ATTR_ENTITY_ID: mock_entity_id}
)
Expand All @@ -443,7 +456,9 @@ async def test_select_source(hass):
"homeassistant.components.ps4.media_player.", "pyps4.Ps4Async.start_title"
)

with patch(mock_func, return_value=MagicMock()) as mock_call:
with patch(mock_func, return_value=MagicMock()) as mock_call, patch(
MOCK_SAVE, side_effect=MagicMock()
):
# Test with title name.
await hass.services.async_call(
"media_player",
Expand All @@ -467,7 +482,9 @@ async def test_select_source_caps(hass):
"homeassistant.components.ps4.media_player.", "pyps4.Ps4Async.start_title"
)

with patch(mock_func, return_value=MagicMock()) as mock_call:
with patch(mock_func, return_value=MagicMock()) as mock_call, patch(
MOCK_SAVE, side_effect=MagicMock()
):
# Test with title name in caps.
await hass.services.async_call(
"media_player",
Expand All @@ -494,7 +511,9 @@ async def test_select_source_id(hass):
"homeassistant.components.ps4.media_player.", "pyps4.Ps4Async.start_title"
)

with patch(mock_func, return_value=MagicMock()) as mock_call:
with patch(mock_func, return_value=MagicMock()) as mock_call, patch(
MOCK_SAVE, side_effect=MagicMock()
):
# Test with title ID.
await hass.services.async_call(
"media_player",
Expand All @@ -513,7 +532,9 @@ async def test_ps4_send_command(hass):
"homeassistant.components.ps4.media_player.", "pyps4.Ps4Async.remote_control"
)

with patch(mock_func, return_value=MagicMock()) as mock_call:
with patch(mock_func, return_value=MagicMock()) as mock_call, patch(
MOCK_SAVE, side_effect=MagicMock()
):
await hass.services.async_call(
DOMAIN, "send_command", {ATTR_ENTITY_ID: mock_entity_id, ATTR_COMMAND: "ps"}
)
Expand Down

0 comments on commit 9b1315d

Please sign in to comment.