diff --git a/src/ifctester/ifctester/facet.py b/src/ifctester/ifctester/facet.py index f914b97256..28290f5dee 100644 --- a/src/ifctester/ifctester/facet.py +++ b/src/ifctester/ifctester/facet.py @@ -745,6 +745,8 @@ class Restriction: if other not in [cast_to_value(v, other) for v in value]: return False elif constraint == "pattern": + if not isinstance(other, str): + return False value = value if isinstance(value, list) else [value] for pattern in value: if re.compile(identities.translate_pattern(pattern)).fullmatch(other) is None: diff --git a/src/ifctester/test/test_facet.py b/src/ifctester/test/test_facet.py index ccda23b59b..d80bba3feb 100644 --- a/src/ifctester/test/test_facet.py +++ b/src/ifctester/test/test_facet.py @@ -376,11 +376,11 @@ class TestAttribute: ) ifc = ifcopenshell.file() - facet = Attribute(name="Name", value="♫") + facet = Attribute(name="Name", value="♫Don'tÄrgerhôtelЊет") run( "Non-ascii characters are treated without encoding", facet=facet, - inst=ifc.createIfcWall(Name="♫"), + inst=ifc.createIfcWall(Name="♫Don'tÄrgerhôtelЊет"), expected=True, ) @@ -911,8 +911,8 @@ class TestProperty: ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foo": "Baz"}) run("Specifying a value fails against different values", facet=facet, inst=element, expected=False) - facet = Property(propertySet="Foo_Bar", name="Foo", value="♫", measure="IfcLabel") - ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foo": "♫"}) + facet = Property(propertySet="Foo_Bar", name="Foo", value="♫Don'tÄrgerhôtelЊет", measure="IfcLabel") + ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foo": "♫Don'tÄrgerhôtelЊет"}) run("Non-ascii characters are treated without encoding", facet=facet, inst=element, expected=True) identifier = "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345" @@ -1595,6 +1595,12 @@ class TestRestriction: element.Name = "A5" run("Regex patterns can be used 3/3", facet=facet, inst=element, expected=False) + ifc = ifcopenshell.file() + restriction = Restriction(options={"pattern": ".*"}) + element = ifc.createIfcSurfaceStyleRefraction(RefractionIndex=42) + facet = Attribute(name="RefractionIndex", value=restriction) + run("Patterns only work on strings and nothing else", facet=facet, inst=element, expected=False) + ifc = ifcopenshell.file() restriction = Restriction(options={"length": 2}) facet = Attribute(name="Name", value=restriction)