hass-core/tests/components/demo/test_init.py
Rohan Kapoor 6ba9ccf052 Load requirements and dependencies from manifests. Fallback to current REQUIREMENTS and DEPENDENCIES (#22717)
* Load dependencies from manifests. Fallback to current DEPENDENCIES

* Fix typing

* Ignore typing correctly

* Split out dependency processing to a new method

* Fix tests

* Only pull from manifest if dependencies is non empty

* Inline temporary function

* Fix light tests [skip ci]

* Fix tests/common

* Fix some mqtt tests [skip ci]

* Fix tests and component manifests which have only one platform

* Fix rflink tests

* Fix more tests and manifests

* Readability over shorthand format

* Fix demo/notify tests

* Load dependencies from manifests. Fallback to current DEPENDENCIES

* Load requirements from manifests. Fallback to current REQUIREMENTS

* Fix typing

* Ignore typing correctly

* Split out dependency processing to a new method

* Only pull from manifest if dependencies is non empty

* Inline temporary function

* Fix tests and component manifests which have only one platform

* Fix rflink tests

* Readability over shorthand format

* Clean up requirements

* Use integration to resolve deps/reqs

* Lint

* Lint

* revert a change

* Revert a test change

* Fix types

* Fix types

* Add back cache for load component

* Fix test_component_not_found

* Move light.test and device_tracker.test into test package instead with manifest to fix tests

* Fix broken device_tracker tests

* Add docstrings to __init__

* Fix all of the light tests that I broke earlier

* Embed the test.switch platform to fix other tests

* Embed and fix the test.imagimage_processing platform

* Fix tests for nx584

* Add dependencies from platform file's DEPENDENCIES

* Try to setup component when entity_platform is setting up

Fix tests in helpers folder

* Rewrite test_setup

* Simplify

* Lint

* Disable demo component if running in test

Temp workaround to unblock CI tests

* Skip demo tests

* Fix config entry test

* Fix repeat test

* Clarify doc

* One extra guard

* Fix import

* Lint

* Workaround google tts
2019-04-11 01:26:36 -07:00

71 lines
1.9 KiB
Python

"""The tests for the Demo component."""
import asyncio
import json
import os
import pytest
from homeassistant.setup import async_setup_component
from homeassistant.components import demo, device_tracker
from homeassistant.helpers.json import JSONEncoder
@pytest.fixture(autouse=True)
def mock_history(hass):
"""Mock history component loaded."""
hass.config.components.add('history')
@pytest.fixture
def minimize_demo_platforms(hass):
"""Cleanup demo component for tests."""
orig = demo.COMPONENTS_WITH_DEMO_PLATFORM
demo.COMPONENTS_WITH_DEMO_PLATFORM = [
'switch', 'light', 'media_player']
yield
demo.COMPONENTS_WITH_DEMO_PLATFORM = orig
@pytest.fixture(autouse=True)
def demo_cleanup(hass):
"""Clean up device tracker demo file."""
yield
try:
os.remove(hass.config.path(device_tracker.YAML_DEVICES))
except FileNotFoundError:
pass
@pytest.mark.skip
@asyncio.coroutine
def test_if_demo_state_shows_by_default(hass, minimize_demo_platforms):
"""Test if demo state shows if we give no configuration."""
yield from async_setup_component(hass, demo.DOMAIN, {demo.DOMAIN: {}})
assert hass.states.get('a.Demo_Mode') is not None
@pytest.mark.skip
@asyncio.coroutine
def test_hiding_demo_state(hass, minimize_demo_platforms):
"""Test if you can hide the demo card."""
yield from async_setup_component(hass, demo.DOMAIN, {
demo.DOMAIN: {'hide_demo_state': 1}})
assert hass.states.get('a.Demo_Mode') is None
@pytest.mark.skip
@asyncio.coroutine
def test_all_entities_can_be_loaded_over_json(hass):
"""Test if you can hide the demo card."""
yield from async_setup_component(hass, demo.DOMAIN, {
demo.DOMAIN: {'hide_demo_state': 1}})
try:
json.dumps(hass.states.async_all(), cls=JSONEncoder)
except Exception:
pytest.fail('Unable to convert all demo entities to JSON. '
'Wrong data in state machine!')