fix: Use anyio for file operations in a few places (#5167)

Use anyio for file operations in a few places
This commit is contained in:
Christophe Bornet 2024-12-10 02:55:42 +01:00 • committed by GitHub
commit e545d12c40
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 36 additions and 30 deletions

View file

@ -10,6 +10,7 @@ from pathlib import Path
from typing import TYPE_CHECKING
from uuid import UUID
import anyio
import orjson
import pytest
from asgi_lifespan import LifespanManager
@ -365,7 +366,7 @@ async def client_fixture(
monkeypatch.undo()
# clear the temp db
with suppress(FileNotFoundError):
db_path.unlink()
await anyio.Path(db_path).unlink()
# create a fixture for session_getter above

View file

@ -7,6 +7,7 @@ from io import BytesIO
from pathlib import Path
from unittest.mock import MagicMock
import anyio
import pytest
from asgi_lifespan import LifespanManager
from httpx import ASGITransport, AsyncClient
@ -76,7 +77,7 @@ async def files_client_fixture(
monkeypatch.undo()
# clear the temp db
with suppress(FileNotFoundError):
db_path.unlink()
await anyio.Path(db_path).unlink()
@pytest.fixture

View file

@ -2,6 +2,7 @@ import asyncio
from datetime import datetime
from pathlib import Path
import anyio
import pytest
from langflow.custom.directory_reader.utils import abuild_custom_component_list_from_path
from langflow.initial_setup.constants import STARTER_FOLDER_NAME
@ -132,7 +133,7 @@ def add_edge(source, target, from_output, to_input):
async def test_refresh_starter_projects():
data_path = str(Path(__file__).parent.parent.parent.absolute() / "base" / "langflow" / "components")
data_path = str(await anyio.Path(__file__).parent.parent.parent.absolute() / "base" / "langflow" / "components")
components = await abuild_custom_component_list_from_path(data_path)
chat_input = find_component_by_name(components, "ChatInput")

View file

@ -1,6 +1,6 @@
import tempfile
from pathlib import Path
import anyio
import pytest
@ -18,21 +18,21 @@ async def test_webhook_endpoint(client, added_webhook_test):
endpoint = f"api/v1/webhook/{endpoint_name}"
# Create a temporary file
with tempfile.TemporaryDirectory() as tmp:
file_path = Path(tmp) / "test_file.txt"
file_path = anyio.Path(tmp) / "test_file.txt"
payload = {"path": str(file_path)}
response = await client.post(endpoint, json=payload)
assert response.status_code == 202
assert file_path.exists()
assert await file_path.exists()
assert not file_path.exists()
assert not await file_path.exists()
# Send an invalid payload
payload = {"invalid_key": "invalid_value"}
response = await client.post(endpoint, json=payload)
assert response.status_code == 202
assert not file_path.exists()
assert not await file_path.exists()
async def test_webhook_flow_on_run_endpoint(client, added_webhook_test, created_api_key):