mirror of
https://github.com/home-assistant/core.git
synced 2025-08-11 06:20:01 +00:00
.devcontainer
.github
.vscode
docs
homeassistant
machine
pylint
rootfs
script
tests
auth
backports
components
fixtures
hassfest
helpers
__init__.py
test_aiohttp_client.py
test_area_registry.py
test_check_config.py
test_collection.py
test_condition.py
test_config_entry_flow.py
test_config_entry_oauth2_flow.py
test_config_validation.py
test_debounce.py
test_deprecation.py
test_device_registry.py
test_discovery.py
test_discovery_flow.py
test_dispatcher.py
test_entity.py
test_entity_component.py
test_entity_platform.py
test_entity_registry.py
test_entity_values.py
test_entityfilter.py
test_event.py
test_frame.py
test_helper_config_entry_flow.py
test_httpx_client.py
test_icon.py
test_init.py
test_instance_id.py
test_integration_platform.py
test_intent.py
test_json.py
test_location.py
test_network.py
test_ratelimit.py
test_recorder.py
test_reload.py
test_restore_state.py
test_script.py
test_script_variables.py
test_selector.py
test_service.py
test_significant_change.py
test_singleton.py
test_start.py
test_state.py
test_storage.py
test_storage_remove.py
test_sun.py
test_system_info.py
test_temperature.py
test_template.py
test_translation.py
test_trigger.py
test_update_coordinator.py
mock
pylint
resources
scripts
test_util
testing_config
util
__init__.py
bandit.yaml
common.py
conftest.py
ignore_uncaught_exceptions.py
test_bootstrap.py
test_config.py
test_config_entries.py
test_core.py
test_data_entry_flow.py
test_exceptions.py
test_loader.py
test_main.py
test_requirements.py
test_runner.py
test_setup.py
test_test_fixtures.py
.core_files.yaml
.coveragerc
.dockerignore
.gitattributes
.gitignore
.hadolint.yaml
.ignore
.pre-commit-config.yaml
.prettierignore
.readthedocs.yml
.strict-typing
.yamllint
CLA.md
CODEOWNERS
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Dockerfile
Dockerfile.dev
LICENSE.md
MANIFEST.in
README.rst
build.yaml
codecov.yml
mypy.ini
pyproject.toml
requirements.txt
requirements_all.txt
requirements_docs.txt
requirements_test.txt
requirements_test_all.txt
requirements_test_pre_commit.txt
setup.cfg
tox.ini
37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
"""Tests for the storage helper with minimal mocking."""
|
|
import asyncio
|
|
from datetime import timedelta
|
|
import os
|
|
from unittest.mock import patch
|
|
|
|
from homeassistant.helpers import storage
|
|
from homeassistant.util import dt
|
|
|
|
from tests.common import async_fire_time_changed, async_test_home_assistant
|
|
|
|
|
|
async def test_removing_while_delay_in_progress(tmpdir):
|
|
"""Test removing while delay in progress."""
|
|
|
|
loop = asyncio.get_event_loop()
|
|
hass = await async_test_home_assistant(loop)
|
|
|
|
test_dir = await hass.async_add_executor_job(tmpdir.mkdir, "storage")
|
|
|
|
with patch.object(storage, "STORAGE_DIR", test_dir):
|
|
real_store = storage.Store(hass, 1, "remove_me")
|
|
|
|
await real_store.async_save({"delay": "no"})
|
|
|
|
assert await hass.async_add_executor_job(os.path.exists, real_store.path)
|
|
|
|
real_store.async_delay_save(lambda: {"delay": "yes"}, 1)
|
|
|
|
await real_store.async_remove()
|
|
assert not await hass.async_add_executor_job(os.path.exists, real_store.path)
|
|
|
|
async_fire_time_changed(hass, dt.utcnow() + timedelta(seconds=1))
|
|
await hass.async_block_till_done()
|
|
assert not await hass.async_add_executor_job(os.path.exists, real_store.path)
|
|
await hass.async_stop()
|