Debian Codegraph @

src/ifcbimtester/bimtester/features/environment.py

raw
1 # BIMTester - OpenBIM Auditing Tool
2 # Copyright (C) 2021 Dion Moult <[email protected]>
3 #
4 # This file is part of BIMTester.
5 #
6 # BIMTester is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Lesser General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # BIMTester is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Lesser General Public License for more details.
15 #
16 # You should have received a copy of the GNU Lesser General Public License
17 # along with BIMTester. If not, see <http://www.gnu.org/licenses/>.
18
19 import os
20 from behave.model import Scenario
21
22 from bimtester.ifc import IfcStore
23 from bimtester.lang import switch_locale
24 from logfile import append_logfile
25 from logfile import create_logfile
26 from zoom_smart_view import add_smartview
27 from zoom_smart_view import create_zoom_set_of_smartviews
28
29
30 this_path = os.path.dirname(os.path.realpath(__file__))
31
32
33 def before_all(context):
34
35 userdata = context.config.userdata
36 context.locale_dir = userdata.get("localedir")
37
38 if context.config.lang:
39 switch_locale(context.locale_dir, context.config.lang)
40
41 continue_after_failed = userdata.getbool("runner.continue_after_failed_step", True)
42 Scenario.continue_after_failed_step = continue_after_failed
43
44 # context.ifc_path = userdata.get("ifc", "")
45 context.ifcfile_basename = os.path.basename(os.path.splitext(userdata["ifc"])[0])
46 context.outpath = os.path.join(this_path, "..")
47 context.create_log = False
48 context.create_smartview = False
49
50 if context.create_log is True:
51 # set up log file
52 context.thelogfile = os.path.join(context.outpath, context.ifcfile_basename + ".log")
53 create_logfile(
54 context.thelogfile,
55 context.ifcfile_basename,
56 )
57
58
59 def before_feature(context, feature):
60
61 # https://github.com/IfcOpenShell/IfcOpenShell/issues/1910#issuecomment-989732600
62 # messages language, parsed by behaves lang argument
63 print("Messages language: {}".format(context.config.lang))
64 # features file language, set in feature files first line
65 # html report will use this too
66 print("Features language: {}".format(context.feature.language))
67
68 # if messages lang is not set use features lang
69 if context.config.lang == "" or context.config.lang is None:
70 context.config.lang = context.feature.language
71 print("Switch messages language to: {}".format(context.config.lang))
72 switch_locale(context.locale_dir, context.config.lang)
73
74 # TODO: refactor zoom smart view support into a decoupled module
75 if context.create_smartview is True:
76 smartview_name = context.ifcfile_basename + "_" + feature.name
77 context.smview_file = os.path.join(context.outpath, smartview_name + ".bcsv")
78 # print("SmartView file: {}".format(context.smview_file))
79 create_zoom_set_of_smartviews(
80 context.smview_file,
81 smartview_name,
82 )
83
84
85 def after_step(context, step):
86
87 if step.status == "failed" and context.create_log is True:
88 append_logfile(context, step)
89
90 if step.status == "failed" and context.create_smartview is True and hasattr(context, "falseguids"):
91 # print(context.falseguids)
92 add_smartview(context.smview_file, step.name, context.falseguids)