mirror of
https://github.com/langgenius/dify.git
synced 2026-11-11 13:51:25 +08:00
refactor(api): enable strict typing for small excluded test files (#44814)
Co-authored-by: Felix Shi <204130665+shi-felix@users.noreply.github.com> Co-authored-by: Asuka Minato <i@asukaminato.eu.org>
This commit is contained in:
10 files changed
+23
-28
No files matched your search
@@ -2,6 +2,6 @@ from core.app.apps.exc import GenerateTaskStoppedError
|
||||
|
||||
|
||||
class TestAppsExceptions:
|
||||
def test_generate_task_stopped_error(self):
|
||||
def test_generate_task_stopped_error(self) -> None:
|
||||
err = GenerateTaskStoppedError("stopped")
|
||||
assert str(err) == "stopped"
|
||||
@@ -2,8 +2,9 @@ from core.app.apps.workflow.errors import WorkflowPausedInBlockingModeError
|
||||
|
||||
|
||||
class TestWorkflowErrors:
|
||||
def test_workflow_paused_in_blocking_mode_error_attributes(self):
|
||||
def test_workflow_paused_in_blocking_mode_error_attributes(self) -> None:
|
||||
err = WorkflowPausedInBlockingModeError()
|
||||
assert err.error_code == "workflow_paused_in_blocking_mode"
|
||||
assert err.code == 400
|
||||
assert err.description is not None
|
||||
assert "blocking response mode" in err.description
|
||||
@@ -2,10 +2,10 @@ from core.app.task_pipeline.exc import RecordNotFoundError, WorkflowRunNotFoundE
|
||||
|
||||
|
||||
class TestTaskPipelineExceptions:
|
||||
def test_record_not_found_error_message(self):
|
||||
def test_record_not_found_error_message(self) -> None:
|
||||
err = RecordNotFoundError("Message", "msg-1")
|
||||
assert str(err) == "Message with id msg-1 not found"
|
||||
|
||||
def test_workflow_run_not_found_error_message(self):
|
||||
def test_workflow_run_not_found_error_message(self) -> None:
|
||||
err = WorkflowRunNotFoundError("run-1")
|
||||
assert str(err) == "WorkflowRun with id run-1 not found"
|
||||
@@ -6,7 +6,7 @@ from core.plugin.impl.debugging import PluginDebuggingClient
|
||||
|
||||
|
||||
class TestPluginDebuggingClient:
|
||||
def test_get_debugging_key(self, mocker: MockerFixture):
|
||||
def test_get_debugging_key(self, mocker: MockerFixture) -> None:
|
||||
client = PluginDebuggingClient()
|
||||
request_mock = mocker.patch.object(
|
||||
client,
|
||||
|
||||
@@ -4,7 +4,7 @@ from core.rag.extractor.html_extractor import HtmlExtractor
|
||||
|
||||
|
||||
class TestHtmlExtractor:
|
||||
def test_extract_returns_text_content(self, tmp_path: Path):
|
||||
def test_extract_returns_text_content(self, tmp_path: Path) -> None:
|
||||
file_path = tmp_path / "sample.html"
|
||||
file_path.write_text("<html><body><h1>Title</h1><p>Hello</p></body></html>", encoding="utf-8")
|
||||
|
||||
@@ -14,7 +14,7 @@ class TestHtmlExtractor:
|
||||
assert len(docs) == 1
|
||||
assert "".join(docs[0].page_content.split()) == "TitleHello"
|
||||
|
||||
def test_load_as_text_strips_whitespace_and_handles_empty(self, tmp_path: Path):
|
||||
def test_load_as_text_strips_whitespace_and_handles_empty(self, tmp_path: Path) -> None:
|
||||
file_path = tmp_path / "sample.html"
|
||||
file_path.write_text("<html><body> \n </body></html>", encoding="utf-8")
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ from core.trigger.utils import endpoint
|
||||
|
||||
|
||||
class TestGeneratePluginTriggerEndpointUrl:
|
||||
def test_builds_correct_url(self):
|
||||
def test_builds_correct_url(self) -> None:
|
||||
with patch.object(endpoint, "base_url", URL("https://api.example.com")):
|
||||
url = endpoint.generate_plugin_trigger_endpoint_url("endpoint-123")
|
||||
|
||||
@@ -18,13 +18,13 @@ class TestGeneratePluginTriggerEndpointUrl:
|
||||
|
||||
|
||||
class TestGenerateWebhookTriggerEndpoint:
|
||||
def test_non_debug_url(self):
|
||||
def test_non_debug_url(self) -> None:
|
||||
with patch.object(endpoint, "base_url", URL("https://api.example.com")):
|
||||
url = endpoint.generate_webhook_trigger_endpoint("sub-456", debug=False)
|
||||
|
||||
assert url == "https://api.example.com/triggers/webhook/sub-456"
|
||||
|
||||
def test_debug_url(self):
|
||||
def test_debug_url(self) -> None:
|
||||
with patch.object(endpoint, "base_url", URL("https://api.example.com")):
|
||||
url = endpoint.generate_webhook_trigger_endpoint("sub-456", debug=True)
|
||||
|
||||
|
||||
@@ -2,18 +2,21 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from core.trigger.utils.locks import build_trigger_refresh_lock_key, build_trigger_refresh_lock_keys
|
||||
from core.trigger.utils.locks import (
|
||||
build_trigger_refresh_lock_key,
|
||||
build_trigger_refresh_lock_keys,
|
||||
)
|
||||
|
||||
|
||||
class TestBuildTriggerRefreshLockKey:
|
||||
def test_correct_format(self):
|
||||
def test_correct_format(self) -> None:
|
||||
key = build_trigger_refresh_lock_key("tenant-1", "sub-1")
|
||||
|
||||
assert key == "trigger_provider_refresh_lock:tenant-1_sub-1"
|
||||
|
||||
|
||||
class TestBuildTriggerRefreshLockKeys:
|
||||
def test_maps_over_pairs(self):
|
||||
def test_maps_over_pairs(self) -> None:
|
||||
pairs = [("t1", "s1"), ("t2", "s2")]
|
||||
|
||||
keys = build_trigger_refresh_lock_keys(pairs)
|
||||
|
||||
@@ -4,13 +4,13 @@ import pytest
|
||||
from libs.orjson import orjson_dumps
|
||||
|
||||
|
||||
def test_orjson_dumps_round_trip_basic():
|
||||
def test_orjson_dumps_round_trip_basic() -> None:
|
||||
obj = {"a": 1, "b": [1, 2, 3], "c": {"d": True}}
|
||||
s = orjson_dumps(obj)
|
||||
assert orjson.loads(s) == obj
|
||||
|
||||
|
||||
def test_orjson_dumps_with_unicode_and_indent():
|
||||
def test_orjson_dumps_with_unicode_and_indent() -> None:
|
||||
obj = {"msg": "你好,Dify"}
|
||||
s = orjson_dumps(obj, option=orjson.OPT_INDENT_2)
|
||||
# contains indentation newline/spaces
|
||||
@@ -18,7 +18,7 @@ def test_orjson_dumps_with_unicode_and_indent():
|
||||
assert orjson.loads(s) == obj
|
||||
|
||||
|
||||
def test_orjson_dumps_non_utf8_encoding_fails():
|
||||
def test_orjson_dumps_non_utf8_encoding_fails() -> None:
|
||||
obj = {"msg": "你好"}
|
||||
# orjson.dumps() always produces UTF-8 bytes; decoding with non-UTF8 fails.
|
||||
with pytest.raises(UnicodeDecodeError):
|
||||
|
||||
@@ -171,7 +171,6 @@ project-excludes = [
|
||||
"core/app/apps/pipeline/test_pipeline_runner.py",
|
||||
"core/app/apps/test_base_app_generator.py",
|
||||
"core/app/apps/test_base_app_queue_manager.py",
|
||||
"core/app/apps/test_exc.py",
|
||||
"core/app/apps/test_message_based_app_generator.py",
|
||||
"core/app/apps/test_message_generator.py",
|
||||
"core/app/apps/test_streaming_utils.py",
|
||||
@@ -182,7 +181,6 @@ project-excludes = [
|
||||
"core/app/apps/workflow/test_app_config_manager.py",
|
||||
"core/app/apps/workflow/test_app_queue_manager.py",
|
||||
"core/app/apps/workflow/test_command_channels.py",
|
||||
"core/app/apps/workflow/test_errors.py",
|
||||
"core/app/apps/workflow/test_generate_response_converter.py",
|
||||
"core/app/apps/workflow/test_generate_task_pipeline.py",
|
||||
"core/app/entities/test_app_invoke_entities.py",
|
||||
@@ -195,7 +193,6 @@ project-excludes = [
|
||||
"core/app/layers/test_trigger_post_layer.py",
|
||||
"core/app/task_pipeline/test_based_generate_task_pipeline.py",
|
||||
"core/app/task_pipeline/test_easy_ui_based_generate_task_pipeline.py",
|
||||
"core/app/task_pipeline/test_exc.py",
|
||||
"core/app/task_pipeline/test_message_cycle_manager.py",
|
||||
"core/app/app_config/easy_ui_based_app/model_config/test_manager.py",
|
||||
"core/app/llm/test_quota.py",
|
||||
@@ -237,7 +234,6 @@ project-excludes = [
|
||||
"core/plugin/impl/test_asset.py",
|
||||
"core/plugin/impl/test_base.py",
|
||||
"core/plugin/impl/test_datasource.py",
|
||||
"core/plugin/impl/test_debugging.py",
|
||||
"core/plugin/impl/test_endpoint.py",
|
||||
"core/plugin/impl/test_exc.py",
|
||||
"core/plugin/impl/test_model.py",
|
||||
@@ -262,7 +258,6 @@ project-excludes = [
|
||||
"core/rag/extractor/test_excel_extractor.py",
|
||||
"core/rag/extractor/test_extract_processor.py",
|
||||
"core/rag/extractor/test_helpers.py",
|
||||
"core/rag/extractor/test_html_extractor.py",
|
||||
"core/rag/extractor/test_markdown_extractor.py",
|
||||
"core/rag/extractor/test_word_extractor.py",
|
||||
"core/rag/extractor/watercrawl/test_client.py",
|
||||
@@ -306,8 +301,6 @@ project-excludes = [
|
||||
"core/tools/workflow_as_tool/test_provider.py",
|
||||
"core/tools/workflow_as_tool/test_tool.py",
|
||||
"core/trigger/utils/test_encryption.py",
|
||||
"core/trigger/utils/test_endpoint.py",
|
||||
"core/trigger/utils/test_locks.py",
|
||||
"context/test_execution_context.py",
|
||||
"context/test_flask_app_context.py",
|
||||
"../e2e_tests/contracts/core/workflow/entities/test_private_workflow_pause.py",
|
||||
@@ -398,7 +391,6 @@ project-excludes = [
|
||||
"libs/test_flask_utils.py",
|
||||
"libs/test_helper.py",
|
||||
"libs/test_login.py",
|
||||
"libs/test_orjson.py",
|
||||
"../e2e_tests/contracts/libs/test_pandas.py",
|
||||
"libs/test_token.py",
|
||||
"migrations/versions/test_2025_07_02_2332-1c9ba48be8e4_add_uuidv7_function_in_sql.py",
|
||||
@@ -480,7 +472,6 @@ project-excludes = [
|
||||
"services/tools/test_api_tools_manage_service.py",
|
||||
"services/tools/test_builtin_tools_manage_service.py",
|
||||
"services/tools/test_tools_transform_service.py",
|
||||
"services/tools/test_tool_labels_service.py",
|
||||
"services/tools/test_tools_manage_service.py",
|
||||
"services/test_workflow_draft_variable_service.py",
|
||||
"services/workflow/test_node_output_inspector_service.py",
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
from services.tools.tool_labels_service import ToolLabelsService
|
||||
|
||||
|
||||
def test_list_tool_labels_returns_default_labels():
|
||||
def test_list_tool_labels_returns_default_labels() -> None:
|
||||
result = ToolLabelsService.list_tool_labels()
|
||||
assert isinstance(result, list)
|
||||
assert len(result) > 0
|
||||
|
||||
|
||||
def test_list_tool_labels_items_are_tool_labels():
|
||||
def test_list_tool_labels_items_are_tool_labels() -> None:
|
||||
from core.tools.entities.tool_entities import ToolLabel
|
||||
|
||||
result = ToolLabelsService.list_tool_labels()
|
||||
@@ -15,7 +15,7 @@ def test_list_tool_labels_items_are_tool_labels():
|
||||
assert isinstance(label, ToolLabel)
|
||||
|
||||
|
||||
def test_list_tool_labels_matches_default_values():
|
||||
def test_list_tool_labels_matches_default_values() -> None:
|
||||
from core.tools.entities.values import default_tool_labels
|
||||
|
||||
assert ToolLabelsService.list_tool_labels() is default_tool_labels
|
||||
Reference in new issue
Block a user