ref: Add ruff rules for bugbear (B) (#3983)

Add ruff rules for bugbear (B)
This commit is contained in:
Christophe Bornet 2024-10-02 18:55:51 +02:00 • committed by GitHub
commit 7e3d470845
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
86 changed files with 267 additions and 230 deletions

View file

@ -11,6 +11,9 @@ from typing import TYPE_CHECKING
import orjson
import pytest
from loguru import logger
from pytest import LogCaptureFixture
from base.langflow.components.inputs.ChatInput import ChatInput
from dotenv import load_dotenv
from fastapi.testclient import TestClient
@ -79,6 +82,19 @@ def get_text():
assert path.exists(), f"File {path} does not exist. Available files: {list(data_path.iterdir())}"
@pytest.fixture
def caplog(caplog: LogCaptureFixture):
handler_id = logger.add(
caplog.handler,
format="{message}",
level=0,
filter=lambda record: record["level"].no >= caplog.handler.level,
enqueue=False, # Set to 'True' if your test is spawning child processes.
)
yield caplog
logger.remove(handler_id)
@pytest.fixture()
async def async_client() -> AsyncGenerator:
from langflow.main import create_app

View file

@ -1,6 +1,8 @@
import logging
from collections import deque
import pytest
from pytest import LogCaptureFixture
from langflow.components.agents.ToolCallingAgent import ToolCallingAgentComponent
from langflow.components.inputs.ChatInput import ChatInput
@ -28,14 +30,16 @@ async def test_graph_not_prepared():
@pytest.mark.asyncio
async def test_graph():
async def test_graph(caplog: LogCaptureFixture):
chat_input = ChatInput()
chat_output = ChatOutput()
graph = Graph()
graph.add_component(chat_input)
graph.add_component(chat_output)
with pytest.warns(UserWarning, match="Graph has vertices but no edges"):
caplog.clear()
with caplog.at_level(logging.WARNING):
graph.prepare()
assert "Graph has vertices but no edges" in caplog.text
@pytest.mark.asyncio