Debian Codegraph @

src/ifcbimtester/bimtester/features/steps/classification/en.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 json
20 from behave import step
21
22 from bimtester import util
23 from bimtester.ifc import IfcStore
24 from bimtester.lang import _
25
26
27 def get_classification(name):
28 classifications = [c for c in IfcStore.file.by_type("IfcClassification") if c.Name == name]
29 if len(classifications) != 1:
30 assert False, f'The classification "{name}" was not found'
31 return classifications[0]
32
33
34 @step('The classification "{name}" must be used')
35 def step_impl(context, name):
36 get_classification(name)
37
38
39 @step('The classification "{name}" is published by "{source}"')
40 def step_impl(context, name, source):
41 util.assert_attribute(get_classification(name), "Source", source)
42
43
44 @step('The classification "{name}" is the edition "{edition}" on "{edition_date}"')
45 def step_impl(context, name, edition, edition_date):
46 element = get_classification(name)
47 util.assert_attribute(element, "Edition", edition)
48 util.assert_attribute(element, "EditionDate", edition_date)
49
50
51 @step('The classification "{name}" has the description "{description}"')
52 def step_impl(context, name, description):
53 util.assert_attribute(get_classification(name), "Description", description)
54
55
56 @step('The classification "{name}" is referenced by the website "{location}"')
57 def step_impl(context, name, location):
58 util.assert_attribute(get_classification(name), "Location", location)
59
60
61 @step('The classification "{name}" has a hierarchy denoted by the tokens "{tokens}"')
62 def step_impl(context, name, tokens):
63 try:
64 tokens = json.loads(tokens)
65 except:
66 assert False, _("Tokens {} are not specified as a JSON list").format(tokens)
67 util.assert_attribute(get_classification(name), "ReferenceTokens", tokens)
68
69
70 @step('The element "{guid}" is classified as a "{identification}" with name "{reference_name}"')
71 def step_impl(context, guid, identification, reference_name):
72 element = util.assert_guid(IfcStore.file, guid)
73 if not hasattr(element, "HasAssociations") or not element.HasAssociations:
74 assert False, _("The element {} has no associations.").format(element)
75 references = [a.RelatingClassification for a in element.HasAssociations if a.is_a("IfcRelAssociatesClassification")]
76 if not references:
77 assert False, _("The element {element} has no associated classification references.").format(element)
78 is_success = False
79 for reference in references:
80 try:
81 util.assert_attribute(reference, "Identification", identification)
82 util.assert_attribute(reference, "Name", reference_name)
83 is_success = True
84 except:
85 pass
86 if not is_success:
87 assert False, _(
88 "No classification references met the requirement for an identification {} and name {} for the element {}. The references we found were: {}"
89 ).format(identification, reference_name, element, references)