refactor: update code references to use _code instead of code (#3113)
This commit is contained in:
parent
f08467d84b
commit
e0afe90410
7 changed files with 48 additions and 49 deletions
|
|
@ -16,7 +16,7 @@ from langflow.services.database.models.flow import Flow, FlowCreate
|
|||
def code_component_with_multiple_outputs():
|
||||
with open("src/backend/tests/data/component_multiple_outputs.py", "r") as f:
|
||||
code = f.read()
|
||||
return Component(code=code)
|
||||
return Component(_code=code)
|
||||
|
||||
|
||||
code_default = """
|
||||
|
|
@ -72,8 +72,8 @@ def test_component_init():
|
|||
"""
|
||||
Test the initialization of the Component class.
|
||||
"""
|
||||
component = BaseComponent(code=code_default, function_entrypoint_name="build")
|
||||
assert component.code == code_default
|
||||
component = BaseComponent(_code=code_default, function_entrypoint_name="build")
|
||||
assert component._code == code_default
|
||||
assert component.function_entrypoint_name == "build"
|
||||
|
||||
|
||||
|
|
@ -81,8 +81,8 @@ def test_component_get_code_tree():
|
|||
"""
|
||||
Test the get_code_tree method of the Component class.
|
||||
"""
|
||||
component = BaseComponent(code=code_default, function_entrypoint_name="build")
|
||||
tree = component.get_code_tree(component.code)
|
||||
component = BaseComponent(_code=code_default, function_entrypoint_name="build")
|
||||
tree = component.get_code_tree(component._code)
|
||||
assert "imports" in tree
|
||||
|
||||
|
||||
|
|
@ -91,7 +91,7 @@ def test_component_code_null_error():
|
|||
Test the get_function method raises the
|
||||
ComponentCodeNullError when the code is empty.
|
||||
"""
|
||||
component = BaseComponent(code="", function_entrypoint_name="")
|
||||
component = BaseComponent(_code="", function_entrypoint_name="")
|
||||
with pytest.raises(ComponentCodeNullError):
|
||||
component.get_function()
|
||||
|
||||
|
|
@ -102,8 +102,8 @@ def test_custom_component_init():
|
|||
"""
|
||||
function_entrypoint_name = "build"
|
||||
|
||||
custom_component = CustomComponent(code=code_default, function_entrypoint_name=function_entrypoint_name)
|
||||
assert custom_component.code == code_default
|
||||
custom_component = CustomComponent(_code=code_default, function_entrypoint_name=function_entrypoint_name)
|
||||
assert custom_component._code == code_default
|
||||
assert custom_component.function_entrypoint_name == function_entrypoint_name
|
||||
|
||||
|
||||
|
|
@ -111,7 +111,7 @@ def test_custom_component_build_template_config():
|
|||
"""
|
||||
Test the build_template_config property of the CustomComponent class.
|
||||
"""
|
||||
custom_component = CustomComponent(code=code_default, function_entrypoint_name="build")
|
||||
custom_component = CustomComponent(_code=code_default, function_entrypoint_name="build")
|
||||
config = custom_component.build_template_config()
|
||||
assert isinstance(config, dict)
|
||||
|
||||
|
|
@ -120,7 +120,7 @@ def test_custom_component_get_function():
|
|||
"""
|
||||
Test the get_function property of the CustomComponent class.
|
||||
"""
|
||||
custom_component = CustomComponent(code="def build(): pass", function_entrypoint_name="build")
|
||||
custom_component = CustomComponent(_code="def build(): pass", function_entrypoint_name="build")
|
||||
my_function = custom_component.get_function()
|
||||
assert isinstance(my_function, types.FunctionType)
|
||||
|
||||
|
|
@ -195,7 +195,7 @@ def test_component_get_function_valid():
|
|||
Test the get_function method of the Component
|
||||
class with valid code and function_entrypoint_name.
|
||||
"""
|
||||
component = BaseComponent(code="def build(): pass", function_entrypoint_name="build")
|
||||
component = BaseComponent(_code="def build(): pass", function_entrypoint_name="build")
|
||||
my_function = component.get_function()
|
||||
assert callable(my_function)
|
||||
|
||||
|
|
@ -205,7 +205,7 @@ def test_custom_component_get_function_entrypoint_args():
|
|||
Test the get_function_entrypoint_args
|
||||
property of the CustomComponent class.
|
||||
"""
|
||||
custom_component = CustomComponent(code=code_default, function_entrypoint_name="build")
|
||||
custom_component = CustomComponent(_code=code_default, function_entrypoint_name="build")
|
||||
args = custom_component.get_function_entrypoint_args
|
||||
assert len(args) == 3
|
||||
assert args[0]["name"] == "self"
|
||||
|
|
@ -219,7 +219,7 @@ def test_custom_component_get_function_entrypoint_return_type():
|
|||
property of the CustomComponent class.
|
||||
"""
|
||||
|
||||
custom_component = CustomComponent(code=code_default, function_entrypoint_name="build")
|
||||
custom_component = CustomComponent(_code=code_default, function_entrypoint_name="build")
|
||||
return_type = custom_component.get_function_entrypoint_return_type
|
||||
assert return_type == [Document]
|
||||
|
||||
|
|
@ -228,7 +228,7 @@ def test_custom_component_get_main_class_name():
|
|||
"""
|
||||
Test the get_main_class_name property of the CustomComponent class.
|
||||
"""
|
||||
custom_component = CustomComponent(code=code_default, function_entrypoint_name="build")
|
||||
custom_component = CustomComponent(_code=code_default, function_entrypoint_name="build")
|
||||
class_name = custom_component.get_main_class_name
|
||||
assert class_name == "YourComponent"
|
||||
|
||||
|
|
@ -238,7 +238,7 @@ def test_custom_component_get_function_valid():
|
|||
Test the get_function property of the CustomComponent
|
||||
class with valid code and function_entrypoint_name.
|
||||
"""
|
||||
custom_component = CustomComponent(code="def build(): pass", function_entrypoint_name="build")
|
||||
custom_component = CustomComponent(_code="def build(): pass", function_entrypoint_name="build")
|
||||
my_function = custom_component.get_function
|
||||
assert callable(my_function)
|
||||
|
||||
|
|
@ -352,9 +352,9 @@ 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 = BaseComponent(code="import os as", function_entrypoint_name="build")
|
||||
component = BaseComponent(_code="import os as", function_entrypoint_name="build")
|
||||
with pytest.raises(CodeSyntaxError):
|
||||
component.get_code_tree(component.code)
|
||||
component.get_code_tree(component._code)
|
||||
|
||||
|
||||
def test_custom_component_class_template_validation_no_code():
|
||||
|
|
@ -362,7 +362,7 @@ def test_custom_component_class_template_validation_no_code():
|
|||
Test the _class_template_validation method of the CustomComponent class
|
||||
raises the HTTPException when the code is None.
|
||||
"""
|
||||
custom_component = CustomComponent(code=None, function_entrypoint_name="build")
|
||||
custom_component = CustomComponent(_code=None, function_entrypoint_name="build")
|
||||
with pytest.raises(TypeError):
|
||||
custom_component.get_function()
|
||||
|
||||
|
|
@ -372,9 +372,9 @@ def test_custom_component_get_code_tree_syntax_error():
|
|||
Test the get_code_tree method of the CustomComponent class
|
||||
raises the CodeSyntaxError when given incorrect syntax.
|
||||
"""
|
||||
custom_component = CustomComponent(code="import os as", function_entrypoint_name="build")
|
||||
custom_component = CustomComponent(_code="import os as", function_entrypoint_name="build")
|
||||
with pytest.raises(CodeSyntaxError):
|
||||
custom_component.get_code_tree(custom_component.code)
|
||||
custom_component.get_code_tree(custom_component._code)
|
||||
|
||||
|
||||
def test_custom_component_get_function_entrypoint_args_no_args():
|
||||
|
|
@ -387,7 +387,7 @@ class MyMainClass(CustomComponent):
|
|||
def build():
|
||||
pass"""
|
||||
|
||||
custom_component = CustomComponent(code=my_code, function_entrypoint_name="build")
|
||||
custom_component = CustomComponent(_code=my_code, function_entrypoint_name="build")
|
||||
args = custom_component.get_function_entrypoint_args
|
||||
assert len(args) == 0
|
||||
|
||||
|
|
@ -402,7 +402,7 @@ class MyClass(CustomComponent):
|
|||
def build():
|
||||
pass"""
|
||||
|
||||
custom_component = CustomComponent(code=my_code, function_entrypoint_name="build")
|
||||
custom_component = CustomComponent(_code=my_code, function_entrypoint_name="build")
|
||||
return_type = custom_component.get_function_entrypoint_return_type
|
||||
assert return_type == []
|
||||
|
||||
|
|
@ -416,7 +416,7 @@ def test_custom_component_get_main_class_name_no_main_class():
|
|||
def build():
|
||||
pass"""
|
||||
|
||||
custom_component = CustomComponent(code=my_code, function_entrypoint_name="build")
|
||||
custom_component = CustomComponent(_code=my_code, function_entrypoint_name="build")
|
||||
class_name = custom_component.get_main_class_name
|
||||
assert class_name == ""
|
||||
|
||||
|
|
@ -426,13 +426,13 @@ def test_custom_component_build_not_implemented():
|
|||
Test the build method of the CustomComponent
|
||||
class raises the NotImplementedError.
|
||||
"""
|
||||
custom_component = CustomComponent(code="def build(): pass", function_entrypoint_name="build")
|
||||
custom_component = CustomComponent(_code="def build(): pass", function_entrypoint_name="build")
|
||||
with pytest.raises(NotImplementedError):
|
||||
custom_component.build()
|
||||
|
||||
|
||||
def test_build_config_no_code():
|
||||
component = CustomComponent(code=None)
|
||||
component = CustomComponent(_code=None)
|
||||
|
||||
assert component.get_function_entrypoint_args == []
|
||||
assert component.get_function_entrypoint_return_type == []
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ from langflow.schema import Data
|
|||
def test_uuid_generator_component():
|
||||
# Arrange
|
||||
uuid_generator_component = helpers.IDGeneratorComponent()
|
||||
uuid_generator_component.code = open(helpers.IDGenerator.__file__, "r").read()
|
||||
uuid_generator_component._code = open(helpers.IDGenerator.__file__, "r").read()
|
||||
|
||||
frontend_node, _ = build_custom_component_template(uuid_generator_component)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue