From d2a708fcc4e9ed9a538dd04d08a515835d9dc161 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Fri, 10 May 2024 17:46:07 +0500 Subject: [PATCH] fix bug in ifc2x3 tests bootstrap it was creating new applications and users every time `ifcopenshell.api.owner.settings.get_user` or `ifcopenshell.api.owner.settings.get_application` was called --- src/ifcopenshell-python/test/bootstrap.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/ifcopenshell-python/test/bootstrap.py b/src/ifcopenshell-python/test/bootstrap.py index 1603fcdb26..678629cb28 100644 --- a/src/ifcopenshell-python/test/bootstrap.py +++ b/src/ifcopenshell-python/test/bootstrap.py @@ -20,6 +20,7 @@ import pytest import ifcopenshell import ifcopenshell.api import ifcopenshell.api.owner.settings +import functools class IFC4X3: @@ -46,7 +47,14 @@ class IFC2X3: @pytest.fixture(autouse=True) def setup(self): self.file: ifcopenshell.file = ifcopenshell.api.run("project.create_file", version="IFC2X3") - ifcopenshell.api.owner.settings.get_user = lambda ifc: ifc.createIfcPersonAndOrganization() - ifcopenshell.api.owner.settings.get_application = lambda ifc: ifc.createIfcApplication() + + @functools.cache + def get_user(ifc: ifcopenshell.file): + person = ifc.create_entity("IfcPerson") + organization = ifc.create_entity("IfcOrganization") + return ifc.create_entity("IfcPersonAndOrganization", ThePerson=person, TheOrganization=organization) + + ifcopenshell.api.owner.settings.get_user = get_user + ifcopenshell.api.owner.settings.get_application = functools.cache(lambda ifc: ifc.createIfcApplication()) ifcopenshell.api.pre_listeners = {} ifcopenshell.api.post_listeners = {}