-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
90 additions
and
8 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
...ata_factory_testing_framework/exceptions/variable_being_evaluated_does_not_exist_error.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class VariableBeingEvaluatedDoesNotExistError(Exception): | ||
def __init__(self, variable_name): | ||
super().__init__(f"Variable being evaluated does not exist: {variable_name}") | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/python/data_factory_testing_framework/models/activities/set_variable_activity.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from data_factory_testing_framework.generated.models import SetVariableActivity, ControlActivity | ||
from data_factory_testing_framework.models.state.pipeline_run_state import PipelineRunState | ||
|
||
|
||
class SetVariableActivity: | ||
|
||
def evaluate(self: SetVariableActivity, state: PipelineRunState): | ||
super(ControlActivity, self).evaluate(state) | ||
|
||
if self.variable_name == "pipelineReturnValue": | ||
return self | ||
|
||
state.set_variable(self.variable_name, self.value.evaluate(state)) | ||
|
||
return self | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/python/tests/models/activities/test_set_variable_activity.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import pytest | ||
|
||
from data_factory_testing_framework.exceptions.variable_being_evaluated_does_not_exist_error import \ | ||
VariableBeingEvaluatedDoesNotExistError | ||
from data_factory_testing_framework.generated.models import SetVariableActivity, DataFactoryElement | ||
from data_factory_testing_framework.models.base.pipeline_run_variable import PipelineRunVariable | ||
from data_factory_testing_framework.models.state.pipeline_run_state import PipelineRunState | ||
from data_factory_testing_framework.models.test_framework import TestFramework | ||
|
||
|
||
class TestSetVariableActivity: | ||
|
||
def test_when_string_variable_evaluated_then_state_variable_should_be_set(self): | ||
# Arrange | ||
test_framework = TestFramework() | ||
variable_name = "TestVariable" | ||
variable = PipelineRunVariable[str](variable_name, "") | ||
set_variable_activity = SetVariableActivity( | ||
name="SetVariableActivity", | ||
variable_name=variable_name, | ||
value=DataFactoryElement("TestValue") | ||
) | ||
state = PipelineRunState() | ||
state.variables.append(variable) | ||
|
||
# Act | ||
set_variable_activity.evaluate(state) | ||
|
||
# Assert | ||
assert variable.value == "TestValue" | ||
|
||
def test_when_unknown_variable_evaluated_then_should_raise_exception(self): | ||
# Arrange | ||
test_framework = TestFramework() | ||
variable_name = "TestVariable" | ||
set_variable_activity = SetVariableActivity( | ||
name="SetVariableActivity", | ||
variable_name=variable_name, | ||
value=DataFactoryElement("TestValue") | ||
) | ||
state = PipelineRunState() | ||
|
||
# Act | ||
with pytest.raises(VariableBeingEvaluatedDoesNotExistError) as exception_info: | ||
set_variable_activity.evaluate(state) | ||
|
||
# Assert | ||
assert exception_info.value.args[0] == "Variable being evaluated does not exist: TestVariable" |