Skip to content

Commit

Permalink
Merge pull request #271 from buildingSMART/IVS117_outcome_massaging
Browse files Browse the repository at this point in the history
IVS-117 outcome massaging
  • Loading branch information
civilx64 authored Sep 10, 2024
2 parents aef5e4a + e460dad commit 5f85ebd
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions features/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,11 @@ def before_feature(context, feature):
severity=OutcomeSeverity.ERROR,
)
context.protocol_errors.append(validation_outcome)

context.gherkin_outcomes = context.protocol_errors


def before_scenario(context, scenario):
context.gherkin_outcomes = []
for protocol_error in context.protocol_errors:
context.gherkin_outcomes.append(protocol_error)
context.applicable = True

def before_step(context, step):
Expand All @@ -68,9 +67,14 @@ def get_validation_outcome_hash(obj):
def after_scenario(context, scenario):
# Given steps may introduce an arbitrary amount of stackframes.
# we need to clean them up before behave starts appending new ones.
old_outcomes = getattr(context, 'gherkin_outcomes', [])
while context._stack[0].get('@layer') == 'attribute':
context._pop()
# preserve the outcomes to be serialized to DB in after_feature()
context.gherkin_outcomes = old_outcomes


def after_feature(context, feature):
execution_mode = context.config.userdata.get('execution_mode')
if execution_mode and execution_mode == 'ExecutionMode.PRODUCTION': # DB interaction only needed during production run, not in testing
from validation_results import OutcomeSeverity, ModelInstance, ValidationTask
Expand All @@ -81,20 +85,15 @@ def reduce_db_outcomes(feature_outcomes):
if failed_outcomes:
unique_outcomes = set() # TODO __hash__ + __eq__ will be better
unique_objects = [obj for obj in failed_outcomes if get_validation_outcome_hash(obj) not in unique_outcomes and (unique_outcomes.add(get_validation_outcome_hash(obj)) or True)]
return unique_objects

yield from unique_objects
else:
outcome_counts = Counter(outcome.severity for outcome in context.gherkin_outcomes)

for severity in [OutcomeSeverity.PASSED, OutcomeSeverity.EXECUTED, OutcomeSeverity.NOT_APPLICABLE]:
if outcome_counts[severity] > 0:
for outcome in context.gherkin_outcomes:
if outcome.severity == severity:
return [outcome]

return []
yield next(outcome for outcome in context.gherkin_outcomes if outcome.severity == severity)
break

outcomes_to_save = reduce_db_outcomes(context.gherkin_outcomes)
outcomes_to_save = list(reduce_db_outcomes(context.gherkin_outcomes))

if outcomes_to_save and context.validation_task_id is not None:
retrieved_task = ValidationTask.objects.get(id=context.validation_task_id)
Expand Down

0 comments on commit 5f85ebd

Please sign in to comment.