mirror of https://github.com/hwchase17/langchain
pull/11175/head
parent
5c1f462bb9
commit
a5b15e9d0f
@ -0,0 +1,34 @@
|
||||
import pytest
|
||||
|
||||
from langchain.schema.runnable.utils import (
|
||||
get_lambda_source,
|
||||
indent_lines_after_first,
|
||||
)
|
||||
from langchain.schema.runnable.base import RunnableLambda
|
||||
|
||||
|
||||
# Test get_lambda_source function
|
||||
@pytest.mark.parametrize(
|
||||
"func, expected_source",
|
||||
[
|
||||
(lambda x: x * 2, "lambda x: x * 2"),
|
||||
(lambda a, b: a + b, "lambda a, b: a + b"),
|
||||
(lambda x: x if x > 0 else 0, "lambda x: x if x > 0 else 0"),
|
||||
],
|
||||
)
|
||||
def test_get_lambda_source(func, expected_source):
|
||||
source = get_lambda_source(func)
|
||||
assert source == expected_source
|
||||
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"text,prefix,expected_output",
|
||||
[
|
||||
("line 1\nline 2\nline 3", "1", "line 1\n line 2\n line 3"),
|
||||
("line 1\nline 2\nline 3", "ax", "line 1\n line 2\n line 3"),
|
||||
],
|
||||
)
|
||||
def test_indent_lines_after_first(text, prefix, expected_output):
|
||||
indented_text = indent_lines_after_first(text, prefix)
|
||||
assert indented_text == expected_output
|
Loading…
Reference in New Issue