mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 15:08:51 +00:00
updated to get make test-tool MODULE=document working
This commit is contained in:
@@ -22,6 +22,7 @@ import ifcopenshell.api
|
|||||||
import ifcopenshell.api.document
|
import ifcopenshell.api.document
|
||||||
import bonsai.core.tool
|
import bonsai.core.tool
|
||||||
import bonsai.tool as tool
|
import bonsai.tool as tool
|
||||||
|
import json
|
||||||
from test.bim.bootstrap import NewFile
|
from test.bim.bootstrap import NewFile
|
||||||
from bonsai.tool.document import Document as subject
|
from bonsai.tool.document import Document as subject
|
||||||
|
|
||||||
@@ -139,35 +140,66 @@ class TestImportDocumentAttributes(NewFile):
|
|||||||
assert props.document_attributes["Description"].string_value == "Description"
|
assert props.document_attributes["Description"].string_value == "Description"
|
||||||
|
|
||||||
|
|
||||||
class TestImportProjectDocuments(NewFile):
|
class TestImportProjectDocumentsExpanded(NewFile):
|
||||||
def test_run(self):
|
def test_run(self):
|
||||||
ifc = ifcopenshell.file()
|
ifc = ifcopenshell.file()
|
||||||
tool.Ifc().set(ifc)
|
tool.Ifc().set(ifc)
|
||||||
ifc.createIfcProject()
|
project = ifc.createIfcProject()
|
||||||
document = ifcopenshell.api.document.add_information(ifc)
|
|
||||||
subject.import_project_documents()
|
|
||||||
props = tool.Document.get_document_props()
|
|
||||||
assert len(props.documents) == 1
|
|
||||||
assert props.documents[0].ifc_definition_id == document.id()
|
|
||||||
assert props.documents[0].name == "Unnamed"
|
|
||||||
assert props.documents[0].identification == "X"
|
|
||||||
assert props.documents[0].is_information is True
|
|
||||||
|
|
||||||
|
|
||||||
class TestImportReferences(NewFile):
|
|
||||||
def test_run(self):
|
|
||||||
ifc = ifcopenshell.file()
|
|
||||||
tool.Ifc().set(ifc)
|
|
||||||
ifc.createIfcProject()
|
|
||||||
document = ifcopenshell.api.document.add_information(ifc)
|
document = ifcopenshell.api.document.add_information(ifc)
|
||||||
reference = ifcopenshell.api.document.add_reference(ifc, information=document)
|
reference = ifcopenshell.api.document.add_reference(ifc, information=document)
|
||||||
subject.import_references(document)
|
|
||||||
|
|
||||||
props = tool.Document.get_document_props()
|
props = tool.Document.get_document_props()
|
||||||
assert len(props.documents) == 1
|
expanded_docs = [document.id()] # Mark document as expanded
|
||||||
assert props.documents[0].ifc_definition_id == reference.id()
|
props.json_string = json.dumps(expanded_docs)
|
||||||
assert props.documents[0].name == "Unnamed"
|
|
||||||
assert props.documents[0].identification == "X"
|
subject.import_project_documents()
|
||||||
assert props.documents[0].is_information is False
|
props = tool.Document.get_document_props()
|
||||||
|
|
||||||
|
# Should have project root + document + reference = 3 total
|
||||||
|
assert len(props.documents) == 3
|
||||||
|
|
||||||
|
assert props.documents[0].ifc_definition_id == -project.id()
|
||||||
|
assert props.documents[0].document_type == "PROJECT"
|
||||||
|
|
||||||
|
doc_info = next((d for d in props.documents if d.ifc_definition_id == document.id()), None)
|
||||||
|
assert doc_info is not None
|
||||||
|
assert doc_info.document_type == "INFORMATION"
|
||||||
|
|
||||||
|
doc_ref = next((d for d in props.documents if d.ifc_definition_id == reference.id()), None)
|
||||||
|
assert doc_ref is not None
|
||||||
|
assert doc_ref.location == ""
|
||||||
|
assert doc_ref.identification == "X"
|
||||||
|
assert doc_ref.document_type == "REFERENCE"
|
||||||
|
|
||||||
|
|
||||||
|
class TestImportProjectDocumentsCollapsed(NewFile):
|
||||||
|
def test_run(self):
|
||||||
|
ifc = ifcopenshell.file()
|
||||||
|
tool.Ifc().set(ifc)
|
||||||
|
project = ifc.createIfcProject()
|
||||||
|
document = ifcopenshell.api.document.add_information(ifc)
|
||||||
|
reference = ifcopenshell.api.document.add_reference(ifc, information=document)
|
||||||
|
|
||||||
|
|
||||||
|
props = tool.Document.get_document_props()
|
||||||
|
props.json_string = json.dumps([]) # Empty expanded list
|
||||||
|
|
||||||
|
subject.import_project_documents()
|
||||||
|
props = tool.Document.get_document_props()
|
||||||
|
|
||||||
|
# Should have project root + document = 2 total (reference not imported because parent is collapsed)
|
||||||
|
assert len(props.documents) == 2
|
||||||
|
|
||||||
|
assert props.documents[0].ifc_definition_id == -project.id()
|
||||||
|
assert props.documents[0].document_type == "PROJECT"
|
||||||
|
|
||||||
|
doc_info = next((d for d in props.documents if d.ifc_definition_id == document.id()), None)
|
||||||
|
assert doc_info is not None
|
||||||
|
assert doc_info.document_type == "INFORMATION"
|
||||||
|
|
||||||
|
doc_ref = next((d for d in props.documents if d.ifc_definition_id == reference.id()), None)
|
||||||
|
assert doc_ref is None
|
||||||
|
|
||||||
|
|
||||||
class TestIsDocumentInformation(NewFile):
|
class TestIsDocumentInformation(NewFile):
|
||||||
|
|||||||
Reference in New Issue
Block a user