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
0534b0de
Unverified
Commit
0534b0de
authored
1 year ago
by
Erik Montnemery
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Improve entity tests (#106175)
parent
39a956ce
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/helpers/test_entity.py
+23
-34
23 additions, 34 deletions
tests/helpers/test_entity.py
with
23 additions
and
34 deletions
tests/helpers/test_entity.py
+
23
−
34
View file @
0534b0de
...
@@ -31,7 +31,6 @@ from tests.common import (
...
@@ -31,7 +31,6 @@ from tests.common import (
MockEntityPlatform
,
MockEntityPlatform
,
MockModule
,
MockModule
,
MockPlatform
,
MockPlatform
,
get_test_home_assistant
,
mock_integration
,
mock_integration
,
mock_registry
,
mock_registry
,
)
)
...
@@ -61,6 +60,17 @@ def test_generate_entity_id_given_keys() -> None:
...
@@ -61,6 +60,17 @@ def test_generate_entity_id_given_keys() -> None:
)
)
async
def
test_generate_entity_id_given_hass
(
hass
:
HomeAssistant
)
->
None
:
"""
Test generating an entity id given hass object.
"""
hass
.
states
.
async_set
(
"
test.overwrite_hidden_true
"
,
"
test
"
)
fmt
=
"
test.{}
"
assert
(
entity
.
generate_entity_id
(
fmt
,
"
overwrite hidden true
"
,
hass
=
hass
)
==
"
test.overwrite_hidden_true_2
"
)
async
def
test_async_update_support
(
hass
:
HomeAssistant
)
->
None
:
async
def
test_async_update_support
(
hass
:
HomeAssistant
)
->
None
:
"""
Test async update getting called.
"""
"""
Test async update getting called.
"""
sync_update
=
[]
sync_update
=
[]
...
@@ -95,40 +105,19 @@ async def test_async_update_support(hass: HomeAssistant) -> None:
...
@@ -95,40 +105,19 @@ async def test_async_update_support(hass: HomeAssistant) -> None:
assert
len
(
async_update
)
==
1
assert
len
(
async_update
)
==
1
class
TestHelpersEntity
:
async
def
test_device_class
(
hass
:
HomeAssistant
)
->
None
:
"""
Test homeassistant.helpers.entity module.
"""
"""
Test device class attribute.
"""
ent
=
entity
.
Entity
()
def
setup_method
(
self
,
method
):
ent
.
entity_id
=
"
test.overwrite_hidden_true
"
"""
Set up things to be run when tests are started.
"""
ent
.
hass
=
hass
self
.
entity
=
entity
.
Entity
()
ent
.
async_write_ha_state
()
self
.
entity
.
entity_id
=
"
test.overwrite_hidden_true
"
state
=
hass
.
states
.
get
(
ent
.
entity_id
)
self
.
hass
=
self
.
entity
.
hass
=
get_test_home_assistant
()
assert
state
.
attributes
.
get
(
ATTR_DEVICE_CLASS
)
is
None
self
.
entity
.
schedule_update_ha_state
()
self
.
hass
.
block_till_done
()
def
teardown_method
(
self
,
method
):
"""
Stop everything that was started.
"""
self
.
hass
.
stop
()
def
test_generate_entity_id_given_hass
(
self
):
"""
Test generating an entity id given hass object.
"""
fmt
=
"
test.{}
"
assert
(
entity
.
generate_entity_id
(
fmt
,
"
overwrite hidden true
"
,
hass
=
self
.
hass
)
==
"
test.overwrite_hidden_true_2
"
)
def
test_device_class
(
self
):
ent
.
_attr_device_class
=
"
test_class
"
"""
Test device class attribute.
"""
ent
.
async_write_ha_state
()
state
=
self
.
hass
.
states
.
get
(
self
.
entity
.
entity_id
)
state
=
hass
.
states
.
get
(
ent
.
entity_id
)
assert
state
.
attributes
.
get
(
ATTR_DEVICE_CLASS
)
is
None
assert
state
.
attributes
.
get
(
ATTR_DEVICE_CLASS
)
==
"
test_class
"
with
patch
(
"
homeassistant.helpers.entity.Entity.device_class
"
,
new
=
"
test_class
"
):
self
.
entity
.
schedule_update_ha_state
()
self
.
hass
.
block_till_done
()
state
=
self
.
hass
.
states
.
get
(
self
.
entity
.
entity_id
)
assert
state
.
attributes
.
get
(
ATTR_DEVICE_CLASS
)
==
"
test_class
"
async
def
test_warn_slow_update
(
async
def
test_warn_slow_update
(
...
...
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