🐛 fix(component.py): change variable name from function_entrypoint_name to _function_entrypoint_name for better readability and consistency

🐛 fix(component.py): fix condition to check if _function_entrypoint_name is empty in Component class

🐛 fix(manager.py): change condition to check if key is in Settings.model_fields.keys() instead of Settings.__fields__.keys() for better accuracy

✨ feat(settings.py): add support for loading settings from a YAML file and updating settings from YAML and kwargs

🐛 fix(util.py): get "type" or "annotation" from value in get_type function to handle both cases

🐛 fix(test_cli.py): convert temp_dir to string before checking if it is in settings_manager.settings.COMPONENTS_PATH

🐛 fix(test_custom_component.py): change variable name from function_entrypoint_name to _function_entrypoint_name in tests for consistency and remove test for ComponentFunctionEntrypointNameNullError since it is not used anymore

📝 docs(test_llms_template.py): update description of `OpenAI` Chat large language models API in test case
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-08-20 15:08:06 -03:00
commit 59e0bd6e9b
7 changed files with 201 additions and 25 deletions

View file

@ -27,4 +27,4 @@ def test_components_path(runner, client, default_settings):
)
assert result.exit_code == 0, result.stdout
settings_manager = utils.get_settings_manager()
assert temp_dir in settings_manager.settings.COMPONENTS_PATH
assert str(temp_dir) in settings_manager.settings.COMPONENTS_PATH

View file

@ -10,7 +10,6 @@ from langflow.interface.custom.base import CustomComponent
from langflow.interface.custom.component import (
Component,
ComponentCodeNullError,
ComponentFunctionEntrypointNameNullError,
)
from langflow.interface.custom.code_parser import CodeParser, CodeSyntaxError
@ -73,16 +72,16 @@ def test_component_init():
"""
Test the initialization of the Component class.
"""
component = Component(code=code_default, function_entrypoint_name="build")
component = Component(code=code_default, _function_entrypoint_name="build")
assert component.code == code_default
assert component.function_entrypoint_name == "build"
assert component._function_entrypoint_name == "build"
def test_component_get_code_tree():
"""
Test the get_code_tree method of the Component class.
"""
component = Component(code=code_default, function_entrypoint_name="build")
component = Component(code=code_default, _function_entrypoint_name="build")
tree = component.get_code_tree(component.code)
assert "imports" in tree
@ -92,19 +91,20 @@ def test_component_code_null_error():
Test the get_function method raises the
ComponentCodeNullError when the code is empty.
"""
component = Component(code="", function_entrypoint_name="")
component = Component(code="", _function_entrypoint_name="")
with pytest.raises(ComponentCodeNullError):
component.get_function()
def test_component_function_entrypoint_name_null_error():
"""
Test the get_function method raises the ComponentFunctionEntrypointNameNullError
when the function_entrypoint_name is empty.
"""
component = Component(code=code_default, function_entrypoint_name="")
with pytest.raises(ComponentFunctionEntrypointNameNullError):
component.get_function()
# TODO: Validate if we should remove this
# def test_component_function_entrypoint_name_null_error():
# """
# Test the get_function method raises the ComponentFunctionEntrypointNameNullError
# when the function_entrypoint_name is empty.
# """
# component = Component(code=code_default, _function_entrypoint_name="")
# with pytest.raises(ComponentFunctionEntrypointNameNullError):
# component.get_function()
def test_custom_component_init():
@ -212,7 +212,7 @@ def test_component_get_function_valid():
Test the get_function method of the Component
class with valid code and function_entrypoint_name.
"""
component = Component(code="def build(): pass", function_entrypoint_name="build")
component = Component(code="def build(): pass", _function_entrypoint_name="build")
my_function = component.get_function()
assert callable(my_function)
@ -382,7 +382,7 @@ def test_component_get_code_tree_syntax_error():
Test the get_code_tree method of the Component class
raises the CodeSyntaxError when given incorrect syntax.
"""
component = Component(code="import os as", function_entrypoint_name="build")
component = Component(code="import os as", _function_entrypoint_name="build")
with pytest.raises(CodeSyntaxError):
component.get_code_tree(component.code)

View file

@ -542,8 +542,7 @@ def test_chat_open_ai(client: TestClient):
}
assert template["_type"] == "ChatOpenAI"
assert (
model["description"]
== "Wrapper around OpenAI Chat large language models." # noqa E501
model["description"] == "`OpenAI` Chat large language models API." # noqa E501
)
assert set(model["base_classes"]) == {
"BaseLLM",