mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 22:50:21 +00:00
Fix #3038. Fix #3039. Selector should default to none instead for throwing errors if the query doesn't have a result.
This commit is contained in:
@@ -255,6 +255,8 @@ class Selector:
|
|||||||
value = element
|
value = element
|
||||||
for key in keys:
|
for key in keys:
|
||||||
key = key.strip()
|
key = key.strip()
|
||||||
|
if value is None:
|
||||||
|
return
|
||||||
if key == "type":
|
if key == "type":
|
||||||
value = ifcopenshell.util.element.get_type(value)
|
value = ifcopenshell.util.element.get_type(value)
|
||||||
elif key in ("material", "mat"):
|
elif key in ("material", "mat"):
|
||||||
@@ -302,7 +304,10 @@ class Selector:
|
|||||||
value = value.get(key, None)
|
value = value.get(key, None)
|
||||||
elif isinstance(value, (list, tuple)): # If we use regex
|
elif isinstance(value, (list, tuple)): # If we use regex
|
||||||
if key.isnumeric():
|
if key.isnumeric():
|
||||||
value = value[int(key)]
|
try:
|
||||||
|
value = value[int(key)]
|
||||||
|
except IndexError:
|
||||||
|
return
|
||||||
else:
|
else:
|
||||||
results = []
|
results = []
|
||||||
for v in value:
|
for v in value:
|
||||||
|
|||||||
@@ -56,6 +56,23 @@ class TestGetElementValue(test.bootstrap.IFC4):
|
|||||||
# Provide shortform for convenience
|
# Provide shortform for convenience
|
||||||
assert subject.get_element_value(element, "mat.i.Name") == ["L1", "L2"]
|
assert subject.get_element_value(element, "mat.i.Name") == ["L1", "L2"]
|
||||||
|
|
||||||
|
def test_selecting_a_query_that_fails_silently(self):
|
||||||
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||||
|
assert subject.get_element_value(element, "material.item.Name.0") is None
|
||||||
|
|
||||||
|
def test_selceting_a_list_item_that_fails_silently(self):
|
||||||
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||||
|
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
|
||||||
|
material2 = ifcopenshell.api.run("material.add_material", self.file, name="CON02")
|
||||||
|
material_set = ifcopenshell.api.run(
|
||||||
|
"material.add_material_set", self.file, name="FOO", set_type="IfcMaterialLayerSet"
|
||||||
|
)
|
||||||
|
layer = ifcopenshell.api.run("material.add_layer", self.file, layer_set=material_set, material=material)
|
||||||
|
layer.Name = "L1"
|
||||||
|
ifcopenshell.api.run("material.assign_material", self.file, product=element, material=material_set)
|
||||||
|
assert subject.get_element_value(element, "material.item.Name.0") == "L1"
|
||||||
|
assert subject.get_element_value(element, "material.item.Name.1") is None
|
||||||
|
|
||||||
|
|
||||||
class TestSelector(test.bootstrap.IFC4):
|
class TestSelector(test.bootstrap.IFC4):
|
||||||
def test_selecting_by_class(self):
|
def test_selecting_by_class(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user