mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-06 12:26:26 +00:00
adapted to get pytest -p no:pytest-blender test/core/test_document.py working. Black formating
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
import bonsai.core.document as subject
|
||||
from test.core.bootstrap import ifc, document
|
||||
|
||||
@@ -29,14 +28,6 @@ class TestLoadProjectDocuments:
|
||||
subject.load_project_documents(document)
|
||||
|
||||
|
||||
class TestLoadDocument:
|
||||
def test_run(self, document):
|
||||
document.clear_document_tree().should_be_called()
|
||||
document.disable_editing_document().should_be_called()
|
||||
document.add_breadcrumb("document").should_be_called()
|
||||
subject.load_document(document, document="document")
|
||||
|
||||
|
||||
class TestDisableDocumentEditingUi:
|
||||
def test_run(self, document):
|
||||
document.disable_editing_ui().should_be_called()
|
||||
@@ -44,38 +35,71 @@ class TestDisableDocumentEditingUi:
|
||||
subject.disable_document_editing_ui(document)
|
||||
|
||||
|
||||
class TestDisableObjectDocumentEditingUi:
|
||||
def test_run(self, document):
|
||||
document.disable_object_editing_ui().should_be_called()
|
||||
subject.disable_object_document_editing_ui(document)
|
||||
|
||||
|
||||
class TestEnableEditingDocument:
|
||||
def test_run(self, document):
|
||||
document.import_document_attributes("document").should_be_called()
|
||||
document.set_active_document("document").should_be_called()
|
||||
subject.enable_editing_document(document, document="document")
|
||||
document.import_document_attributes("document").should_be_called()
|
||||
subject.enable_editing_document(document, ifc_document="document")
|
||||
|
||||
|
||||
class TestDisableEditingDocument:
|
||||
def test_run(self, document):
|
||||
document.disable_editing_document().should_be_called()
|
||||
document.clear_active_document().should_be_called()
|
||||
document.clear_document_attributes().should_be_called()
|
||||
subject.disable_editing_document(document)
|
||||
|
||||
|
||||
class TestAddInformation:
|
||||
def test_add_and_reload_tree_at_project_root(self, ifc, document):
|
||||
document.clear_document_tree().should_be_called()
|
||||
ifc.run("document.add_information", parent=None).should_be_called().will_return("information")
|
||||
document.get_default_parent_for_information().should_be_called().will_return("default_parent")
|
||||
ifc.run("document.add_information", parent="default_parent").should_be_called().will_return("information")
|
||||
ifc.run("document.add_reference", information="information").should_be_called()
|
||||
document.is_document_information("default_parent").should_be_called().will_return(True)
|
||||
document.expand_document("default_parent").should_be_called()
|
||||
document.import_project_documents().should_be_called()
|
||||
|
||||
subject.add_information(ifc, document)
|
||||
|
||||
def test_add_and_reload_tree_at_current_parent(self, ifc, document):
|
||||
document.clear_document_tree().should_be_called()
|
||||
ifc.run("document.add_information", parent="parent").should_be_called().will_return("information")
|
||||
ifc.run("document.add_reference", information="information").should_be_called()
|
||||
subject.add_information(ifc, document)
|
||||
document.is_document_information("parent").should_be_called().will_return(True)
|
||||
document.expand_document("parent").should_be_called()
|
||||
document.import_project_documents().should_be_called()
|
||||
|
||||
subject.add_information(ifc, document, parent="parent")
|
||||
|
||||
def test_add_without_expanding_if_parent_is_not_information(self, ifc, document):
|
||||
document.clear_document_tree().should_be_called()
|
||||
ifc.run("document.add_information", parent="parent").should_be_called().will_return("information")
|
||||
ifc.run("document.add_reference", information="information").should_be_called()
|
||||
document.is_document_information("parent").should_be_called().will_return(False)
|
||||
document.import_project_documents().should_be_called()
|
||||
|
||||
subject.add_information(ifc, document, parent="parent")
|
||||
|
||||
|
||||
class TestAddReference:
|
||||
def test_run(self, ifc, document):
|
||||
def test_run_with_selected_parent(self, ifc, document):
|
||||
document.get_selected_document_information().should_be_called().will_return("parent")
|
||||
ifc.run("document.add_reference", information="parent").should_be_called()
|
||||
document.clear_document_tree().should_be_called()
|
||||
document.expand_document("parent").should_be_called()
|
||||
document.import_project_documents().should_be_called()
|
||||
|
||||
subject.add_reference(ifc, document)
|
||||
|
||||
def test_run_without_selected_parent(self, ifc, document):
|
||||
document.get_selected_document_information().should_be_called().will_return(None)
|
||||
document.import_project_documents().should_be_called()
|
||||
|
||||
subject.add_reference(ifc, document)
|
||||
|
||||
|
||||
@@ -87,7 +111,7 @@ class TestEditDocument:
|
||||
document.disable_editing_document().should_be_called()
|
||||
document.clear_document_tree().should_be_called()
|
||||
document.import_project_documents().should_be_called()
|
||||
subject.edit_document(ifc, document, document="document")
|
||||
subject.edit_document(ifc, document, ifc_document="document")
|
||||
|
||||
def test_edit_reference(self, ifc, document):
|
||||
document.export_document_attributes().should_be_called().will_return("attributes")
|
||||
@@ -95,7 +119,8 @@ class TestEditDocument:
|
||||
ifc.run("document.edit_reference", reference="document", attributes="attributes").should_be_called()
|
||||
document.disable_editing_document().should_be_called()
|
||||
document.clear_document_tree().should_be_called()
|
||||
subject.edit_document(ifc, document, document="document")
|
||||
document.import_project_documents().should_be_called()
|
||||
subject.edit_document(ifc, document, ifc_document="document")
|
||||
|
||||
|
||||
class TestRemoveDocument:
|
||||
@@ -104,22 +129,23 @@ class TestRemoveDocument:
|
||||
document.is_document_information("document").should_be_called().will_return(True)
|
||||
ifc.run("document.remove_information", information="document").should_be_called()
|
||||
document.import_project_documents().should_be_called()
|
||||
subject.remove_document(ifc, document, document="document")
|
||||
subject.remove_document(ifc, document, ifc_document="document")
|
||||
|
||||
def test_remove_reference(self, ifc, document):
|
||||
document.clear_document_tree().should_be_called()
|
||||
document.is_document_information("document").should_be_called().will_return(False)
|
||||
ifc.run("document.remove_reference", reference="document").should_be_called()
|
||||
subject.remove_document(ifc, document, document="document")
|
||||
document.import_project_documents().should_be_called()
|
||||
subject.remove_document(ifc, document, ifc_document="document")
|
||||
|
||||
|
||||
class TestAssignDocument:
|
||||
def test_run(self, ifc):
|
||||
ifc.run("document.assign_document", products=["product"], document="document").should_be_called()
|
||||
subject.assign_document(ifc, product="product", document="document")
|
||||
subject.assign_document(ifc, product="product", ifc_document="document")
|
||||
|
||||
|
||||
class TestUnassignDocument:
|
||||
def test_run(self, ifc):
|
||||
ifc.run("document.unassign_document", products=["product"], document="document").should_be_called()
|
||||
subject.unassign_document(ifc, product="product", document="document")
|
||||
subject.unassign_document(ifc, product="product", ifc_document="document")
|
||||
|
||||
@@ -148,24 +148,23 @@ class TestImportProjectDocumentsExpanded(NewFile):
|
||||
document = ifcopenshell.api.document.add_information(ifc)
|
||||
reference = ifcopenshell.api.document.add_reference(ifc, information=document)
|
||||
|
||||
|
||||
props = tool.Document.get_document_props()
|
||||
expanded_docs = [document.id()] # Mark document as expanded
|
||||
props.json_string = json.dumps(expanded_docs)
|
||||
|
||||
|
||||
subject.import_project_documents()
|
||||
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 == ""
|
||||
@@ -180,24 +179,23 @@ class TestImportProjectDocumentsCollapsed(NewFile):
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user