File tree Expand file tree Collapse file tree 3 files changed +35
-0
lines changed
appslab_modules/steps/execute_function Expand file tree Collapse file tree 3 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+
2+ class ExecuteFunction :
3+ def __init__ (self , function :callable ):
4+ if function == None :
5+ raise ValueError ("Function is None" )
6+ self .function = function
7+
8+ def process (self , item ):
9+ return self .function (item )
Original file line number Diff line number Diff line change 1+ name : execute_function
2+ module_description : " Module that allow the execute of a user defined function."
Original file line number Diff line number Diff line change 1+ import unittest
2+ from __init__ import ExecuteFunction
3+
4+ class TestExecuteFunction (unittest .TestCase ):
5+
6+ def test_load_no_function (self ):
7+ """Test loading with no function."""
8+ with self .assertRaises (ValueError ):
9+ ps = ExecuteFunction (None )
10+
11+ def test_execute (self ):
12+ """Test successfull function execution."""
13+
14+ def my_function (item ):
15+ return f"Function executed with { item } "
16+
17+ input_data = '{"test_key": "test_val"}'
18+
19+ ps = ExecuteFunction (my_function )
20+ out = ps .process (input_data )
21+ self .assertEqual (out , my_function (input_data ))
22+
23+ if __name__ == '__main__' :
24+ unittest .main ()
You can’t perform that action at this time.
0 commit comments