Fix #4893. IfcTester now requires lowercase booleans or 0/1.

This changed on May 5: https://github.com/buildingSMART/IDS/issues/290
This commit is contained in:
Dion Moult
2024-06-20 09:52:45 +10:00
parent fcf2c37432
commit 030119fd0e
2 changed files with 19 additions and 9 deletions
+2 -2
View File
@@ -39,9 +39,9 @@ def cast_to_value(from_value, to_value):
# We do not cast to int because 42.0 == 42 and 42.3 != 42
return float(from_value)
elif target_type == "bool":
if from_value == "TRUE":
if from_value in ("true", "1"):
return True
elif from_value == "FALSE":
elif from_value in ("false", "0"):
return False
return builtins.__dict__[target_type](from_value)
except ValueError:
+17 -7
View File
@@ -557,14 +557,19 @@ class TestAttribute:
expected=False,
)
facet = Attribute(name="IsMilestone", value="TRUE")
facet = Attribute(name="IsMilestone", value="true")
ifc = ifcopenshell.file()
element = ifc.createIfcTask(IsMilestone=False)
run("Booleans must be specified as uppercase strings 1/3", facet=facet, inst=element, expected=False)
facet = Attribute(name="IsMilestone", value="FALSE")
run("Booleans must be specified as uppercase strings 2/3", facet=facet, inst=element, expected=True)
run("Booleans must be specified as lowercase strings 1/3", facet=facet, inst=element, expected=False)
facet = Attribute(name="IsMilestone", value="false")
run("Booleans must be specified as lowercase strings 2/3", facet=facet, inst=element, expected=True)
facet = Attribute(name="IsMilestone", value="False")
run("Booleans must be specified as uppercase strings 2/3", facet=facet, inst=element, expected=False)
run("Booleans must be specified as lowercase strings 2/3", facet=facet, inst=element, expected=False)
facet = Attribute(name="IsMilestone", value="0")
run("Booleans can be specified as a 0 or 1 1/2", facet=facet, inst=element, expected=True)
facet = Attribute(name="IsMilestone", value="1")
run("Booleans can be specified as a 0 or 1 2/2", facet=facet, inst=element, expected=False)
facet = Attribute(name="EditionDate", value="2022-01-01")
ifc = ifcopenshell.file()
@@ -982,14 +987,19 @@ class TestProperty:
)
run("Floating point numbers are compared with a 1e-6 tolerance 4/4", facet=facet, inst=element, expected=False)
facet = Property(propertySet="Foo_Bar", baseName="Foo", value="TRUE", dataType="IFCBOOLEAN")
facet = Property(propertySet="Foo_Bar", baseName="Foo", value="true", dataType="IFCBOOLEAN")
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foo": ifc.createIfcBoolean(False)})
run("Booleans must be specified as uppercase strings 1/3", facet=facet, inst=element, expected=False)
facet = Property(propertySet="Foo_Bar", baseName="Foo", value="FALSE", dataType="IFCBOOLEAN")
facet = Property(propertySet="Foo_Bar", baseName="Foo", value="false", dataType="IFCBOOLEAN")
run("Booleans must be specified as uppercase strings 2/3", facet=facet, inst=element, expected=True)
facet = Property(propertySet="Foo_Bar", baseName="Foo", value="False", dataType="IFCBOOLEAN")
run("Booleans must be specified as uppercase strings 3/3", facet=facet, inst=element, expected=False)
facet = Property(propertySet="Foo_Bar", baseName="Foo", value="0", dataType="IFCBOOLEAN")
run("Booleans can be specified as as a 0 or 1 1/2", facet=facet, inst=element, expected=True)
facet = Property(propertySet="Foo_Bar", baseName="Foo", value="1", dataType="IFCBOOLEAN")
run("Booleans can be specified as as a 0 or 1 2/2", facet=facet, inst=element, expected=False)
facet = Property(propertySet="Foo_Bar", baseName="Foo", value="2022-01-01", dataType="IFCDATE")
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foo": ifc.createIfcDate("2022-01-01")})
run("Dates are treated as strings 1/2", facet=facet, inst=element, expected=True)