Fixed ifctester tests by the latest ids schema #3458

Commented out tests involving minOccurs and maxOccurs until https://github.com/buildingSMART/IDS/issues/144 gets resolved.
This commit is contained in:
Andrej730
2023-07-21 15:32:59 +05:00
parent 08756a24a4
commit 630ac7250a
3 changed files with 45 additions and 26 deletions
+9 -4
View File
@@ -26,12 +26,14 @@ import ifctester
import test_facet
import test_ids
import numpy as np
from pathlib import Path
from xml.dom.minidom import parseString
from ifctester import ids
from ifcopenshell import validate
outdir = "build"
# Just for aesthetics so we don't keep on getting brand new GlobalIds on each generation
def regenerate_guids(ifc):
ns = uuid.UUID("b59aa156-82a4-4b4c-a6e5-3d04a0236af9")
@@ -183,7 +185,7 @@ test_ids.run = IdsDocGenerator()
pytest.main(["-p", "no:pytest-blender"])
for facet, testcases in test_facet.run.testcases.items():
with open(os.path.join(outdir, f"testcases-{facet}.md"), "w") as f:
with open(os.path.join(outdir, f"testcases-{facet}.md"), "w", encoding="utf-8") as f:
write = functools.partial(print, file=f)
write(f"# {facet.capitalize()} testcases")
write()
@@ -207,7 +209,7 @@ for facet, testcases in test_facet.run.testcases.items():
)
write()
with open(os.path.join(outdir, f"testcases-ids.md"), "w") as f:
with open(os.path.join(outdir, f"testcases-ids.md"), "w", encoding="utf-8") as f:
write = functools.partial(print, file=f)
write(f"# IDS integration testcases")
write()
@@ -283,13 +285,16 @@ spec.requirements.append(
ifctester.ids.Property(
propertySet="Pset_WallCommon",
name="FireRating",
measure="IfcLabel",
datatype="IfcLabel",
value=restriction,
instructions="Fire rating is specified using the Fire Resistance Level as defined in the Australian National Construction Code (NCC) 2019. Valid examples include -/-/-, -/120/120, and 60/60/60",
)
)
specs.to_xml(os.path.join(outdir, "library", "sample.ids"))
ids_path = Path(outdir) / "library" / "sample.ids"
if not ids_path.parent.exists():
ids_path.parent.mkdir()
specs.to_xml(str(ids_path))
# Create sample model
model = ifcopenshell.file()
+8 -7
View File
@@ -201,7 +201,7 @@ class TestEntity:
run(
"Entities can be specified as a XSD regex pattern 2/2",
facet=facet,
inst=ifc.createIfcWallType(),
inst=ifc.createIfcWallType(PredefinedType="USERDEFINED"),
expected=True,
)
@@ -255,12 +255,13 @@ class TestAttribute:
facet = Attribute(name="Name")
element = ifc.createIfcWall(Name="Foobar")
run("A required facet checks all parameters as normal", facet=facet, inst=element, expected=True)
facet = Attribute(name="Name", minOccurs=0, maxOccurs=0)
run("A prohibited facet returns the opposite of a required facet", facet=facet, inst=element, expected=False)
facet = Attribute(name="Name", minOccurs=0)
run("An optional facet always passes regardless of outcome 1/2", facet=facet, inst=element, expected=True)
facet = Attribute(name="Rabbit", minOccurs=0)
run("An optional facet always passes regardless of outcome 2/2", facet=facet, inst=element, expected=True)
# facet = Attribute(name="Name", minOccurs=0, maxOccurs=0)
# run("A prohibited facet returns the opposite of a required facet", facet=facet, inst=element, expected=False)
# facet = Attribute(name="Name", minOccurs=0)
# run("An optional facet always passes regardless of outcome 1/2", facet=facet, inst=element, expected=True)
# facet = Attribute(name="Rabbit", minOccurs=0)
# run("An optional facet always passes regardless of outcome 2/2", facet=facet, inst=element, expected=True)
ifc = ifcopenshell.file()
facet = Attribute(name="Name")
+28 -15
View File
@@ -116,7 +116,7 @@ class TestIds:
specs = ids.Ids(title="Title")
spec = ids.Specification(name="Name")
spec.applicability.append(ids.Entity(name="IFCWALL"))
spec.requirements.append(ids.Attribute(name="Name", value="Waldo"))
spec.requirements.append(name_attr := ids.Attribute(name="Name", value="Waldo"))
specs.specifications.append(spec)
assert "http://standards.buildingsmart.org/IDS" in specs.to_string()
assert spec.status == None
@@ -167,30 +167,43 @@ class TestIds:
spec.maxOccurs = "unbounded"
model = ifcopenshell.file()
wall = model.createIfcWall(Name="Waldo")
spec.requirements.append(ids.Attribute(name="Description", value="Foobar"))
spec.requirements.append(description_attr := ids.Attribute(name="Description", value="Foobar"))
run("A specification passes only if all requirements pass 1/2", specs, model, False, [wall], [wall])
wall.Description = "Foobar"
run("A specification passes only if all requirements pass 2/2", specs, model, True, [wall])
spec.requirements[1].minOccurs = 0
wall.Description = None
run("Specification optionality and facet optionality can be combined", specs, model, True, [wall])
# optional attribute
# description_attr.minOccurs = 0
# description_attr.maxOccurs = "unbounded"
# wall.Description = None
# run("Specification optionality and facet optionality can be combined", specs, model, True, [wall])
spec.minOccurs = 0
spec.maxOccurs = 0
spec.requirements[0].minOccurs = 0
spec.requirements[0].maxOccurs = 0
spec.requirements[1].minOccurs = 0
spec.requirements[1].maxOccurs = 0
wall.Name = "Waldo"
wall.Description = "Foobar"
run("A prohibited specification and a prohibited facet results in a double negative", specs, model, True, [wall])
# double negative / required attributes
# spec.minOccurs = 0
# spec.maxOccurs = 0
# name_attr.minOccurs = 0
# name_attr.maxOccurs = 0
# description_attr.minOccurs = 0
# description_attr.maxOccurs = 0
# wall.Name = "Waldo"
# wall.Description = "Foobar"
# run("A prohibited specification and a prohibited facet results in a double negative", specs, model, True, [wall])
# specs independency
specs = ids.Ids(title="Title")
spec = ids.Specification(name="Name")
spec.applicability.append(ids.Entity(name="IFCWALL"))
spec.requirements.append(ids.Attribute(name="Description", value="Foobar"))
specs.specifications.append(spec)
spec = ids.Specification(name="Name")
spec.applicability.append(ids.Entity(name="IFCWALL"))
spec.requirements.append(ids.Attribute(name="Name", value="Waldo"))
specs.specifications.append(spec)
wall2 = model.createIfcWall(Name="Waldo")
wall.Name = "Waldo"
wall.Description = "Foobar"
wall2 = model.createIfcWall(Name="Waldo", Description="Foobar")
run("Multiple specifications are independent of one another", specs, model, True, [wall, wall2])
def test_creating_multiple_specifications(self):