The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
fix(core): make subprocess and temporary file tests portable on Windows (#39664)
Jacopos311c8b2d767bf2f
diff --git a/libs/core/tests/unit_tests/prompts/test_prompt.py b/libs/core/tests/unit_tests/prompts/test_prompt.pyindex ed7449fd7e..49525b75c7 100644--- a/libs/core/tests/unit_tests/prompts/test_prompt.py+++ b/libs/core/tests/unit_tests/prompts/test_prompt.py@@ -2,7 +2,7 @@import refrom collections import ChainMap, UserDict-from tempfile import NamedTemporaryFile+from pathlib import Pathfrom types import MappingProxyTypefrom typing import Any, Literalfrom unittest import mock@@ -39,25 +39,23 @@ def test_prompt_valid() -> None:assert prompt.input_variables == input_variables-def test_from_file_encoding() -> None:+def test_from_file_encoding(tmp_path: Path) -> None:"""Test that we can load a template from a file with a non utf-8 encoding."""template = "This is a {foo} test with special character €."input_variables = ["foo"]# First write to a file using CP-1252 encoding.- with NamedTemporaryFile(delete=True, mode="w", encoding="cp1252") as f:- f.write(template)- f.flush()- file_name = f.name-- # Now read from the file using CP-1252 encoding and test- prompt = PromptTemplate.from_file(file_name, encoding="cp1252")- assert prompt.template == template- assert prompt.input_variables == input_variables-- # Now read from the file using UTF-8 encoding and test- with pytest.raises(UnicodeDecodeError):- PromptTemplate.from_file(file_name, encoding="utf-8")+ file_path = tmp_path / "template.txt"+ file_path.write_text(template, encoding="cp1252")++ # Now read from the file using CP-1252 encoding and test+ prompt = PromptTemplate.from_file(file_path, encoding="cp1252")+ assert prompt.template == template+ assert prompt.input_variables == input_variables++ # Now read from the file using UTF-8 encoding and test+ with pytest.raises(UnicodeDecodeError):+ PromptTemplate.from_file(file_path, encoding="utf-8")def test_prompt_from_template() -> None:diff --git a/libs/core/tests/unit_tests/test_imports.py b/libs/core/tests/unit_tests/test_imports.pyindex 22a1a9a823..f035595c8c 100644--- a/libs/core/tests/unit_tests/test_imports.py+++ b/libs/core/tests/unit_tests/test_imports.py@@ -1,6 +1,7 @@import concurrent.futuresimport importlibimport subprocess+import sysfrom pathlib import Path@@ -26,7 +27,7 @@ def try_to_import(module_name: str) -> tuple[int, str]:getattr(module, cls_)result = subprocess.run(- ["python", "-c", f"import langchain_core.{module_name}"], check=True+ [sys.executable, "-c", f"import langchain_core.{module_name}"], check=True)return result.returncode, module_name