diff --git a/src/ifcbimtester/bimtester/features/environment.py b/src/ifcbimtester/bimtester/features/environment.py
index 5e5ef6303e..911b54b9df 100644
--- a/src/ifcbimtester/bimtester/features/environment.py
+++ b/src/ifcbimtester/bimtester/features/environment.py
@@ -1,12 +1,70 @@
+import os
+
from behave.model import Scenario
+from logfile import create_logfile
+from logfile import append_logfile
+from zoom_smart_view import append_zoom_smartview
+from zoom_smart_view import create_zoom_smartview
+
+
+this_path = os.path.dirname(os.path.realpath(__file__))
+
def before_all(context):
+
+ # get from userdata
userdata = context.config.userdata
context.ifcbasename = userdata["ifcbasename"]
context.localedir = userdata.get("localedir")
# do not break after a failed scenario
# https://community.osarch.org/discussion/comment/3328/#Comment_3328
- continue_after_failed = userdata.getbool("runner.continue_after_failed_step", True)
+ continue_after_failed = userdata.getbool(
+ "runner.continue_after_failed_step", True
+ )
Scenario.continue_after_failed_step = continue_after_failed
+
+ # keep out path
+ context.outpath = os.path.join(this_path, "..")
+
+ # since bimtesterfc directory in tmp is removed on every run
+ # neither log file nor sm file does need to be explicit removed first
+
+ # set up log file
+ context.thelogfile = os.path.join(
+ context.outpath,
+ context.ifcbasename + ".log"
+ )
+ create_logfile(
+ context.thelogfile,
+ context.ifcbasename,
+ )
+
+ # set up smart view file
+ context.smview_file = os.path.join(
+ context.outpath,
+ context.ifcbasename + ".bcsv"
+ )
+ create_zoom_smartview(
+ context.smview_file,
+ context.ifcbasename,
+ )
+
+
+def after_step(context, step):
+
+ if step.status == "failed":
+
+ # append log file
+ append_logfile(context, step)
+
+ # extend smart view
+ if hasattr(context, "falseguids"):
+ # print(context.falseguids)
+
+ append_zoom_smartview(
+ context.smview_file,
+ step.name,
+ context.falseguids
+ )
diff --git a/src/ifcbimtester/bimtester/features/logfile.py b/src/ifcbimtester/bimtester/features/logfile.py
new file mode 100644
index 0000000000..2528b3587b
--- /dev/null
+++ b/src/ifcbimtester/bimtester/features/logfile.py
@@ -0,0 +1,30 @@
+import json
+
+
+def create_logfile(thelogfile, ifcbasename):
+
+ logfile = open(thelogfile, "w")
+ logfile.write("BIMTester log file\n")
+ logfile.write("------------------\n\n")
+ logfile.write("ifc base file name: {}\n".format(ifcbasename))
+ logfile.close()
+
+
+def append_logfile(thecontext, step):
+
+ # step attributes (also these set by user) scope is the scenario
+ # https://behave.readthedocs.io/en/latest/thecontext_attributes.html
+ print("Step '{}' failed".format(step.name))
+
+ # log file
+ logfile = open(thecontext.thelogfile, "a")
+ logfile.write("\n\nStep '{}' failed\n".format(step.name))
+ if hasattr(thecontext, "falseelems"):
+ logfile.write("{}\n".format(
+ json.dumps(thecontext.falseelems, indent=4)
+ ))
+ if hasattr(thecontext, "falseprops"):
+ logfile.write("{}\n".format(
+ json.dumps(thecontext.falseprops, indent=4)
+ ))
+ logfile.close()
diff --git a/src/ifcbimtester/bimtester/features/zoom_smart_view.py b/src/ifcbimtester/bimtester/features/zoom_smart_view.py
new file mode 100644
index 0000000000..fa544f8871
--- /dev/null
+++ b/src/ifcbimtester/bimtester/features/zoom_smart_view.py
@@ -0,0 +1,138 @@
+import fileinput
+
+
+def create_zoom_smartview(sm_file, ifcbasename):
+
+ smf = open(sm_file, "w")
+ smf.write('\n')
+ smf.write("\n")
+ smf.write(" 5\n")
+ smf.write(" Win - Version: ")
+ # next line belongs to last, because of line length
+ smf.write("3.4 (build 3.4.13.559)\n")
+ smf.write("\n")
+ smf.write("\n")
+ smf.write("\n")
+ smf.write(" \n")
+ smf.write(" BIMTester {}\n".format(ifcbasename))
+ smf.write(" \n")
+ smf.write(" a2ddfaf7-97f2-4519-aabd-f2d94f6b4d6b\n")
+ smf.write(" 2020-10-30T13:23:30")
+ # next line belongs to last, because of line length
+ smf.write("\n")
+ smf.write(" \n")
+ smf.write(" \n")
+ smf.write(" \n")
+ smf.write("\n")
+ smf.close()
+
+
+def append_zoom_smartview(sm_file, step_name, false_elements_guid):
+
+ # build the smartview string
+ smview_string = " \n"
+ smview_string += (
+ " GUID filter, {}\n"
+ .format(step_name)
+ )
+ smview_string += "{}\n".format(each_smartview_string_before)
+ for guid in false_elements_guid:
+ smview_string += (
+ "{}{}{}\n".format(
+ rule_string_before,
+ guid,
+ rule_string_after)
+ )
+ smview_string += "{}\n".format(each_smartview_string_after)
+
+ # insert smartview string into file
+ theline = " "
+ newtext = smview_string + theline
+ for line in fileinput.FileInput(sm_file, inplace=True):
+ # the print replaces the line in the file
+ # and add the line afterwards
+ print(line.replace(theline, newtext), end="")
+
+
+each_smartview_string_title = """
+ Filter GUID
+ """
+
+
+each_smartview_string_before = """ bernd@bimstatik.ch
+ 2020-10-30T13:18:45
+ bernd@bimstatik.ch
+ 2020-10-30T13:23:30
+ 15fda94f-b4bf-43be-8ef4-15d3121137e1
+
+
+ Any
+
+ None
+ None
+ None
+ None
+ None
+
+
+ Is
+
+
+
+ AddSetColored
+ 187
+ 187
+ 187
+
+
+
+ Any
+
+ None
+ None
+ None
+ None
+ None
+
+
+ Is
+
+
+
+ SetTransparent
+
+ """
+
+
+each_smartview_string_after = """
+
+ None
+ None
+ 0
+
+ """
+
+
+rule_string_before = """
+ Any
+
+ GUID
+ Summary
+ Summary
+ StringValue
+ None
+
+
+ Is
+ """
+
+
+rule_string_after = """
+
+
+ SetColored
+ 255
+ 10
+ 10
+
+ """