1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-25 05:26:47 +00:00

Replacing tempfile with mock_open in tests (#3753)

- test_bootstrap.py
- test_config.py
- components/test_init.py
- components/test_panel_custom.py
- components/test_api.py
- components/notify/test_file.py
- components/notify/test_demo.py
- components/camera/test_local_file.py
- helpers/test_config_validation.py
- util/test_package.py
- util/test_yaml.py

No changes needed in:
- components/cover/test_command_line.py
- components/switch/test_command_line.py
- components/rollershutter/test_command_line.py
- components/test_shell_command.py
- components/notify/test_command_line.py

Misc changes in:
- components/mqtt/test_server.py

Also, removed some unused mock parameters in tests/components/mqtt/test_server.py.
This commit is contained in:
Rob Capellini
2016-10-17 23:16:36 -04:00
committed by Paulus Schoutsen
parent 7d67017de7
commit 272539105f
12 changed files with 403 additions and 335 deletions

View File

@@ -1,12 +1,10 @@
"""The tests for the notify demo platform."""
import tempfile
import unittest
from homeassistant.bootstrap import setup_component
import homeassistant.components.notify as notify
from homeassistant.components.notify import demo
from homeassistant.helpers import script
from homeassistant.util import yaml
from tests.common import get_test_home_assistant
@@ -70,21 +68,18 @@ class TestNotifyDemo(unittest.TestCase):
def test_calling_notify_from_script_loaded_from_yaml_without_title(self):
"""Test if we can call a notify from a script."""
yaml_conf = """
service: notify.notify
data:
data:
push:
sound: US-EN-Morgan-Freeman-Roommate-Is-Arriving.wav
data_template:
message: >
Test 123 {{ 2 + 2 }}
"""
with tempfile.NamedTemporaryFile() as fp:
fp.write(yaml_conf.encode('utf-8'))
fp.flush()
conf = yaml.load_yaml(fp.name)
conf = {
'service': 'notify.notify',
'data': {
'data': {
'push': {
'sound':
'US-EN-Morgan-Freeman-Roommate-Is-Arriving.wav'
}
}
},
'data_template': {'message': 'Test 123 {{ 2 + 2 }}\n'},
}
script.call_from_config(self.hass, conf)
self.hass.block_till_done()
@@ -99,22 +94,21 @@ data_template:
def test_calling_notify_from_script_loaded_from_yaml_with_title(self):
"""Test if we can call a notify from a script."""
yaml_conf = """
service: notify.notify
data:
data:
push:
sound: US-EN-Morgan-Freeman-Roommate-Is-Arriving.wav
data_template:
title: Test
message: >
Test 123 {{ 2 + 2 }}
"""
with tempfile.NamedTemporaryFile() as fp:
fp.write(yaml_conf.encode('utf-8'))
fp.flush()
conf = yaml.load_yaml(fp.name)
conf = {
'service': 'notify.notify',
'data': {
'data': {
'push': {
'sound':
'US-EN-Morgan-Freeman-Roommate-Is-Arriving.wav'
}
}
},
'data_template': {
'message': 'Test 123 {{ 2 + 2 }}\n',
'title': 'Test'
}
}
script.call_from_config(self.hass, conf)
self.hass.pool.block_till_done()