Skip to content

Commit ef7f812

Browse files
aothmsGhesselink
andauthored
Attempts at integration into VS (#145)
* Fixes * Update validation_results.py Co-authored-by: Geert Hesselink <[email protected]> * fix import error apps.py from datamodel * delete redundant closing bracket --------- Co-authored-by: Geert Hesselink <[email protected]> Co-authored-by: Ghesselink <[email protected]>
1 parent 71384aa commit ef7f812

File tree

7 files changed

+38
-25
lines changed

7 files changed

+38
-25
lines changed

features/environment.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ def get_validation_outcome_hash(obj):
7171

7272
def after_feature(context, feature):
7373
execution_mode = context.config.userdata.get('execution_mode')
74-
execution_mode = 'ExecutionMode.PRODUCTION'
7574
if execution_mode and execution_mode == 'ExecutionMode.PRODUCTION': # DB interaction only needed during production run, not in testing
7675
from validation_results import OutcomeSeverity, ModelInstance, ValidationTask
76+
7777
def reduce_db_outcomes(feature_outcomes):
7878

7979
failed_outcomes = [outcome for outcome in feature_outcomes if outcome.severity in [OutcomeSeverity.WARNING, OutcomeSeverity.ERROR]]

features/steps/givens/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import sys
22
import os
33
from pathlib import Path
4-
current_script_dir = os.path.dirname(os.path.abspath(__file__))
5-
sys.path.append(str(Path(current_script_dir).parent.parent.parent))
64
from validation_results import ValidationOutcome
75

86
OutcomeSeverity = ValidationOutcome.OutcomeSeverity

features/steps/steps/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import sys
22
import os
33
from pathlib import Path
4-
current_script_dir = os.path.dirname(os.path.abspath(__file__))
5-
sys.path.append(str(Path(current_script_dir).parent.parent.parent))
64
from validation_results import ValidationOutcome
75

86
OutcomeSeverity = ValidationOutcome.OutcomeSeverity

features/steps/thens/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import sys
22
import os
33
from pathlib import Path
4-
current_script_dir = os.path.dirname(os.path.abspath(__file__))
5-
sys.path.append(str(Path(current_script_dir).parent.parent))
64
from validation_results import ValidationOutcome
75

86
OutcomeSeverity = ValidationOutcome.OutcomeSeverity

features/steps/validation_handling.py

-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
import itertools
1111
from operator import attrgetter
1212
import ast
13-
current_script_dir = os.path.dirname(os.path.abspath(__file__))
14-
sys.path.append(str(Path(current_script_dir).parent.parent))
15-
1613
from validation_results import ValidationOutcome, OutcomeSeverity, ValidationOutcomeCode
1714

1815
from behave.runner import Context

main.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,13 @@ def run(filename, rule_type=RuleType.ALL, with_console_output=False, execution_m
6262

6363
# If this is a test file from the repository filter only the relevant scenarios
6464
feature_filter = []
65-
try:
66-
rule_code = os.path.basename(filename).split('-')[1].strip().upper()
67-
if re.match(r'[A-Z]{3}[0-9]{3}', rule_code):
68-
feature_filter = ["-i", rule_code]
69-
except Exception as e:
70-
print(e)
65+
if execution_mode != ExecutionMode.PRODUCTION:
66+
bfn = os.path.basename(filename)
67+
parts = bfn.split('-')
68+
if len(parts) >= 2:
69+
rule_code = parts[1].strip().upper()
70+
if re.match(r'[A-Z]{3}[0-9]{3}', rule_code):
71+
feature_filter = ["-i", rule_code]
7172

7273
if with_console_output:
7374
# Sometimes it's easier to see what happens exactly on the console output
@@ -81,6 +82,11 @@ def run(filename, rule_type=RuleType.ALL, with_console_output=False, execution_m
8182
],
8283
cwd=cwd
8384
)
85+
86+
kwargs = {}
87+
if execution_mode == ExecutionMode.TESTING:
88+
# Only capture output in testing mode
89+
kwargs['capture_output'] = True
8490

8591
proc = subprocess.run(
8692
[
@@ -90,8 +96,7 @@ def run(filename, rule_type=RuleType.ALL, with_console_output=False, execution_m
9096
"--define", f"execution_mode={execution_mode}",
9197
"-f", "json", "-o", jsonfn # save to json file
9298
],
93-
cwd=cwd, capture_output=True
94-
)
99+
cwd=cwd, **kwargs)
95100

96101
if execution_mode == ExecutionMode.TESTING:
97102
with open(jsonfn) as f:

validation_results.py

+24-7
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,33 @@
55
import django
66
from django.core.management import call_command
77

8-
current_script_dir = os.path.dirname(os.path.abspath(__file__))
9-
sys.path.append(str(Path(current_script_dir).parent.parent))
8+
# @todo importing from random directories is a security hazard, this should be properly passed as a configuration param
9+
current_script_dir = Path(os.path.dirname(os.path.abspath(__file__)))
10+
sys.path.insert(0, str(current_script_dir.parent.parent.parent.parent))
11+
12+
try:
13+
import apps.ifc_validation_models as ifc_validation_models
14+
except:
15+
import ifc_validation_models
16+
17+
if Path(ifc_validation_models.__file__).parent == current_script_dir / 'ifc_validation_models':
18+
# we are using our own submodule
19+
try:
20+
ifc_validation_models.apps.IfcValidationModelsConfig.name = 'ifc_validation_models'
21+
except:
22+
from ifc_validation_models import apps
23+
apps.IfcValidationModelsConfig.name = 'ifc_validation_models'
24+
os.environ['DJANGO_SETTINGS_MODULE'] = 'ifc_validation_models.independent_worker_settings'
25+
else:
26+
os.environ['DJANGO_SETTINGS_MODULE'] = 'apps.ifc_validation_models.dependent_worker_settings'
1027

11-
import ifc_validation_models.apps
12-
13-
ifc_validation_models.apps.IfcValidationModelsConfig.name = 'ifc_validation_models'
14-
os.environ['DJANGO_SETTINGS_MODULE'] = 'ifc_validation_models.independent_worker_settings'
1528
django.setup()
1629

17-
from ifc_validation_models.models import ValidationOutcome, ModelInstance, ValidationTask
30+
try:
31+
from apps.ifc_validation_models.models import ValidationOutcome, ModelInstance, ValidationTask
32+
except:
33+
from ifc_validation_models.models import ValidationOutcome, ModelInstance, ValidationTask
34+
1835
OutcomeSeverity = ValidationOutcome.OutcomeSeverity
1936
ValidationOutcomeCode = ValidationOutcome.ValidationOutcomeCode
2037

0 commit comments

Comments
 (0)