Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
HomeAssistant
Core
Commits
713abf4c
Unverified
Commit
713abf4c
authored
9 months ago
by
epenet
Committed by
GitHub
9 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Refactor PLATFORM_SCHEMA imports in tests (#120566)
parent
32c07180
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_setup.py
+13
-15
13 additions, 15 deletions
tests/test_setup.py
with
13 additions
and
15 deletions
tests/test_setup.py
+
13
−
15
View file @
713abf4c
...
...
@@ -12,11 +12,7 @@ from homeassistant import config_entries, loader, setup
from
homeassistant.const
import
EVENT_COMPONENT_LOADED
,
EVENT_HOMEASSISTANT_START
from
homeassistant.core
import
CoreState
,
HomeAssistant
,
callback
from
homeassistant.exceptions
import
HomeAssistantError
from
homeassistant.helpers
import
discovery
,
translation
from
homeassistant.helpers.config_validation
import
(
PLATFORM_SCHEMA
,
PLATFORM_SCHEMA_BASE
,
)
from
homeassistant.helpers
import
config_validation
as
cv
,
discovery
,
translation
from
homeassistant.helpers.dispatcher
import
(
async_dispatcher_connect
,
async_dispatcher_send
,
...
...
@@ -88,8 +84,8 @@ async def test_validate_platform_config(
hass
:
HomeAssistant
,
caplog
:
pytest
.
LogCaptureFixture
)
->
None
:
"""
Test validating platform configuration.
"""
platform_schema
=
PLATFORM_SCHEMA
.
extend
({
"
hello
"
:
str
})
platform_schema_base
=
PLATFORM_SCHEMA_BASE
.
extend
({})
platform_schema
=
cv
.
PLATFORM_SCHEMA
.
extend
({
"
hello
"
:
str
})
platform_schema_base
=
cv
.
PLATFORM_SCHEMA_BASE
.
extend
({})
mock_integration
(
hass
,
MockModule
(
"
platform_conf
"
,
platform_schema_base
=
platform_schema_base
),
...
...
@@ -149,8 +145,8 @@ async def test_validate_platform_config_2(
hass
:
HomeAssistant
,
caplog
:
pytest
.
LogCaptureFixture
)
->
None
:
"""
Test component PLATFORM_SCHEMA_BASE prio over PLATFORM_SCHEMA.
"""
platform_schema
=
PLATFORM_SCHEMA
.
extend
({
"
hello
"
:
str
})
platform_schema_base
=
PLATFORM_SCHEMA_BASE
.
extend
({
"
hello
"
:
"
world
"
})
platform_schema
=
cv
.
PLATFORM_SCHEMA
.
extend
({
"
hello
"
:
str
})
platform_schema_base
=
cv
.
PLATFORM_SCHEMA_BASE
.
extend
({
"
hello
"
:
"
world
"
})
mock_integration
(
hass
,
MockModule
(
...
...
@@ -183,8 +179,8 @@ async def test_validate_platform_config_3(
hass
:
HomeAssistant
,
caplog
:
pytest
.
LogCaptureFixture
)
->
None
:
"""
Test fallback to component PLATFORM_SCHEMA.
"""
component_schema
=
PLATFORM_SCHEMA_BASE
.
extend
({
"
hello
"
:
str
})
platform_schema
=
PLATFORM_SCHEMA
.
extend
({
"
cheers
"
:
str
,
"
hello
"
:
"
world
"
})
component_schema
=
cv
.
PLATFORM_SCHEMA_BASE
.
extend
({
"
hello
"
:
str
})
platform_schema
=
cv
.
PLATFORM_SCHEMA
.
extend
({
"
cheers
"
:
str
,
"
hello
"
:
"
world
"
})
mock_integration
(
hass
,
MockModule
(
"
platform_conf
"
,
platform_schema
=
component_schema
)
)
...
...
@@ -210,8 +206,8 @@ async def test_validate_platform_config_3(
async
def
test_validate_platform_config_4
(
hass
:
HomeAssistant
)
->
None
:
"""
Test entity_namespace in PLATFORM_SCHEMA.
"""
component_schema
=
PLATFORM_SCHEMA_BASE
platform_schema
=
PLATFORM_SCHEMA
component_schema
=
cv
.
PLATFORM_SCHEMA_BASE
platform_schema
=
cv
.
PLATFORM_SCHEMA
mock_integration
(
hass
,
MockModule
(
"
platform_conf
"
,
platform_schema_base
=
component_schema
),
...
...
@@ -386,7 +382,9 @@ async def test_component_setup_with_validation_and_dependency(
async
def
test_platform_specific_config_validation
(
hass
:
HomeAssistant
)
->
None
:
"""
Test platform that specifies config.
"""
platform_schema
=
PLATFORM_SCHEMA
.
extend
({
"
valid
"
:
True
},
extra
=
vol
.
PREVENT_EXTRA
)
platform_schema
=
cv
.
PLATFORM_SCHEMA
.
extend
(
{
"
valid
"
:
True
},
extra
=
vol
.
PREVENT_EXTRA
)
mock_setup
=
Mock
(
spec_set
=
True
)
...
...
@@ -533,7 +531,7 @@ async def test_component_warn_slow_setup(hass: HomeAssistant) -> None:
async
def
test_platform_no_warn_slow
(
hass
:
HomeAssistant
)
->
None
:
"""
Do not warn for long entity setup time.
"""
mock_integration
(
hass
,
MockModule
(
"
test_component1
"
,
platform_schema
=
PLATFORM_SCHEMA
)
hass
,
MockModule
(
"
test_component1
"
,
platform_schema
=
cv
.
PLATFORM_SCHEMA
)
)
with
patch
.
object
(
hass
.
loop
,
"
call_later
"
)
as
mock_call
:
result
=
await
setup
.
async_setup_component
(
hass
,
"
test_component1
"
,
{})
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment