2020-07-27 18:38:13 +10:00
|
|
|
import ifcopenshell
|
2020-07-28 16:41:13 +10:00
|
|
|
import ifcopenshell.util.element
|
2021-02-02 16:37:14 +11:00
|
|
|
from bimtester.lang import _
|
2020-07-27 18:38:13 +10:00
|
|
|
|
|
|
|
|
|
2021-02-02 16:37:14 +11:00
|
|
|
def assert_guid(ifc, guid):
|
|
|
|
|
try:
|
|
|
|
|
return ifc.by_guid(guid)
|
|
|
|
|
except:
|
|
|
|
|
assert False, _("An element with the ID {} could not be found.").format(guid)
|
2020-11-01 19:22:49 +07:00
|
|
|
|
2020-07-28 16:41:13 +10:00
|
|
|
|
|
|
|
|
def assert_number(number):
|
|
|
|
|
try:
|
|
|
|
|
return float(number)
|
|
|
|
|
except ValueError:
|
2021-02-02 16:37:14 +11:00
|
|
|
assert False, _("A number should be specified, not {}").format(number)
|
2020-11-01 19:22:49 +07:00
|
|
|
|
2020-07-28 16:41:13 +10:00
|
|
|
|
2020-08-06 18:32:33 +10:00
|
|
|
def assert_type(element, ifc_class, is_exact=False):
|
|
|
|
|
if is_exact:
|
2021-02-02 16:37:14 +11:00
|
|
|
assert element.is_a() == ifc_class, _("The element {} is an {} instead of {}.").format(
|
2020-08-06 18:32:33 +10:00
|
|
|
element, element.is_a(), ifc_class
|
|
|
|
|
)
|
|
|
|
|
else:
|
2021-02-02 16:37:14 +11:00
|
|
|
assert element.is_a(ifc_class), _("The element {} is an {} instead of {}.").format(
|
2020-08-06 18:32:33 +10:00
|
|
|
element, element.is_a(), ifc_class
|
|
|
|
|
)
|
2020-11-01 19:22:49 +07:00
|
|
|
|
2020-08-06 18:32:33 +10:00
|
|
|
|
|
|
|
|
def assert_attribute(element, name, value=None):
|
2020-07-28 16:41:13 +10:00
|
|
|
if not hasattr(element, name):
|
2021-02-02 16:37:14 +11:00
|
|
|
assert False, _("The element {} does not have the attribute {}").format(element, name)
|
2020-08-06 18:32:33 +10:00
|
|
|
if not value:
|
|
|
|
|
if getattr(element, name) is None:
|
2021-02-02 16:37:14 +11:00
|
|
|
assert False, _("The element {} does not have a value for the attribute {}").format(element, name)
|
2020-09-10 17:43:30 +10:00
|
|
|
return getattr(element, name)
|
2020-08-06 18:32:33 +10:00
|
|
|
if value == "NULL":
|
|
|
|
|
value = None
|
2020-07-28 16:41:13 +10:00
|
|
|
actual_value = getattr(element, name)
|
2020-08-21 19:52:50 +10:00
|
|
|
if isinstance(value, list) and actual_value:
|
2020-08-06 18:32:33 +10:00
|
|
|
actual_value = list(actual_value)
|
2021-02-02 16:37:14 +11:00
|
|
|
assert actual_value == value, _('We expected a value of "{}" but instead got "{}" for the element {}').format(
|
2020-07-28 17:31:26 +10:00
|
|
|
value, actual_value, element
|
|
|
|
|
)
|
2020-11-01 19:22:49 +07:00
|
|
|
|
2020-07-28 16:41:13 +10:00
|
|
|
|
|
|
|
|
def assert_pset(element, pset_name, prop_name=None, value=None):
|
2020-07-28 17:31:26 +10:00
|
|
|
if value == "NULL":
|
|
|
|
|
value = None
|
2020-07-28 16:41:13 +10:00
|
|
|
psets = ifcopenshell.util.element.get_psets(site)
|
|
|
|
|
if pset_name not in psets:
|
2021-02-02 16:37:14 +11:00
|
|
|
assert False, _("The element {} does not have a property set named {}").format(element, pset_name)
|
2020-07-28 16:41:13 +10:00
|
|
|
if prop_name is None:
|
|
|
|
|
return psets[pset_name]
|
|
|
|
|
if prop_name not in psets[pset_name]:
|
2021-02-02 16:37:14 +11:00
|
|
|
assert False, _('The element {} does not have a property named "{}" in the pset "{}"').format(
|
2020-07-28 16:41:13 +10:00
|
|
|
element, prop_name, pset_name
|
|
|
|
|
)
|
|
|
|
|
if value is None:
|
|
|
|
|
return psets[pset_name][prop_name]
|
|
|
|
|
actual_value = psets[pset_name][prop_name]
|
2021-02-02 16:37:14 +11:00
|
|
|
assert actual_value == value, _('We expected a value of "{}" but instead got "{}" for the element {}').format(
|
2020-07-28 17:31:26 +10:00
|
|
|
value, actual_value, element
|
|
|
|
|
)
|
2020-12-16 08:33:39 +01:00
|
|
|
|
|
|
|
|
|
2021-02-02 16:37:14 +11:00
|
|
|
# TODO: what is this?
|
2020-12-21 10:31:05 +01:00
|
|
|
def assert_elements(
|
|
|
|
|
ifc_class,
|
|
|
|
|
elemcount,
|
|
|
|
|
falsecount,
|
|
|
|
|
falseelems,
|
|
|
|
|
message_all_falseelems,
|
|
|
|
|
message_some_falseelems,
|
|
|
|
|
message_no_elems,
|
2021-02-02 12:34:14 +11:00
|
|
|
parameter=None,
|
2020-12-21 10:31:05 +01:00
|
|
|
):
|
|
|
|
|
if elemcount > 0 and falsecount == 0:
|
|
|
|
|
return # Test OK
|
|
|
|
|
elif elemcount == 0:
|
2021-02-02 12:34:14 +11:00
|
|
|
assert False, message_no_elems.format(ifc_class=ifc_class)
|
2020-12-21 10:31:05 +01:00
|
|
|
elif falsecount == elemcount:
|
|
|
|
|
if parameter is None:
|
2021-02-02 12:34:14 +11:00
|
|
|
assert False, message_all_falseelems.format(elemcount=elemcount, ifc_class=ifc_class)
|
2020-12-21 10:31:05 +01:00
|
|
|
else:
|
2021-02-02 12:34:14 +11:00
|
|
|
assert False, message_all_falseelems.format(elemcount=elemcount, ifc_class=ifc_class, parameter=parameter)
|
2020-12-21 10:31:05 +01:00
|
|
|
elif falsecount > 0 and falsecount < elemcount:
|
|
|
|
|
if parameter is None:
|
2021-02-02 12:34:14 +11:00
|
|
|
assert False, message_some_falseelems.format(
|
|
|
|
|
falsecount=falsecount,
|
|
|
|
|
elemcount=elemcount,
|
|
|
|
|
ifc_class=ifc_class,
|
|
|
|
|
falseelems=falseelems,
|
2020-12-21 10:31:05 +01:00
|
|
|
)
|
|
|
|
|
else:
|
2021-02-02 12:34:14 +11:00
|
|
|
assert False, message_some_falseelems.format(
|
|
|
|
|
falsecount=falsecount,
|
|
|
|
|
elemcount=elemcount,
|
|
|
|
|
ifc_class=ifc_class,
|
|
|
|
|
falseelems=falseelems,
|
|
|
|
|
parameter=parameter,
|
2020-12-21 10:31:05 +01:00
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
assert False, _("Error in falsecount, something went wrong.")
|