Split up yaml loaders into multiple files (#23774)

* Start moving parts of yaml utils to own module

Move parts of yaml loader out of the single large file and start
to create the structure of the yaml loaders in Ansible [0].

[0]: https://github.com/ansible/ansible/tree/devel/lib/ansible/parsing/yaml

* Finish yaml migration, update tests and mocks

  * Move code around to finish the migration
  * Update the mocks so that `open` is patched in
    `homeassistant.util.yaml.loader` instead of
    `homeassistant.util.yaml`.
  * Updated mypy ignores
  * Updated external API of `homeasistant.util.yaml`, see below:

Checked what part of the api of `homeassistant.util.yaml` was actually
called from outside the tests and added an `__ALL__` that contains only
these elements.

Updated the tests so that references to internal parts of the API (e.g.
the yaml module imported into `homeassistant.util.yaml.loader`) are
referenced directly from `homeassistant.util.yaml.loader`.

In `tests/test_yaml.py` the import `yaml` refers to
`homeassistant.util.yaml` and `yaml_loader` refers to `~.loader`.

Future work that remains for the next iteration is to create a custom
SafeConstructor and refers to that instead of monkey patching `yaml` with
custom loaders.

* Update mocks in yaml dumper, check_config
This commit is contained in:
Ties de Kock 2019-05-09 09:07:56 -07:00 committed by Paulus Schoutsen
parent 118d3bc11c
commit 4004867eda
11 changed files with 179 additions and 139 deletions

View file

@ -15,7 +15,8 @@ from io import StringIO
from unittest.mock import MagicMock, Mock, patch
import homeassistant.util.dt as date_util
import homeassistant.util.yaml as yaml
import homeassistant.util.yaml.loader as yaml_loader
import homeassistant.util.yaml.dumper as yaml_dumper
from homeassistant import auth, config_entries, core as ha, loader
from homeassistant.auth import (
@ -680,7 +681,8 @@ def patch_yaml_files(files_dict, endswith=True):
# Not found
raise FileNotFoundError("File not found: {}".format(fname))
return patch.object(yaml, 'open', mock_open_f, create=True)
return patch.object(yaml_loader, 'open', mock_open_f, create=True)
return patch.object(yaml_dumper, 'open', mock_open_f, create=True)
def mock_coro(return_value=None, exception=None):