mirror of
https://github.com/home-assistant/core.git
synced 2026-09-25 07:51:46 -05:00
Fix backup test ResourceWarnings (#168180)
This commit is contained in:
@@ -319,9 +319,9 @@ async def test_decrypted_backup_streamer(
|
||||
expected_padding = b"\0" * padding_size
|
||||
|
||||
async def send_backup() -> AsyncIterator[bytes]:
|
||||
f = encrypted_backup_path.open("rb")
|
||||
while chunk := f.read(1024):
|
||||
yield chunk
|
||||
with encrypted_backup_path.open("rb") as f:
|
||||
while chunk := f.read(1024):
|
||||
yield chunk
|
||||
|
||||
async def open_backup() -> AsyncIterator[bytes]:
|
||||
return send_backup()
|
||||
@@ -367,10 +367,10 @@ async def test_decrypted_backup_streamer_interrupt_stuck_reader(
|
||||
stuck = asyncio.Event()
|
||||
|
||||
async def send_backup() -> AsyncIterator[bytes]:
|
||||
f = encrypted_backup_path.open("rb")
|
||||
while chunk := f.read(1024):
|
||||
await stuck.wait()
|
||||
yield chunk
|
||||
with encrypted_backup_path.open("rb") as f:
|
||||
while chunk := f.read(1024):
|
||||
await stuck.wait()
|
||||
yield chunk
|
||||
|
||||
async def open_backup() -> AsyncIterator[bytes]:
|
||||
return send_backup()
|
||||
@@ -403,9 +403,9 @@ async def test_decrypted_backup_streamer_interrupt_stuck_writer(
|
||||
)
|
||||
|
||||
async def send_backup() -> AsyncIterator[bytes]:
|
||||
f = encrypted_backup_path.open("rb")
|
||||
while chunk := f.read(1024):
|
||||
yield chunk
|
||||
with encrypted_backup_path.open("rb") as f:
|
||||
while chunk := f.read(1024):
|
||||
yield chunk
|
||||
|
||||
async def open_backup() -> AsyncIterator[bytes]:
|
||||
return send_backup()
|
||||
@@ -436,9 +436,9 @@ async def test_decrypted_backup_streamer_wrong_password(hass: HomeAssistant) ->
|
||||
)
|
||||
|
||||
async def send_backup() -> AsyncIterator[bytes]:
|
||||
f = encrypted_backup_path.open("rb")
|
||||
while chunk := f.read(1024):
|
||||
yield chunk
|
||||
with encrypted_backup_path.open("rb") as f:
|
||||
while chunk := f.read(1024):
|
||||
yield chunk
|
||||
|
||||
async def open_backup() -> AsyncIterator[bytes]:
|
||||
return send_backup()
|
||||
@@ -499,9 +499,9 @@ async def test_encrypted_backup_streamer(
|
||||
expected_padding = b"\0" * padding_size
|
||||
|
||||
async def send_backup() -> AsyncIterator[bytes]:
|
||||
f = decrypted_backup_path.open("rb")
|
||||
while chunk := f.read(1024):
|
||||
yield chunk
|
||||
with decrypted_backup_path.open("rb") as f:
|
||||
while chunk := f.read(1024):
|
||||
yield chunk
|
||||
|
||||
async def open_backup() -> AsyncIterator[bytes]:
|
||||
return send_backup()
|
||||
@@ -562,10 +562,10 @@ async def test_encrypted_backup_streamer_interrupt_stuck_reader(
|
||||
stuck = asyncio.Event()
|
||||
|
||||
async def send_backup() -> AsyncIterator[bytes]:
|
||||
f = decrypted_backup_path.open("rb")
|
||||
while chunk := f.read(1024):
|
||||
await stuck.wait()
|
||||
yield chunk
|
||||
with decrypted_backup_path.open("rb") as f:
|
||||
while chunk := f.read(1024):
|
||||
await stuck.wait()
|
||||
yield chunk
|
||||
|
||||
async def open_backup() -> AsyncIterator[bytes]:
|
||||
return send_backup()
|
||||
@@ -600,9 +600,9 @@ async def test_encrypted_backup_streamer_interrupt_stuck_writer(
|
||||
)
|
||||
|
||||
async def send_backup() -> AsyncIterator[bytes]:
|
||||
f = decrypted_backup_path.open("rb")
|
||||
while chunk := f.read(1024):
|
||||
yield chunk
|
||||
with decrypted_backup_path.open("rb") as f:
|
||||
while chunk := f.read(1024):
|
||||
yield chunk
|
||||
|
||||
async def open_backup() -> AsyncIterator[bytes]:
|
||||
return send_backup()
|
||||
@@ -638,9 +638,9 @@ async def test_encrypted_backup_streamer_random_nonce(hass: HomeAssistant) -> No
|
||||
)
|
||||
|
||||
async def send_backup() -> AsyncIterator[bytes]:
|
||||
f = decrypted_backup_path.open("rb")
|
||||
while chunk := f.read(1024):
|
||||
yield chunk
|
||||
with decrypted_backup_path.open("rb") as f:
|
||||
while chunk := f.read(1024):
|
||||
yield chunk
|
||||
|
||||
async def open_backup() -> AsyncIterator[bytes]:
|
||||
return send_backup()
|
||||
@@ -702,9 +702,9 @@ async def test_encrypted_backup_streamer_error(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
async def send_backup() -> AsyncIterator[bytes]:
|
||||
f = decrypted_backup_path.open("rb")
|
||||
while chunk := f.read(1024):
|
||||
yield chunk
|
||||
with decrypted_backup_path.open("rb") as f:
|
||||
while chunk := f.read(1024):
|
||||
yield chunk
|
||||
|
||||
async def open_backup() -> AsyncIterator[bytes]:
|
||||
return send_backup()
|
||||
|
||||
@@ -173,13 +173,13 @@ def test_restoring_backup_that_is_not_a_file(
|
||||
restore_file_path = tmp_path / ".HA_RESTORE"
|
||||
|
||||
# Set up restore file to point to a file within the temporary directory
|
||||
restore_config = json.load(
|
||||
get_fixture_path(f"core/backup_restore/{restore_config}", None).open(
|
||||
"r", encoding="utf-8"
|
||||
restore_config = json.loads(
|
||||
get_fixture_path(f"core/backup_restore/{restore_config}", None).read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
)
|
||||
restore_config["path"] = backup_file_path.as_posix()
|
||||
json.dump(restore_config, restore_file_path.open("w", encoding="utf-8"))
|
||||
restore_file_path.write_text(json.dumps(restore_config), encoding="utf-8")
|
||||
assert restore_file_path.exists()
|
||||
|
||||
# Create a directory at the backup file path to simulate the backup file not being a file
|
||||
@@ -211,13 +211,13 @@ def test_aborting_for_older_versions(restore_config: str, tmp_path: Path) -> Non
|
||||
restore_file_path = tmp_path / ".HA_RESTORE"
|
||||
|
||||
# Set up restore file to point to a file within the temporary directory
|
||||
restore_config = json.load(
|
||||
get_fixture_path(f"core/backup_restore/{restore_config}", None).open(
|
||||
"r", encoding="utf-8"
|
||||
restore_config = json.loads(
|
||||
get_fixture_path(f"core/backup_restore/{restore_config}", None).read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
)
|
||||
restore_config["path"] = backup_file_path.as_posix()
|
||||
json.dump(restore_config, restore_file_path.open("w", encoding="utf-8"))
|
||||
restore_file_path.write_text(json.dumps(restore_config), encoding="utf-8")
|
||||
assert restore_file_path.exists()
|
||||
|
||||
get_fixture_path("core/backup_restore/backup_from_future.tar", None).copy_into(
|
||||
|
||||
Reference in New Issue
Block a user