ifc2x3 tests

removed part of test_append_two_type_products_sharing_the_same_material_indirectly_via_a_material_set for ifc2x3 compatibility and removed part is already tested in test_append_two_type_products_sharing_the_same_material_with_properties
This commit is contained in:
Andrej730
2024-05-13 12:32:58 +05:00
parent 3665dda87c
commit a9cba30da6
35 changed files with 395 additions and 262 deletions
@@ -25,3 +25,7 @@ class TestAddLibrary(test.bootstrap.IFC4):
library = ifcopenshell.api.run("library.add_library", self.file, name="Name")
assert library.is_a("IfcLibraryInformation")
assert library.Name == "Name"
class TestAddLibraryIFC2X3(test.bootstrap.IFC2X3, TestAddLibrary):
pass
@@ -20,28 +20,6 @@ import test.bootstrap
import ifcopenshell.api
def validate_ifc_file(ifc_file: ifcopenshell.file, use_json=True):
import ifcopenshell
import ifcopenshell.validate
if use_json:
logger = ifcopenshell.validate.json_logger()
else:
import logging
logger = logging.getLogger("validate")
logger.setLevel(logging.DEBUG)
ifcopenshell.validate.validate(ifc_file, logger, express_rules=True)
if use_json:
if logger.statements:
from pprint import pprint
pprint(logger.statements)
else:
print("IFC is completely valid.")
class TestAssignReference(test.bootstrap.IFC4):
def test_assigning_a_reference(self):
reference = self.file.createIfcLibraryReference()
@@ -17,26 +17,41 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import test.bootstrap
import datetime
import ifcopenshell.api
import ifcopenshell.util.date
class TestEditLibrary(test.bootstrap.IFC4):
def test_editing_a_library(self):
library = self.file.createIfcLibraryInformation()
dt = datetime.datetime.now()
attributes = {
"Name": "Name",
"Version": "Version",
"VersionDate": dt,
}
if self.file.schema != "IFC2X3":
attributes["Location"] = "Location"
attributes["Description"] = "Description"
ifcopenshell.api.run(
"library.edit_library",
self.file,
library=library,
attributes={
"Name": "Name",
"Version": "Version",
"VersionDate": "VersionDate",
"Location": "Location",
"Description": "Description",
},
attributes=attributes,
)
assert library.Name == "Name"
assert library.Version == "Version"
assert library.VersionDate == "VersionDate"
assert library.Location == "Location"
assert library.Description == "Description"
if self.file.schema != "IFC2X3":
assert library.VersionDate == ifcopenshell.util.date.datetime2ifc(dt, "IfcDateTime")
assert library.Location == "Location"
assert library.Description == "Description"
else:
info = library.VersionDate.get_info()
del info["id"], info["type"]
assert info == ifcopenshell.util.date.datetime2ifc(dt, "IfcCalendarDate")
class TestEditLibraryIFC2X3(test.bootstrap.IFC2X3, TestEditLibrary):
pass
@@ -23,20 +23,28 @@ import ifcopenshell.api
class TestEditReference(test.bootstrap.IFC4):
def test_editing_a_reference(self):
reference = self.file.createIfcLibraryReference()
attributes = {
"Location": "Location",
"Identification" if self.file.schema != "IFC2X3" else "ItemReference": "Identification",
"Name": "Name",
}
if self.file.schema != "IFC2X3":
attributes["Description"] = "Description"
attributes["Language"] = "Language"
ifcopenshell.api.run(
"library.edit_reference",
self.file,
reference=reference,
attributes={
"Location": "Location",
"Identification": "Identification",
"Name": "Name",
"Description": "Description",
"Language": "Language",
},
attributes=attributes,
)
assert reference.Location == "Location"
assert reference.Identification == "Identification"
# 1 IfcExternalReference Identification(>IFC2X3) / ItemReference (IFC2X3)
assert reference[1] == "Identification"
assert reference.Name == "Name"
assert reference.Description == "Description"
assert reference.Language == "Language"
if self.file.schema != "IFC2X3":
assert reference.Description == "Description"
assert reference.Language == "Language"
class TestEditReferenceIFC2X3(test.bootstrap.IFC2X3, TestEditReference):
pass
@@ -27,11 +27,21 @@ class TestRemoveLibrary(test.bootstrap.IFC4):
assert len(self.file.by_type("IfcLibraryInformation")) == 0
def test_removing_a_library_and_all_references(self):
library = self.file.createIfcLibraryInformation()
reference1 = self.file.createIfcLibraryReference(ReferencedLibrary=library)
reference2 = self.file.createIfcLibraryReference(ReferencedLibrary=library)
if self.file.schema != "IFC2X3":
library = self.file.createIfcLibraryInformation()
reference1 = self.file.createIfcLibraryReference(ReferencedLibrary=library)
reference2 = self.file.createIfcLibraryReference(ReferencedLibrary=library)
else:
reference1 = self.file.createIfcLibraryReference()
reference2 = self.file.createIfcLibraryReference()
library = self.file.createIfcLibraryInformation(LibraryReference=[reference1, reference2])
self.file.createIfcRelAssociatesLibrary(GlobalId="foo", RelatingLibrary=library)
self.file.createIfcRelAssociatesLibrary(GlobalId="bar", RelatingLibrary=reference1)
ifcopenshell.api.run("library.remove_library", self.file, library=library)
assert len(self.file.by_type("IfcLibraryReference")) == 0
assert len(self.file.by_type("IfcRelAssociatesLibrary")) == 0
class TestRemoveLibraryIFC2X3(test.bootstrap.IFC2X3, TestRemoveLibrary):
pass
@@ -28,3 +28,7 @@ class TestRemoveReference(test.bootstrap.IFC4):
ifcopenshell.api.run("library.remove_reference", self.file, reference=reference)
assert len(self.file.by_type("IfcLibraryReference")) == 0
assert len(self.file.by_type("IfcRelAssociatesLibrary")) == 0
class TestRemoveReferenceIFC2X3(test.bootstrap.IFC2X3, TestRemoveReference):
pass