1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Catch UnicodeDecodeError Error (#4007)

* Catch UnicodeDecodeError Error 

Error for #3933

* Forgot (exc)

* catch...

* Tests by @lwis

* Docstring

* Create open
This commit is contained in:
Johann Kellerman
2016-10-24 03:55:06 +02:00
committed by Paulus Schoutsen
parent 1f89e6ddba
commit 5df8477536
2 changed files with 10 additions and 4 deletions

View File

@@ -95,7 +95,6 @@ class TestYaml(unittest.TestCase):
mock_walk.return_value = [
['/tmp', ['tmp2', '.ignore', 'ignore'], ['zero.yaml']],
['/tmp/tmp2', [], ['one.yaml', 'two.yaml']],
['/tmp/.ignore', [], []],
['/tmp/ignore', [], ['.ignore.yaml']]
]
@@ -136,7 +135,6 @@ class TestYaml(unittest.TestCase):
mock_walk.return_value = [
['/tmp', ['tmp2', '.ignore', 'ignore'], ['first.yaml']],
['/tmp/tmp2', [], ['second.yaml', 'third.yaml']],
['/tmp/.ignore', [], []],
['/tmp/ignore', [], ['.ignore.yaml']]
]
@@ -175,7 +173,6 @@ class TestYaml(unittest.TestCase):
mock_walk.return_value = [
['/tmp', ['tmp2', '.ignore', 'ignore'], ['first.yaml']],
['/tmp/tmp2', [], ['second.yaml', 'third.yaml']],
['/tmp/.ignore', [], []],
['/tmp/ignore', [], ['.ignore.yaml']]
]
@@ -218,7 +215,6 @@ class TestYaml(unittest.TestCase):
mock_walk.return_value = [
['/tmp', ['tmp2', '.ignore', 'ignore'], ['first.yaml']],
['/tmp/tmp2', [], ['second.yaml', 'third.yaml']],
['/tmp/.ignore', [], []],
['/tmp/ignore', [], ['.ignore.yaml']]
]
@@ -241,6 +237,13 @@ class TestYaml(unittest.TestCase):
"key4": "four"
}
@patch('homeassistant.util.yaml.open', create=True)
def test_load_yaml_encoding_error(self, mock_open):
"""Test raising a UnicodeDecodeError."""
mock_open.side_effect = UnicodeDecodeError('', b'', 1, 0, '')
self.assertRaises(HomeAssistantError, yaml.load_yaml, 'test')
FILES = {}