mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-13 02:47:48 +00:00
rename test files to test_* prefix for pytest discovery and fix missing add_pset name arg
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
import itertools
|
||||
import os
|
||||
import weakref
|
||||
|
||||
import pytest
|
||||
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api.attribute
|
||||
import ifcopenshell.api.material
|
||||
import ifcopenshell.api.owner
|
||||
import ifcopenshell.api.project
|
||||
import ifcopenshell.api.pset
|
||||
import ifcopenshell.guid
|
||||
import ifcopenshell.template
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"args",
|
||||
itertools.product((0, 1), (0, 1), (0, 1), (0, 1, 2)),
|
||||
)
|
||||
def test_file_gc(args):
|
||||
do_run_api, do_delete_ref, file_first, api = args
|
||||
|
||||
f = ifcopenshell.file()
|
||||
if api == 0:
|
||||
inst = f.createIfcPerson()
|
||||
elif api in (1, 2):
|
||||
inst = f.createIfcSite()
|
||||
|
||||
r = weakref.ref(f)
|
||||
|
||||
if do_run_api:
|
||||
if api == 0:
|
||||
ifcopenshell.api.attribute.edit_attributes(
|
||||
f,
|
||||
product=inst,
|
||||
attributes={"FamilyName": "Bimson"},
|
||||
)
|
||||
elif api == 1:
|
||||
ifcopenshell.api.pset.add_pset(f, product=inst, name="ePSet_MapConversion")
|
||||
elif api == 2:
|
||||
pset = f.create_entity(
|
||||
"IfcPropertySet",
|
||||
**{
|
||||
"GlobalId": ifcopenshell.guid.new(),
|
||||
"OwnerHistory": ifcopenshell.api.owner.create_owner_history(f),
|
||||
"Name": "ePSet_MapConversion",
|
||||
},
|
||||
)
|
||||
f.create_entity(
|
||||
"IfcRelDefinesByProperties",
|
||||
**{
|
||||
"GlobalId": ifcopenshell.guid.new(),
|
||||
"OwnerHistory": ifcopenshell.api.owner.create_owner_history(f),
|
||||
"RelatedObjects": [inst],
|
||||
"RelatingPropertyDefinition": pset,
|
||||
},
|
||||
)
|
||||
del pset
|
||||
|
||||
if file_first:
|
||||
del f
|
||||
else:
|
||||
del inst
|
||||
|
||||
# File should still exist, because we either have a direct ref
|
||||
# or the instance from the file still available
|
||||
assert r()
|
||||
|
||||
if not file_first:
|
||||
del f
|
||||
else:
|
||||
del inst
|
||||
|
||||
# With both deleted we should have no longer access to the file.
|
||||
assert r() is None
|
||||
|
||||
|
||||
def test_bug_2517():
|
||||
fixtures = os.path.join(os.path.dirname(__file__), "fixtures")
|
||||
model: ifcopenshell.file
|
||||
library: ifcopenshell.file
|
||||
model = ifcopenshell.open(f"{fixtures}/bug_2517_test2.ifc")
|
||||
library = ifcopenshell.open(f"{fixtures}/bug_2517_lib.ifc")
|
||||
result = model.add(library.by_type("IfcClassification")[0])
|
||||
model.create_entity(
|
||||
"IfcRelAssociatesClassification",
|
||||
GlobalId=ifcopenshell.guid.new(),
|
||||
RelatedObjects=[model.by_type("IfcProject")[0]],
|
||||
RelatingClassification=result,
|
||||
)
|
||||
|
||||
|
||||
def test_bug_2486_a():
|
||||
file = ifcopenshell.api.project.create_file()
|
||||
|
||||
mymaterial = ifcopenshell.api.material.add_material(file)
|
||||
pset = ifcopenshell.api.pset.add_pset(file, product=mymaterial, name="Foo")
|
||||
ifcopenshell.api.pset.edit_pset(
|
||||
file,
|
||||
pset=pset,
|
||||
properties={"foo": "bar"},
|
||||
)
|
||||
|
||||
another_file = ifcopenshell.api.project.create_file()
|
||||
|
||||
ifcopenshell.api.project.append_asset(
|
||||
another_file,
|
||||
library=file,
|
||||
element=mymaterial,
|
||||
)
|
||||
|
||||
|
||||
def test_bug_2486_b():
|
||||
file = ifcopenshell.template.create()
|
||||
file.header.file_name.name = "myfile.ifc"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pytest.main(["-sx", __file__])
|
||||
Reference in New Issue
Block a user