Skip to content

Commit

Permalink
chore: removing unused imports in tests (#9049)
Browse files Browse the repository at this point in the history
  • Loading branch information
bowenliang123 authored Oct 8, 2024
1 parent a8b4d1a commit 7c0b159
Show file tree
Hide file tree
Showing 30 changed files with 21 additions and 52 deletions.
12 changes: 6 additions & 6 deletions api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from configs import dify_config

# DO NOT REMOVE BELOW
from events import event_handlers
from events import event_handlers # noqa: F401
from extensions import (
ext_celery,
ext_code_based_extension,
Expand All @@ -45,7 +45,7 @@
from libs.passport import PassportService

# TODO: Find a way to avoid importing models here
from models import account, dataset, model, source, task, tool, tools, web
from models import account, dataset, model, source, task, tool, tools, web # noqa: F401
from services.account_service import AccountService

# DO NOT REMOVE ABOVE
Expand Down Expand Up @@ -181,10 +181,10 @@ def load_user_from_request(request_from_flask_login):
decoded = PassportService().verify(auth_token)
user_id = decoded.get("user_id")

account = AccountService.load_logged_in_account(account_id=user_id, token=auth_token)
if account:
contexts.tenant_id.set(account.current_tenant_id)
return account
logged_in_account = AccountService.load_logged_in_account(account_id=user_id, token=auth_token)
if logged_in_account:
contexts.tenant_id.set(logged_in_account.current_tenant_id)
return logged_in_account


@login_manager.unauthorized_handler
Expand Down
2 changes: 1 addition & 1 deletion api/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ ignore = [

[tool.ruff.lint.per-file-ignores]
"app.py" = [
"F401", # unused-import
"F811", # redefined-while-unused
]
"__init__.py" = [
"F401", # unused-import
Expand All @@ -88,10 +86,15 @@ ignore = [
"N803", # invalid-argument-name
]
"tests/*" = [
"F401", # unused-import
"F811", # redefined-while-unused
]

[tool.ruff.lint.pyflakes]
allowed-unused-imports=[
"_pytest.monkeypatch",
"tests.integration_tests",
]

[tool.ruff.format]
exclude = [
]
Expand Down Expand Up @@ -260,4 +263,4 @@ optional = true

[tool.poetry.group.lint.dependencies]
dotenv-linter = "~0.5.0"
ruff = "~0.6.8"
ruff = "~0.6.9"
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import anthropic
import pytest
from _pytest.monkeypatch import MonkeyPatch
from anthropic import Anthropic, Stream
from anthropic import Stream
from anthropic.resources import Messages
from anthropic.types import (
ContentBlock,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from collections.abc import Callable
from typing import Any, Literal, Union
from typing import Any, Literal

import pytest

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re
from collections.abc import Generator
from json import dumps, loads
from json import dumps
from time import time

# import monkeypatch
Expand All @@ -11,11 +11,9 @@
from openai.resources.chat.completions import Completions
from openai.types import Completion as CompletionMessage
from openai.types.chat import (
ChatCompletion,
ChatCompletionChunk,
ChatCompletionMessageParam,
ChatCompletionMessageToolCall,
ChatCompletionToolChoiceOptionParam,
ChatCompletionToolParam,
completion_create_params,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import re
from typing import Any, Literal, Union

from openai import OpenAI
from openai._types import NOT_GIVEN, NotGiven
from openai.resources.embeddings import Embeddings
from openai.types.create_embedding_response import CreateEmbeddingResponse, Usage
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from time import time

from openai.resources.models import Models
from openai.types.model import Model


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import pytest
from _pytest.monkeypatch import MonkeyPatch
from requests import Response
from requests.exceptions import ConnectionError
from requests.sessions import Session
from xinference_client.client.restful.restful_client import (
Client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta
from core.model_runtime.entities.message_entities import (
AssistantPromptMessage,
ImagePromptMessageContent,
PromptMessageTool,
SystemPromptMessage,
TextPromptMessageContent,
UserPromptMessage,
)
from core.model_runtime.errors.validate import CredentialsValidateFailedError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
AssistantPromptMessage,
PromptMessageTool,
SystemPromptMessage,
TextPromptMessageContent,
UserPromptMessage,
)
from core.model_runtime.entities.model_entities import AIModelEntity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import pytest

from core.model_runtime.entities.rerank_entities import RerankDocument, RerankResult
from core.model_runtime.entities.text_embedding_entities import TextEmbeddingResult
from core.model_runtime.entities.rerank_entities import RerankResult
from core.model_runtime.errors.validate import CredentialsValidateFailedError
from core.model_runtime.model_providers.huggingface_tei.rerank.rerank import (
HuggingfaceTeiRerankModel,
Expand Down
2 changes: 0 additions & 2 deletions api/tests/integration_tests/model_runtime/localai/test_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
AssistantPromptMessage,
PromptMessageTool,
SystemPromptMessage,
TextPromptMessageContent,
UserPromptMessage,
)
from core.model_runtime.entities.model_entities import ParameterRule
from core.model_runtime.errors.validate import CredentialsValidateFailedError
from core.model_runtime.model_providers.localai.llm.llm import LocalAILanguageModel

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from core.model_runtime.errors.validate import CredentialsValidateFailedError
from core.model_runtime.model_providers.nomic.nomic import NomicAtlasProvider
from core.model_runtime.model_providers.nomic.text_embedding.text_embedding import NomicTextEmbeddingModel
from tests.integration_tests.model_runtime.__mock.nomic_embeddings import setup_nomic_mock


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta
from core.model_runtime.entities.message_entities import (
AssistantPromptMessage,
PromptMessageTool,
SystemPromptMessage,
UserPromptMessage,
)
Expand Down
1 change: 0 additions & 1 deletion api/tests/integration_tests/model_runtime/oci/test_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
AssistantPromptMessage,
PromptMessageTool,
SystemPromptMessage,
TextPromptMessageContent,
UserPromptMessage,
)
from core.model_runtime.errors.validate import CredentialsValidateFailedError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
)
from core.model_runtime.entities.model_entities import AIModelEntity, ModelType
from core.model_runtime.errors.validate import CredentialsValidateFailedError
from core.model_runtime.model_providers.__base.large_language_model import LargeLanguageModel
from core.model_runtime.model_providers.openai.llm.llm import OpenAILargeLanguageModel

"""FOR MOCK FIXTURES, DO NOT REMOVE"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta
from core.model_runtime.entities.message_entities import (
AssistantPromptMessage,
PromptMessageTool,
SystemPromptMessage,
UserPromptMessage,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os

import pytest

from core.model_runtime.errors.validate import CredentialsValidateFailedError
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os

import pytest

from core.model_runtime.entities.text_embedding_entities import TextEmbeddingResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta
from core.model_runtime.entities.message_entities import (
AssistantPromptMessage,
ImagePromptMessageContent,
PromptMessageTool,
SystemPromptMessage,
TextPromptMessageContent,
UserPromptMessage,
)
from core.model_runtime.entities.model_entities import AIModelEntity, ModelType
from core.model_runtime.entities.model_entities import AIModelEntity
from core.model_runtime.errors.validate import CredentialsValidateFailedError
from core.model_runtime.model_providers.stepfun.llm.llm import StepfunLargeLanguageModel

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta
from core.model_runtime.entities.message_entities import (
AssistantPromptMessage,
PromptMessageTool,
SystemPromptMessage,
UserPromptMessage,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
SystemPromptMessage,
UserPromptMessage,
)
from core.model_runtime.entities.model_entities import AIModelEntity, ModelType
from core.model_runtime.entities.model_entities import AIModelEntity
from core.model_runtime.errors.validate import CredentialsValidateFailedError
from core.model_runtime.model_providers.__base.large_language_model import LargeLanguageModel
from core.model_runtime.model_providers.upstage.llm.llm import UpstageLargeLanguageModel

"""FOR MOCK FIXTURES, DO NOT REMOVE"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
AssistantPromptMessage,
PromptMessageTool,
SystemPromptMessage,
TextPromptMessageContent,
UserPromptMessage,
)
from core.model_runtime.entities.model_entities import AIModelEntity
from core.model_runtime.errors.validate import CredentialsValidateFailedError
from core.model_runtime.model_providers.xinference.llm.llm import XinferenceAILargeLanguageModel

Expand Down
1 change: 0 additions & 1 deletion api/tests/integration_tests/vdb/pgvector/test_pgvector.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from core.rag.datasource.vdb.pgvector.pgvector import PGVector, PGVectorConfig
from core.rag.models.document import Document
from tests.integration_tests.vdb.test_vector_store import (
AbstractVectorTest,
get_example_text,
Expand Down
1 change: 0 additions & 1 deletion api/tests/integration_tests/vdb/test_vector_store.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import random
import uuid
from unittest.mock import MagicMock

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from typing import Literal, Optional
from typing import Literal

import pytest
from _pytest.monkeypatch import MonkeyPatch
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
import os
import time
import uuid
Expand Down
1 change: 0 additions & 1 deletion api/tests/unit_tests/core/app/segments/test_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from pydantic import ValidationError

from core.app.segments import (
ArrayAnyVariable,
FloatVariable,
IntegerVariable,
ObjectVariable,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import os
from unittest import mock

from core.rag.extractor.firecrawl.firecrawl_app import FirecrawlApp
from core.rag.extractor.firecrawl.firecrawl_web_extractor import FirecrawlWebExtractor
from core.rag.models.document import Document
from tests.unit_tests.core.rag.extractor.test_notion_extractor import _mock_response


Expand Down

0 comments on commit 7c0b159

Please sign in to comment.