diff --git a/docs/basic/state.md b/docs/basic/state.md index 1c19ce3e..301ecf91 100644 --- a/docs/basic/state.md +++ b/docs/basic/state.md @@ -32,6 +32,15 @@ state = PipelineRunState( ]) ``` +The following `RunParameterType` values are available: + +* `RunParameterType.Parameter` to set a pipeline parameter: `@pipeline().parameters.` +* `RunParameterType.Global` to set a global parameter: `@pipeline().globalParameters.` +* `RunParameterType.System` to set a system parameter: `@pipeline().` +* `RunParameterType.Dataset` to set a dataset: `@dataset().` +* `RunParameterType.LinkedService` to set a linked service: `@linkedService().` +* `RunParameterType.LibraryVariables` to set a library variable: `@pipeline().libraryVariables.` + ### Activity results In the scenario where an activity has an expression that references the output of another activity `activity('another_activity_name').output.some_field`, the `PipelineRunState` can be used to configure the output of the `another_activity_name` activity. diff --git a/src/data_factory_testing_framework/_expression_runtime/expression_runtime.py b/src/data_factory_testing_framework/_expression_runtime/expression_runtime.py index 5a3ba43b..5edf6836 100644 --- a/src/data_factory_testing_framework/_expression_runtime/expression_runtime.py +++ b/src/data_factory_testing_framework/_expression_runtime/expression_runtime.py @@ -64,6 +64,13 @@ def evaluate(self, expression: str, state: PipelineRunState) -> str: and not state._contains_parameter_with_type_and_name(RunParameterType.Global, property_name) ): raise ParameterNotFoundError(RunParameterType.Global, property_name) from e + elif ( + f"pipeline().libraryVariables.{property_name}" in expression + and not state._contains_parameter_with_type_and_name( + RunParameterType.LibraryVariables, property_name + ) + ): + raise ParameterNotFoundError(RunParameterType.LibraryVariables, property_name) from e elif ( f"pipeline().dataset.{property_name}" in expression and not state._contains_parameter_with_type_and_name(RunParameterType.Dataset, property_name) diff --git a/src/data_factory_testing_framework/_pythonnet/data_factory_testing_framework_expressions_evaluator.py b/src/data_factory_testing_framework/_pythonnet/data_factory_testing_framework_expressions_evaluator.py index e420adcb..8bcf7e64 100644 --- a/src/data_factory_testing_framework/_pythonnet/data_factory_testing_framework_expressions_evaluator.py +++ b/src/data_factory_testing_framework/_pythonnet/data_factory_testing_framework_expressions_evaluator.py @@ -16,6 +16,7 @@ def evaluate(expression: str, state: PipelineRunState) -> Union[str, int, float, parameters = { "globalParameters": {}, "parameters": {}, + "libraryVariables": {}, "dataset": {}, "linkedService": {}, } @@ -27,6 +28,8 @@ def evaluate(expression: str, state: PipelineRunState) -> Union[str, int, float, parameters["globalParameters"][parameter.name] = parameter.value elif parameter.type == RunParameterType.Pipeline: parameters["parameters"][parameter.name] = parameter.value + elif parameter.type == RunParameterType.LibraryVariables: + parameters["libraryVariables"][parameter.name] = parameter.value elif parameter.type == RunParameterType.Dataset: parameters["dataset"][parameter.name] = parameter.value elif parameter.type == RunParameterType.LinkedService: diff --git a/src/data_factory_testing_framework/state/_run_parameter_type.py b/src/data_factory_testing_framework/state/_run_parameter_type.py index 6b569bf9..d8dc794b 100644 --- a/src/data_factory_testing_framework/state/_run_parameter_type.py +++ b/src/data_factory_testing_framework/state/_run_parameter_type.py @@ -9,6 +9,7 @@ class RunParameterType(str, Enum, metaclass=CaseInsensitiveEnumMeta): Dataset = "Dataset" LinkedService = "LinkedService" System = "System" + LibraryVariables = "LibraryVariables" def __str__(self) -> str: """Get the string representation of the enum. diff --git a/tests/unit/functions/test_data_factory_testing_framework_expression_evaluator.py b/tests/unit/functions/test_data_factory_testing_framework_expression_evaluator.py index 365aa40d..e88c0b7a 100644 --- a/tests/unit/functions/test_data_factory_testing_framework_expression_evaluator.py +++ b/tests/unit/functions/test_data_factory_testing_framework_expression_evaluator.py @@ -75,6 +75,17 @@ "value", id="pipeline_global_parameters_reference", ), + p( + "@pipeline().libraryVariables.variable", + PipelineRunState( + parameters=[ + RunParameter(RunParameterType.LibraryVariables, "variable", "value"), + ] + ), + "@pipeline().libraryVariables.variable", + "value", + id="pipeline_library_variables_reference", + ), p( "@variables('variable')", PipelineRunState( @@ -724,6 +735,37 @@ def test_evaluate_system_variable_raises_exception_when_parameter_not_set() -> N assert str(exinfo.value) == "Parameter: 'RunId' of type 'RunParameterType.System' not found" +def test_evaluate_library_variable() -> None: + # Arrange + expression = "@pipeline().libraryVariables.variable" + expression_runtime = ExpressionRuntime() + state = PipelineRunState( + parameters=[ + RunParameter(RunParameterType.LibraryVariables, "variable", "value"), + ] + ) + + # Act + evaluated_value = expression_runtime.evaluate(expression, state) + + # Assert + assert evaluated_value == "value" + + +def test_evaluate_library_variable_raises_exception_when_parameter_not_set() -> None: + # Arrange + expression = "@pipeline().libraryVariables.variable" + expression_runtime = ExpressionRuntime() + state = PipelineRunState() + + # Act + with pytest.raises(ParameterNotFoundError) as exinfo: + expression_runtime.evaluate(expression, state) + + # Assert + assert str(exinfo.value) == "Parameter: 'variable' of type 'RunParameterType.LibraryVariables' not found" + + @pytest.mark.parametrize( ["json_expression", "accessor", "expected"], [ @@ -967,6 +1009,7 @@ def test_conditional_expression_with_branching( [ (RunParameterType.Pipeline, "pipeline().parameters"), (RunParameterType.Global, "pipeline().globalParameters"), + (RunParameterType.LibraryVariables, "pipeline().libraryVariables"), (RunParameterType.Dataset, "pipeline().dataset"), (RunParameterType.LinkedService, "pipeline().linkedService"), (RunParameterType.System, "pipeline()"), @@ -990,6 +1033,7 @@ def test_complex_expression_with_missing_parameter(run_parameter_type: RunParame "run_parameter_type, parameter_prefix", [ (RunParameterType.Global, "pipeline().globalParameters"), + (RunParameterType.LibraryVariables, "pipeline().libraryVariables"), (RunParameterType.Dataset, "pipeline().dataset"), (RunParameterType.LinkedService, "pipeline().linkedService"), (RunParameterType.System, "pipeline()"),