-
Notifications
You must be signed in to change notification settings - Fork 22
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
86 additions
and
5 deletions.
There are no files selected for viewing
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
21 changes: 21 additions & 0 deletions
21
...a_factory_testing_framework/models/activities/control_activities/if_condition_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,21 @@ | ||
from typing import Callable, Generator | ||
|
||
from data_factory_testing_framework.generated.models import ForEachActivity, Activity, ControlActivity, \ | ||
IfConditionActivity | ||
from data_factory_testing_framework.models.state.pipeline_run_state import PipelineRunState | ||
|
||
|
||
class IfConditionActivity: | ||
|
||
def evaluate(self: IfConditionActivity, state: PipelineRunState): | ||
self.expression.evaluate(state) | ||
|
||
return super(ControlActivity, self).evaluate(state) | ||
|
||
def evaluate_control_activity_iterations(self: IfConditionActivity, state: PipelineRunState, evaluate_activities: Callable[[PipelineRunState], Generator[Activity, None, None]]): | ||
scoped_state = state.create_iteration_scope(None) | ||
activities = self.if_true_activities if self.expression.value else self.if_false_activities | ||
for activity in evaluate_activities(activities, scoped_state): | ||
yield activity | ||
|
||
state.add_scoped_activity_results_from_scoped_state(scoped_state) |
11 changes: 7 additions & 4 deletions
11
src/python/data_factory_testing_framework/models/expression.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
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
Empty file.
Empty file.
Empty file.
54 changes: 54 additions & 0 deletions
54
src/python/tests/models/activities/control_activities/test_if_condition_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,54 @@ | ||
import pytest | ||
|
||
from data_factory_testing_framework.generated.models import ForEachActivity, Expression, ExpressionType, \ | ||
SetVariableActivity, DataFactoryElement, IfConditionActivity | ||
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 TestIfConditionActivity: | ||
|
||
def test_when_evaluated_should_evaluate_expression(self): | ||
# Arrange | ||
activity = IfConditionActivity( | ||
name="IfConditionActivity", | ||
expression=Expression(type=ExpressionType.EXPRESSION, value="@equals(1, 1)")) | ||
|
||
# Act | ||
activity.evaluate(PipelineRunState()) | ||
|
||
# Assert | ||
# assert activity.expression.evaluated == True | ||
|
||
@pytest.mark.parametrize("expression_outcome,expected_activity_name", [(True, "setVariableActivity1"),(False, "setVariableActivity2")]) | ||
def test_when_evaluated_should_evaluate_correct_child_activities(self, expression_outcome, expected_activity_name): | ||
# Arrange | ||
test_framework = TestFramework() | ||
expression = "@equals(1, 1)" if expression_outcome else "@equals(1, 2)" | ||
activity = IfConditionActivity( | ||
name="IfConditionActivity", | ||
expression=Expression(type=ExpressionType.EXPRESSION, value=expression), | ||
if_true_activities=[ | ||
SetVariableActivity( | ||
name="setVariableActivity1", | ||
variable_name="variable", | ||
value="dummy") | ||
], | ||
if_false_activities=[ | ||
SetVariableActivity( | ||
name="setVariableActivity2", | ||
variable_name="variable", | ||
value="dummy") | ||
] | ||
) | ||
|
||
state = PipelineRunState() | ||
state.variables.append(PipelineRunVariable("variable", "")) | ||
|
||
# Act | ||
child_activities = list(test_framework.evaluate_activity(activity, state)) | ||
|
||
# Assert | ||
assert len(child_activities) == 1 | ||
assert child_activities[0].name == expected_activity_name |