From 52982a65c3d8b3f2a906e3927084be5c070379fd Mon Sep 17 00:00:00 2001 From: Yotam-Perlitz Date: Wed, 8 Jan 2025 19:43:24 +0100 Subject: [PATCH] add processors tests Signed-off-by: Yotam-Perlitz --- tests/library/test_collections_operators.py | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/library/test_collections_operators.py b/tests/library/test_collections_operators.py index 8af98b7167..7ae1630f53 100644 --- a/tests/library/test_collections_operators.py +++ b/tests/library/test_collections_operators.py @@ -7,6 +7,7 @@ Slice, Wrap, ) +from unitxt.processors import AddPrefix, GetSQL from unitxt.test_utils.operators import check_operator from tests.utils import UnitxtTestCase @@ -113,3 +114,25 @@ def test_chunk(self): inputs = [{"x": [0, 1, 2]}, {"x": [0, 1]}, {"x": [3]}] targets = [{"x": [[0, 1], [2]]}, {"x": [[0, 1]]}, {"x": [[3]]}] check_operator(operator=operator, inputs=inputs, targets=targets, tester=self) + + def test_add_prefix(self): + operator = AddPrefix(field="text", prefix="Hello ") + inputs = [{"text": "World"}, {"text": "Hello there"}, {"text": " Hello again"}] + targets = [ + {"text": "Hello World"}, + {"text": "Hello there"}, + {"text": "Hello again"}, + ] + check_operator(operator=operator, inputs=inputs, targets=targets, tester=self) + + def test_get_sql_with_simple_query(self): + operator = GetSQL(field="text") + inputs = [{"text": "SELECT * FROM table;"}] + targets = [{"text": "SELECT * FROM table"}] + check_operator(operator=operator, inputs=inputs, targets=targets, tester=self) + + def test_get_sql_with_code_block(self): + operator = GetSQL(field="text") + inputs = [{"text": "```SELECT id FROM table```"}] + targets = [{"text": "SELECT id FROM table"}] + check_operator(operator=operator, inputs=inputs, targets=targets, tester=self)