Option to bypass storing types when opening model

This commit is contained in:
Thomas Krijnen
2025-10-24 12:06:59 +02:00
parent a6d20c0cc4
commit 0494bd9677
8 changed files with 174 additions and 33 deletions
@@ -23,6 +23,11 @@ import pytest
import ifcopenshell
import tempfile
try:
import psutil
except ImportError:
psutil = None
fn = os.path.join(os.path.dirname(__file__), "fixtures/ColumnPSetsOfSets.ifc")
@@ -32,18 +37,40 @@ def test_stream():
"value": ({"ref": 136}, {"ref": 138}),
}
def test_chunked_stream():
assert list(ifcopenshell.stream2(fn)) == list(ifcopenshell.stream2(fn, page_size=1024))
def test_mmaped_stream():
assert list(ifcopenshell.stream2(fn)) == list(ifcopenshell.stream2(fn, mmap=True))
def test_file():
f = ifcopenshell.open(fn)
assert f[139].RelatingPropertyDefinition.is_a("IfcPropertySetDefinitionSet")
assert {x.id() for x in f[139].RelatingPropertyDefinition[0]} == {136, 138}
def test_partial_open():
f = ifcopenshell.open(fn)
assert len(f.by_type("ifccartesianpoint"))
f = ifcopenshell.open(fn, bypass_types=("IfcRepresentationItem",))
assert len(f.by_type("ifccartesianpoint")) == 0
@pytest.mark.skipif(psutil is None, reason="psutil not installed")
def test_memusage_partial_open():
m0 = psutil.Process().memory_info().rss
f = ifcopenshell.open(fn)
m1 = psutil.Process().memory_info().rss
g = ifcopenshell.open(fn, bypass_types=("IfcRepresentationItem",))
m2 = psutil.Process().memory_info().rss
# arbitrary...
expected_ratio = 0.75
assert (m2 - m1) < (m1 - m0) * expected_ratio
def test_rocks():
with tempfile.TemporaryDirectory() as d:
rfn = os.path.join(d, os.path.basename(fn))