Skip to content

Commit 7f3860b

Browse files
committed
util.attribute - add tests
1 parent d08756d commit 7f3860b

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# IfcOpenShell - IFC toolkit and geometry engine
2+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
3+
#
4+
# This file is part of IfcOpenShell.
5+
#
6+
# IfcOpenShell 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+
# IfcOpenShell 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 IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
18+
19+
import ifcopenshell
20+
import pytest
21+
import ifcopenshell.ifcopenshell_wrapper as W
22+
import ifcopenshell.util.attribute as subject
23+
24+
25+
def getattr_(ifc_class: str, attr_name: str) -> W.attribute:
26+
schema = ifcopenshell.schema_by_name("IFC4")
27+
declaration = schema.declaration_by_name(ifc_class).as_entity()
28+
assert declaration
29+
i = declaration.attribute_index(attr_name)
30+
attr = declaration.all_attributes()[i]
31+
return attr
32+
33+
34+
class TestGetPrimitiveType:
35+
def test_run(self):
36+
assert subject.get_primitive_type(getattr_("IfcWindow", "OverallHeight")) == "float"
37+
assert subject.get_primitive_type(getattr_("IfcRelVoidsElement", "RelatingBuildingElement")) == "entity"
38+
assert subject.get_primitive_type(getattr_("IfcPostalAddress", "Description")) == "string"
39+
assert subject.get_primitive_type(getattr_("IfcPostalAddress", "Purpose")) == "enum"
40+
assert subject.get_primitive_type(getattr_("IfcPostalAddress", "AddressLines")) == ("list", "string")
41+
42+
43+
class TestGetEnumItems:
44+
def test_run(self):
45+
assert subject.get_enum_items(getattr_("IfcPostalAddress", "Purpose")) == (
46+
"OFFICE",
47+
"SITE",
48+
"HOME",
49+
"DISTRIBUTIONPOINT",
50+
"USERDEFINED",
51+
)
52+
53+
54+
class TestGetSelectItems:
55+
def test_run(self):
56+
select_items = subject.get_select_items(getattr_("IfcLocalPlacement", "RelativePlacement"))
57+
assert type(select_items) is tuple
58+
assert len(select_items) == 2
59+
assert all(isinstance(i, W.declaration) for i in select_items)
60+
assert [i.name() for i in select_items] == ["IfcAxis2Placement2D", "IfcAxis2Placement3D"]

0 commit comments

Comments
 (0)