parent
9e278835c2
commit
eb53f66641
11 changed files with 59 additions and 87 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import ast
|
||||
import types
|
||||
from pathlib import Path
|
||||
from textwrap import dedent
|
||||
|
||||
import pytest
|
||||
|
|
@ -18,9 +19,8 @@ def client():
|
|||
|
||||
@pytest.fixture
|
||||
def code_component_with_multiple_outputs():
|
||||
with open("src/backend/tests/data/component_multiple_outputs.py") as f:
|
||||
code = f.read()
|
||||
return Component(_code=code)
|
||||
code = Path("src/backend/tests/data/component_multiple_outputs.py").read_text()
|
||||
return Component(_code=code)
|
||||
|
||||
|
||||
code_default = """
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from langflow.custom import Component
|
||||
|
|
@ -9,9 +11,8 @@ from langflow.services.settings.feature_flags import FEATURE_FLAGS
|
|||
|
||||
@pytest.fixture
|
||||
def code_component_with_multiple_outputs():
|
||||
with open("src/backend/tests/data/component_multiple_outputs.py") as f:
|
||||
code = f.read()
|
||||
return Component(_code=code)
|
||||
code = Path("src/backend/tests/data/component_multiple_outputs.py").read_text()
|
||||
return Component(_code=code)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import os
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from unittest.mock import Mock, patch, ANY
|
||||
|
|
@ -128,7 +127,7 @@ def test_directory_component_build_with_multithreading(
|
|||
):
|
||||
# Arrange
|
||||
directory_component = data.DirectoryComponent()
|
||||
path = os.path.dirname(os.path.abspath(__file__))
|
||||
path = Path(__file__).resolve().parent
|
||||
depth = 1
|
||||
max_concurrency = 2
|
||||
load_hidden = False
|
||||
|
|
@ -136,16 +135,15 @@ def test_directory_component_build_with_multithreading(
|
|||
silent_errors = False
|
||||
use_multithreading = True
|
||||
|
||||
mock_resolve_path.return_value = path
|
||||
mock_retrieve_file_paths.return_value = [
|
||||
os.path.join(path, file) for file in os.listdir(path) if file.endswith(".py")
|
||||
]
|
||||
mock_resolve_path.return_value = str(path)
|
||||
|
||||
mock_retrieve_file_paths.return_value = [str(p) for p in path.iterdir() if p.suffix == ".py"]
|
||||
mock_parallel_load_data.return_value = [Mock()]
|
||||
|
||||
# Act
|
||||
directory_component.set_attributes(
|
||||
{
|
||||
"path": path,
|
||||
"path": str(path),
|
||||
"depth": depth,
|
||||
"max_concurrency": max_concurrency,
|
||||
"load_hidden": load_hidden,
|
||||
|
|
@ -157,9 +155,9 @@ def test_directory_component_build_with_multithreading(
|
|||
directory_component.load_directory()
|
||||
|
||||
# Assert
|
||||
mock_resolve_path.assert_called_once_with(path)
|
||||
mock_resolve_path.assert_called_once_with(str(path))
|
||||
mock_retrieve_file_paths.assert_called_once_with(
|
||||
path, load_hidden=load_hidden, recursive=recursive, depth=depth, types=ANY
|
||||
str(path), load_hidden=load_hidden, recursive=recursive, depth=depth, types=ANY
|
||||
)
|
||||
mock_parallel_load_data.assert_called_once_with(
|
||||
mock_retrieve_file_paths.return_value, silent_errors=silent_errors, max_concurrency=max_concurrency
|
||||
|
|
@ -170,11 +168,9 @@ def test_directory_without_mocks():
|
|||
directory_component = data.DirectoryComponent()
|
||||
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
with open(temp_dir + "/test.txt", "w") as f:
|
||||
f.write("test")
|
||||
(Path(temp_dir) / "test.txt").write_text("test")
|
||||
# also add a json file
|
||||
with open(temp_dir + "/test.json", "w") as f:
|
||||
f.write('{"test": "test"}')
|
||||
(Path(temp_dir) / "test.json").write_text('{"test": "test"}')
|
||||
|
||||
directory_component.set_attributes({"path": str(temp_dir), "use_multithreading": False})
|
||||
results = directory_component.load_directory()
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import os
|
||||
import re
|
||||
import shutil
|
||||
import tempfile
|
||||
|
|
@ -39,7 +38,7 @@ async def files_client_fixture(session: Session, monkeypatch, request, load_flow
|
|||
monkeypatch.setenv("LANGFLOW_AUTO_LOGIN", "false")
|
||||
if "load_flows" in request.keywords:
|
||||
shutil.copyfile(
|
||||
pytest.BASIC_EXAMPLE_PATH, os.path.join(load_flows_dir, "c54f9130-f2fa-4a3e-b22a-3856d946351b.json")
|
||||
pytest.BASIC_EXAMPLE_PATH, Path(load_flows_dir) / "c54f9130-f2fa-4a3e-b22a-3856d946351b.json"
|
||||
)
|
||||
monkeypatch.setenv("LANGFLOW_LOAD_FLOWS_PATH", load_flows_dir)
|
||||
monkeypatch.setenv("LANGFLOW_AUTO_LOGIN", "true")
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from pathlib import Path
|
||||
|
||||
from langflow.components import helpers
|
||||
from langflow.custom.utils import build_custom_component_template
|
||||
from langflow.schema import Data
|
||||
|
|
@ -40,7 +42,7 @@ def client():
|
|||
def test_uuid_generator_component():
|
||||
# Arrange
|
||||
uuid_generator_component = helpers.IDGeneratorComponent()
|
||||
uuid_generator_component._code = open(helpers.IDGenerator.__file__).read()
|
||||
uuid_generator_component._code = Path(helpers.IDGenerator.__file__).read_text()
|
||||
|
||||
frontend_node, _ = build_custom_component_template(uuid_generator_component)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue