Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

test(rag): close temp file before encoding detection in test_helpers (#39896)

AlexMultiAgent702595c9eeed
diff --git a/api/tests/unit_tests/core/rag/extractor/test_helpers.py b/api/tests/unit_tests/core/rag/extractor/test_helpers.py
index 43ef3283392..608bc1c2ab7 100644
--- a/api/tests/unit_tests/core/rag/extractor/test_helpers.py
+++ b/api/tests/unit_tests/core/rag/extractor/test_helpers.py
@@ -1,3 +1,4 @@
+import os
import tempfile
from pathlib import Path
from types import SimpleNamespace
@@ -45,11 +46,14 @@ class TestHelpers:
assert encodings[0].encoding == "ascii"
def test_detect_file_encodings(self) -> None:
- with tempfile.NamedTemporaryFile(mode="w+t", suffix=".txt") as temp:
+ with tempfile.NamedTemporaryFile(mode="w+t", suffix=".txt", delete=False) as temp:
temp.write("Shared data")
temp.flush()
temp_path = temp.name
+ try:
encodings = detect_file_encodings(temp_path)
+ finally:
+ os.unlink(temp_path)
assert len(encodings) == 1
assert encodings[0].encoding in {"utf_8", "ascii"}