mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 14:41:25 +00:00
Add support for null attributes for people, roles, and addresses. New prototoype testable architecture. See #1711.
This commit is contained in:
@@ -32,7 +32,7 @@ from mathutils import Vector
|
||||
webbrowser.open = lambda x: True
|
||||
|
||||
|
||||
variables = {"cwd": os.getcwd()}
|
||||
variables = {"cwd": os.getcwd(), "ifc": "IfcStore.get_file()"}
|
||||
|
||||
|
||||
class NewFile:
|
||||
@@ -45,6 +45,17 @@ class NewFile:
|
||||
bpy.ops.outliner.orphans_purge(do_local_ids=True, do_linked_ids=True, do_recursive=True)
|
||||
|
||||
|
||||
class NewIfc:
|
||||
@pytest.fixture(autouse=True)
|
||||
def setup(self):
|
||||
IfcStore.purge()
|
||||
bpy.ops.wm.read_homefile(app_template="")
|
||||
while bpy.data.objects:
|
||||
bpy.data.objects.remove(bpy.data.objects[0])
|
||||
bpy.ops.outliner.orphans_purge(do_local_ids=True, do_linked_ids=True, do_recursive=True)
|
||||
bpy.ops.bim.create_project()
|
||||
|
||||
|
||||
def scenario(function):
|
||||
def subfunction(self):
|
||||
run(function(self))
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# BlenderBIM Add-on - OpenBIM Blender Add-on
|
||||
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
||||
#
|
||||
# This file is part of BlenderBIM Add-on.
|
||||
#
|
||||
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# BlenderBIM Add-on is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||
@@ -0,0 +1,279 @@
|
||||
# BlenderBIM Add-on - OpenBIM Blender Add-on
|
||||
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
||||
#
|
||||
# This file is part of BlenderBIM Add-on.
|
||||
#
|
||||
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# BlenderBIM Add-on is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import test.bim.bootstrap
|
||||
|
||||
|
||||
class TestAddPerson(test.bim.bootstrap.NewFile):
|
||||
@test.bim.bootstrap.scenario
|
||||
def test_run(self):
|
||||
return """
|
||||
Given an empty IFC project
|
||||
When I press "bim.add_person"
|
||||
Then nothing interesting happens
|
||||
"""
|
||||
|
||||
|
||||
class TestRemovePerson(test.bim.bootstrap.NewFile):
|
||||
@test.bim.bootstrap.scenario
|
||||
def test_run(self):
|
||||
return """
|
||||
Given an empty IFC project
|
||||
And I press "bim.add_person"
|
||||
And the variable "person" is "{ifc}.by_type('IfcPerson')[0].id()"
|
||||
When I press "bim.remove_person(person={person})"
|
||||
Then nothing interesting happens
|
||||
"""
|
||||
|
||||
|
||||
class TestAddPersonAttribute(test.bim.bootstrap.NewFile):
|
||||
@test.bim.bootstrap.scenario
|
||||
def test_run(self):
|
||||
return """
|
||||
Given an empty IFC project
|
||||
And I press "bim.add_person"
|
||||
When I press "bim.add_person_attribute(name='MiddleNames')"
|
||||
And I press "bim.add_person_attribute(name='PrefixTitles')"
|
||||
And I press "bim.add_person_attribute(name='SuffixTitles')"
|
||||
Then nothing interesting happens
|
||||
"""
|
||||
|
||||
|
||||
class TestRemovePersonAttribute(test.bim.bootstrap.NewFile):
|
||||
@test.bim.bootstrap.scenario
|
||||
def test_run(self):
|
||||
return """
|
||||
Given an empty IFC project
|
||||
And I press "bim.add_person"
|
||||
When I press "bim.add_person_attribute(name='MiddleNames')"
|
||||
And I press "bim.remove_person_attribute(name='MiddleNames', id=0)"
|
||||
And I press "bim.add_person_attribute(name='PrefixTitles')"
|
||||
And I press "bim.remove_person_attribute(name='PrefixTitles', id=0)"
|
||||
And I press "bim.add_person_attribute(name='SuffixTitles')"
|
||||
And I press "bim.remove_person_attribute(name='SuffixTitles', id=0)"
|
||||
Then nothing interesting happens
|
||||
"""
|
||||
|
||||
|
||||
class TestEnableEditingPerson(test.bim.bootstrap.NewFile):
|
||||
@test.bim.bootstrap.scenario
|
||||
def test_run(self):
|
||||
return """
|
||||
Given an empty IFC project
|
||||
And I press "bim.add_person"
|
||||
And the variable "person" is "{ifc}.by_type('IfcPerson')[0].id()"
|
||||
When I press "bim.enable_editing_person(person={person})"
|
||||
Then "scene.BIMOwnerProperties.active_person_id" is "{person}"
|
||||
"""
|
||||
|
||||
|
||||
class TestDisableEditingPerson(test.bim.bootstrap.NewFile):
|
||||
@test.bim.bootstrap.scenario
|
||||
def test_run(self):
|
||||
return """
|
||||
Given an empty IFC project
|
||||
And I press "bim.add_person"
|
||||
And the variable "person" is "{ifc}.by_type('IfcPerson')[0].id()"
|
||||
And I press "bim.enable_editing_person(person={person})"
|
||||
When I press "bim.disable_editing_person"
|
||||
Then "scene.BIMOwnerProperties.active_person_id" is "0"
|
||||
"""
|
||||
|
||||
|
||||
class TestEditPerson(test.bim.bootstrap.NewFile):
|
||||
@test.bim.bootstrap.scenario
|
||||
def test_run(self):
|
||||
return """
|
||||
Given an empty IFC project
|
||||
And I press "bim.add_person"
|
||||
And the variable "person" is "{ifc}.by_type('IfcPerson')[0].id()"
|
||||
And I press "bim.enable_editing_person(person={person})"
|
||||
When I press "bim.edit_person"
|
||||
Then "scene.BIMOwnerProperties.active_person_id" is "0"
|
||||
"""
|
||||
|
||||
|
||||
class TestAddRole(test.bim.bootstrap.NewFile):
|
||||
@test.bim.bootstrap.scenario
|
||||
def test_run(self):
|
||||
return """
|
||||
Given an empty IFC project
|
||||
And I press "bim.add_person"
|
||||
And the variable "person" is "{ifc}.by_type('IfcPerson')[0].id()"
|
||||
When I press "bim.add_role(parent={person})"
|
||||
Then nothing interesting happens
|
||||
"""
|
||||
|
||||
|
||||
class TestRemoveRole(test.bim.bootstrap.NewFile):
|
||||
@test.bim.bootstrap.scenario
|
||||
def test_run(self):
|
||||
return """
|
||||
Given an empty IFC project
|
||||
And I press "bim.add_person"
|
||||
And the variable "person" is "{ifc}.by_type('IfcPerson')[0].id()"
|
||||
And I press "bim.add_role(parent={person})"
|
||||
And the variable "role" is "{ifc}.by_type('IfcActorRole')[0].id()"
|
||||
When I press "bim.remove_role(role={role})"
|
||||
Then nothing interesting happens
|
||||
"""
|
||||
|
||||
|
||||
class TestEnableEditingRole(test.bim.bootstrap.NewFile):
|
||||
@test.bim.bootstrap.scenario
|
||||
def test_run(self):
|
||||
return """
|
||||
Given an empty IFC project
|
||||
And I press "bim.add_person"
|
||||
And the variable "person" is "{ifc}.by_type('IfcPerson')[0].id()"
|
||||
And I press "bim.add_role(parent={person})"
|
||||
And the variable "role" is "{ifc}.by_type('IfcActorRole')[0].id()"
|
||||
When I press "bim.enable_editing_role(role={role})"
|
||||
Then nothing interesting happens
|
||||
"""
|
||||
|
||||
|
||||
class TestDisableEditingRole(test.bim.bootstrap.NewFile):
|
||||
@test.bim.bootstrap.scenario
|
||||
def test_run(self):
|
||||
return """
|
||||
Given an empty IFC project
|
||||
And I press "bim.add_person"
|
||||
And the variable "person" is "{ifc}.by_type('IfcPerson')[0].id()"
|
||||
And I press "bim.add_role(parent={person})"
|
||||
And the variable "role" is "{ifc}.by_type('IfcActorRole')[0].id()"
|
||||
And I press "bim.enable_editing_role(role={role})"
|
||||
When I press "bim.disable_editing_role()"
|
||||
Then nothing interesting happens
|
||||
"""
|
||||
|
||||
|
||||
class TestEditRole(test.bim.bootstrap.NewFile):
|
||||
@test.bim.bootstrap.scenario
|
||||
def test_run(self):
|
||||
return """
|
||||
Given an empty IFC project
|
||||
And I press "bim.add_person"
|
||||
And the variable "person" is "{ifc}.by_type('IfcPerson')[0].id()"
|
||||
And I press "bim.add_role(parent={person})"
|
||||
And the variable "role" is "{ifc}.by_type('IfcActorRole')[0].id()"
|
||||
And I press "bim.enable_editing_role(role={role})"
|
||||
When I press "bim.edit_role()"
|
||||
Then nothing interesting happens
|
||||
"""
|
||||
|
||||
|
||||
class TestAddAddress(test.bim.bootstrap.NewFile):
|
||||
@test.bim.bootstrap.scenario
|
||||
def test_run(self):
|
||||
return """
|
||||
Given an empty IFC project
|
||||
And I press "bim.add_person"
|
||||
And the variable "person" is "{ifc}.by_type('IfcPerson')[0].id()"
|
||||
When I press "bim.add_address(parent={person}, ifc_class='IfcPostalAddress')"
|
||||
Then nothing interesting happens
|
||||
"""
|
||||
|
||||
|
||||
class TestAddAddressAttribute(test.bim.bootstrap.NewFile):
|
||||
@test.bim.bootstrap.scenario
|
||||
def test_run(self):
|
||||
return """
|
||||
Given an empty IFC project
|
||||
And I press "bim.add_person"
|
||||
And the variable "person" is "{ifc}.by_type('IfcPerson')[0].id()"
|
||||
And I press "bim.add_address(parent={person}, ifc_class='IfcPostalAddress')"
|
||||
And the variable "address" is "{ifc}.by_type('IfcPostalAddress')[0].id()"
|
||||
And I press "bim.enable_editing_address(address={address})"
|
||||
When I press "bim.add_address_attribute(name='AddressLines')"
|
||||
Then nothing interesting happens
|
||||
"""
|
||||
|
||||
|
||||
class TestRemoveAddressAttribute(test.bim.bootstrap.NewFile):
|
||||
@test.bim.bootstrap.scenario
|
||||
def test_run(self):
|
||||
return """
|
||||
Given an empty IFC project
|
||||
And I press "bim.add_person"
|
||||
And the variable "person" is "{ifc}.by_type('IfcPerson')[0].id()"
|
||||
And I press "bim.add_address(parent={person}, ifc_class='IfcPostalAddress')"
|
||||
And the variable "address" is "{ifc}.by_type('IfcPostalAddress')[0].id()"
|
||||
And I press "bim.enable_editing_address(address={address})"
|
||||
And I press "bim.add_address_attribute(name='AddressLines')"
|
||||
When I press "bim.remove_address_attribute(name='AddressLines', id=0)"
|
||||
Then nothing interesting happens
|
||||
"""
|
||||
|
||||
|
||||
class TestRemoveAddress(test.bim.bootstrap.NewFile):
|
||||
@test.bim.bootstrap.scenario
|
||||
def test_run(self):
|
||||
return """
|
||||
Given an empty IFC project
|
||||
And I press "bim.add_person"
|
||||
And the variable "person" is "{ifc}.by_type('IfcPerson')[0].id()"
|
||||
And I press "bim.add_address(parent={person}, ifc_class='IfcPostalAddress')"
|
||||
And the variable "address" is "{ifc}.by_type('IfcPostalAddress')[0].id()"
|
||||
When I press "bim.remove_address(address={address})"
|
||||
Then nothing interesting happens
|
||||
"""
|
||||
|
||||
|
||||
class TestEnableEditingAddress(test.bim.bootstrap.NewFile):
|
||||
@test.bim.bootstrap.scenario
|
||||
def test_run(self):
|
||||
return """
|
||||
Given an empty IFC project
|
||||
And I press "bim.add_person"
|
||||
And the variable "person" is "{ifc}.by_type('IfcPerson')[0].id()"
|
||||
And I press "bim.add_address(parent={person}, ifc_class='IfcPostalAddress')"
|
||||
And the variable "address" is "{ifc}.by_type('IfcPostalAddress')[0].id()"
|
||||
When I press "bim.enable_editing_address(address={address})"
|
||||
Then nothing interesting happens
|
||||
"""
|
||||
|
||||
|
||||
class TestDisableEditingAddress(test.bim.bootstrap.NewFile):
|
||||
@test.bim.bootstrap.scenario
|
||||
def test_run(self):
|
||||
return """
|
||||
Given an empty IFC project
|
||||
And I press "bim.add_person"
|
||||
And the variable "person" is "{ifc}.by_type('IfcPerson')[0].id()"
|
||||
And I press "bim.add_address(parent={person}, ifc_class='IfcPostalAddress')"
|
||||
And the variable "address" is "{ifc}.by_type('IfcPostalAddress')[0].id()"
|
||||
And I press "bim.enable_editing_address(address={address})"
|
||||
When I press "bim.disable_editing_address()"
|
||||
Then nothing interesting happens
|
||||
"""
|
||||
|
||||
|
||||
class TestEditAddress(test.bim.bootstrap.NewFile):
|
||||
@test.bim.bootstrap.scenario
|
||||
def test_run(self):
|
||||
return """
|
||||
Given an empty IFC project
|
||||
And I press "bim.add_person"
|
||||
And the variable "person" is "{ifc}.by_type('IfcPerson')[0].id()"
|
||||
And I press "bim.add_address(parent={person}, ifc_class='IfcPostalAddress')"
|
||||
And the variable "address" is "{ifc}.by_type('IfcPostalAddress')[0].id()"
|
||||
And I press "bim.enable_editing_address(address={address})"
|
||||
When I press "bim.edit_address()"
|
||||
Then nothing interesting happens
|
||||
"""
|
||||
@@ -35,25 +35,25 @@ def blender():
|
||||
prophet.verify()
|
||||
|
||||
|
||||
def subject(sus):
|
||||
def decorate(cls):
|
||||
cls.sus = sus
|
||||
return cls
|
||||
|
||||
return decorate
|
||||
@pytest.fixture
|
||||
def person_editor():
|
||||
prophet = Prophecy(blenderbim.core.tool.PersonEditor)
|
||||
yield prophet
|
||||
prophet.verify()
|
||||
|
||||
|
||||
class Spec:
|
||||
@pytest.fixture(autouse=True)
|
||||
def setup(self):
|
||||
self.subject = None
|
||||
@pytest.fixture
|
||||
def role_editor():
|
||||
prophet = Prophecy(blenderbim.core.tool.RoleEditor)
|
||||
yield prophet
|
||||
prophet.verify()
|
||||
|
||||
def construct_with(self, *args, **kwargs):
|
||||
self.subject = self.sus(*args, **kwargs)
|
||||
return self.subject
|
||||
|
||||
def predict(self, cls):
|
||||
return Prophecy(cls)
|
||||
@pytest.fixture
|
||||
def address_editor():
|
||||
prophet = Prophecy(blenderbim.core.tool.AddressEditor)
|
||||
yield prophet
|
||||
prophet.verify()
|
||||
|
||||
|
||||
class Prophecy:
|
||||
@@ -66,10 +66,12 @@ class Prophecy:
|
||||
|
||||
def __getattr__(self, attr):
|
||||
if not hasattr(self.subject, attr):
|
||||
raise AttributeError(f"Prophecy has no attribute {attr}")
|
||||
raise AttributeError(f"Prophecy {self.subject} has no attribute {attr}")
|
||||
|
||||
def decorate(*args, **kwargs):
|
||||
call = {"name": attr, "args": args, "kwargs": kwargs}
|
||||
# Ensure that signature is valid
|
||||
getattr(self.subject, attr)(*args, **kwargs)
|
||||
try:
|
||||
key = json.dumps(call, sort_keys=True)
|
||||
self.calls.append(call)
|
||||
@@ -81,23 +83,25 @@ class Prophecy:
|
||||
|
||||
return decorate
|
||||
|
||||
def should(self):
|
||||
def should_be_called(self, number=None):
|
||||
self.should_call = self.calls.pop()
|
||||
return self
|
||||
|
||||
def be_called(self, number=None):
|
||||
self.predictions.append({"type": "SHOULD_BE_CALLED", "number": number, "call": self.should_call})
|
||||
return self
|
||||
|
||||
def return_with(self, value):
|
||||
def will_return(self, value):
|
||||
key = json.dumps(self.should_call, sort_keys=True)
|
||||
self.return_values[key] = value
|
||||
return self
|
||||
|
||||
def verify(self):
|
||||
predicted_calls = []
|
||||
for prediction in self.predictions:
|
||||
predicted_calls.append(prediction["call"])
|
||||
if prediction["type"] == "SHOULD_BE_CALLED":
|
||||
self.verify_should_be_called(prediction)
|
||||
for call in self.calls:
|
||||
if call not in predicted_calls:
|
||||
raise Exception(f"Unpredicted call: {call}")
|
||||
|
||||
def verify_should_be_called(self, prediction):
|
||||
if prediction["number"]:
|
||||
@@ -106,4 +110,4 @@ class Prophecy:
|
||||
raise Exception(f"Called {count}: {prediction}")
|
||||
else:
|
||||
if prediction["call"] not in self.calls:
|
||||
raise Exception("Not called", prediction)
|
||||
raise Exception(f"{self.subject} was not called with {prediction['call']['name']}: {prediction}")
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
# BlenderBIM Add-on - OpenBIM Blender Add-on
|
||||
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
||||
#
|
||||
# This file is part of BlenderBIM Add-on.
|
||||
#
|
||||
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# BlenderBIM Add-on is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
import blenderbim.core.owner as subject
|
||||
from test.core.bootstrap import ifc, blender, person_editor, role_editor, address_editor
|
||||
|
||||
|
||||
class TestAddPerson:
|
||||
def test_run(self, ifc):
|
||||
ifc.run("owner.add_person").should_be_called().will_return("person")
|
||||
assert subject.add_person(ifc) == "person"
|
||||
|
||||
|
||||
class TestRemovePerson:
|
||||
def test_run(self, ifc):
|
||||
ifc.run("owner.remove_person", person="person").should_be_called()
|
||||
subject.remove_person(ifc, person="person")
|
||||
|
||||
|
||||
class TestEnableEditingPerson:
|
||||
def test_run(self, person_editor):
|
||||
person_editor.set_person("person").should_be_called()
|
||||
person_editor.import_attributes().should_be_called()
|
||||
subject.enable_editing_person(person_editor, person="person")
|
||||
|
||||
|
||||
class TestDisableEditingPerson:
|
||||
def test_run(self, person_editor):
|
||||
person_editor.clear_person().should_be_called()
|
||||
subject.disable_editing_person(person_editor)
|
||||
|
||||
|
||||
class TestEditPerson:
|
||||
def test_run(self, ifc, person_editor):
|
||||
person_editor.get_person().should_be_called().will_return("person")
|
||||
person_editor.export_attributes().should_be_called().will_return("attributes")
|
||||
ifc.run("owner.edit_person", person="person", attributes="attributes").should_be_called()
|
||||
person_editor.clear_person().should_be_called()
|
||||
subject.edit_person(ifc, person_editor)
|
||||
|
||||
|
||||
class TestAddPersonAttribute:
|
||||
def test_run(self, person_editor):
|
||||
person_editor.add_attribute("name").should_be_called()
|
||||
subject.add_person_attribute(person_editor, name="name")
|
||||
|
||||
|
||||
class TestRemovePersonAttribute:
|
||||
def test_run(self, person_editor):
|
||||
person_editor.remove_attribute("name", "id").should_be_called()
|
||||
subject.remove_person_attribute(person_editor, name="name", id="id")
|
||||
|
||||
|
||||
class TestAddRole:
|
||||
def test_run(self, ifc):
|
||||
ifc.run("owner.add_role", assigned_object="parent").should_be_called().will_return("role")
|
||||
assert subject.add_role(ifc, parent="parent") == "role"
|
||||
|
||||
|
||||
class TestRemoveRole:
|
||||
def test_run(self, ifc):
|
||||
ifc.run("owner.remove_role", role="role").should_be_called()
|
||||
subject.remove_role(ifc, role="role")
|
||||
|
||||
|
||||
class TestEnableEditingRole:
|
||||
def test_run(self, role_editor):
|
||||
role_editor.set_role("role").should_be_called()
|
||||
role_editor.import_attributes().should_be_called()
|
||||
subject.enable_editing_role(role_editor, role="role")
|
||||
|
||||
|
||||
class TestDisableEditingRole:
|
||||
def test_run(self, role_editor):
|
||||
role_editor.clear_role().should_be_called()
|
||||
subject.disable_editing_role(role_editor)
|
||||
|
||||
|
||||
class TestEditRole:
|
||||
def test_run(self, ifc, role_editor):
|
||||
role_editor.export_attributes().should_be_called().will_return("attributes")
|
||||
role_editor.get_role().should_be_called().will_return("role")
|
||||
ifc.run("owner.edit_role", role="role", attributes="attributes").should_be_called()
|
||||
role_editor.clear_role().should_be_called()
|
||||
subject.edit_role(ifc, role_editor)
|
||||
|
||||
|
||||
class TestAddAddress:
|
||||
def test_run(self, ifc):
|
||||
ifc.run(
|
||||
"owner.add_address", assigned_object="parent", ifc_class="IfcPostalAddress"
|
||||
).should_be_called().will_return("address")
|
||||
assert subject.add_address(ifc, parent="parent", ifc_class="IfcPostalAddress") == "address"
|
||||
|
||||
|
||||
class TestRemoveAddress:
|
||||
def test_run(self, ifc):
|
||||
ifc.run("owner.remove_address", address="address").should_be_called()
|
||||
subject.remove_address(ifc, address="address")
|
||||
|
||||
|
||||
class TestEnableEditingAddress:
|
||||
def test_run(self, address_editor):
|
||||
address_editor.set_address("address").should_be_called()
|
||||
address_editor.import_attributes().should_be_called()
|
||||
subject.enable_editing_address(address_editor, address="address")
|
||||
|
||||
|
||||
class TestDisableEditingAddress:
|
||||
def test_run(self, address_editor):
|
||||
address_editor.clear_address().should_be_called()
|
||||
subject.disable_editing_address(address_editor)
|
||||
|
||||
|
||||
class TestEditAddress:
|
||||
def test_run(self, ifc, address_editor):
|
||||
address_editor.get_address().should_be_called().will_return("address")
|
||||
address_editor.export_attributes().should_be_called().will_return("attributes")
|
||||
ifc.run("owner.edit_address", address="address", attributes="attributes").should_be_called()
|
||||
address_editor.clear_address().should_be_called()
|
||||
subject.edit_address(ifc, address_editor)
|
||||
|
||||
|
||||
class TestAddAddressAttribute:
|
||||
def test_run(self, address_editor):
|
||||
address_editor.add_attribute("name").should_be_called()
|
||||
subject.add_address_attribute(address_editor, name="name")
|
||||
|
||||
|
||||
class TestRemoveAddressAttribute:
|
||||
def test_run(self, address_editor):
|
||||
address_editor.remove_attribute("name", "id").should_be_called()
|
||||
subject.remove_address_attribute(address_editor, name="name", id="id")
|
||||
@@ -0,0 +1,17 @@
|
||||
# BlenderBIM Add-on - OpenBIM Blender Add-on
|
||||
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
||||
#
|
||||
# This file is part of BlenderBIM Add-on.
|
||||
#
|
||||
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# BlenderBIM Add-on is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||
@@ -0,0 +1,197 @@
|
||||
# BlenderBIM Add-on - OpenBIM Blender Add-on
|
||||
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
||||
#
|
||||
# This file is part of BlenderBIM Add-on.
|
||||
#
|
||||
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# BlenderBIM Add-on is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import bpy
|
||||
import ifcopenshell
|
||||
import test.bim.bootstrap
|
||||
import blenderbim.core.tool
|
||||
import blenderbim.tool as tool
|
||||
from blenderbim.tool.address_editor import AddressEditor as subject
|
||||
|
||||
|
||||
class TestImplementsTool(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
assert isinstance(subject(), blenderbim.core.tool.AddressEditor)
|
||||
|
||||
|
||||
class TestSetAddress(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
ifc = ifcopenshell.file()
|
||||
address = ifc.createIfcPostalAddress()
|
||||
subject().set_address(address)
|
||||
assert bpy.context.scene.BIMOwnerProperties.active_address_id == address.id()
|
||||
|
||||
|
||||
class TestImportAttributes(test.bim.bootstrap.NewFile):
|
||||
def test_importing_a_postal_address(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc().set(ifc)
|
||||
address = ifc.createIfcPostalAddress()
|
||||
address.Purpose = "USERDEFINED"
|
||||
address.Description = "Description"
|
||||
address.UserDefinedPurpose = "UserDefinedPurpose"
|
||||
address.InternalLocation = "InternalLocation"
|
||||
address.AddressLines = ["Address", "Lines"]
|
||||
address.PostalBox = "PostalBox"
|
||||
address.Town = "Town"
|
||||
address.Region = "Region"
|
||||
address.PostalCode = "PostalCode"
|
||||
address.Country = "Country"
|
||||
subject().set_address(address)
|
||||
subject().import_attributes()
|
||||
props = bpy.context.scene.BIMOwnerProperties
|
||||
assert props.address_attributes.get("Purpose").enum_value == "USERDEFINED"
|
||||
assert props.address_attributes.get("Description").string_value == "Description"
|
||||
assert props.address_attributes.get("UserDefinedPurpose").string_value == "UserDefinedPurpose"
|
||||
assert props.address_attributes.get("InternalLocation").string_value == "InternalLocation"
|
||||
assert props.address_attributes.get("PostalBox").string_value == "PostalBox"
|
||||
assert props.address_attributes.get("Town").string_value == "Town"
|
||||
assert props.address_attributes.get("Region").string_value == "Region"
|
||||
assert props.address_attributes.get("PostalCode").string_value == "PostalCode"
|
||||
assert props.address_attributes.get("Country").string_value == "Country"
|
||||
assert len(props.address_lines) == 2
|
||||
assert props.address_lines[0].name == "Address"
|
||||
assert props.address_lines[1].name == "Lines"
|
||||
|
||||
def test_importing_a_postal_address_twice(self):
|
||||
self.test_importing_a_postal_address()
|
||||
ifc = tool.Ifc().get()
|
||||
address = ifc.createIfcPostalAddress()
|
||||
address.Purpose = "OFFICE"
|
||||
subject().set_address(address)
|
||||
subject().import_attributes()
|
||||
props = bpy.context.scene.BIMOwnerProperties
|
||||
assert props.address_attributes.get("Purpose").enum_value == "OFFICE"
|
||||
assert len(props.address_lines) == 0
|
||||
|
||||
def test_importing_a_telecom_address(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc().set(ifc)
|
||||
address = ifc.createIfcTelecomAddress()
|
||||
address.Purpose = "USERDEFINED"
|
||||
address.Description = "Description"
|
||||
address.UserDefinedPurpose = "UserDefinedPurpose"
|
||||
address.TelephoneNumbers = ["Telephone", "Numbers"]
|
||||
address.FacsimileNumbers = ["Facsimile", "Numbers"]
|
||||
address.PagerNumber = "PagerNumber"
|
||||
address.ElectronicMailAddresses = ["Electronic", "Mail", "Addresses"]
|
||||
address.WWWHomePageURL = "WWWHomePageURL"
|
||||
address.MessagingIDs = ["Messaging", "IDs"]
|
||||
subject().set_address(address)
|
||||
subject().import_attributes()
|
||||
props = bpy.context.scene.BIMOwnerProperties
|
||||
assert props.address_attributes.get("Purpose").enum_value == "USERDEFINED"
|
||||
assert props.address_attributes.get("Description").string_value == "Description"
|
||||
assert props.address_attributes.get("UserDefinedPurpose").string_value == "UserDefinedPurpose"
|
||||
assert [a.name for a in props.telephone_numbers] == ["Telephone", "Numbers"]
|
||||
assert [a.name for a in props.facsimile_numbers] == ["Facsimile", "Numbers"]
|
||||
assert [a.name for a in props.electronic_mail_addresses] == ["Electronic", "Mail", "Addresses"]
|
||||
assert [a.name for a in props.messaging_ids] == ["Messaging", "IDs"]
|
||||
|
||||
def test_importing_a_telecom_address_twice(self):
|
||||
self.test_importing_a_telecom_address()
|
||||
ifc = tool.Ifc().get()
|
||||
address = ifc.createIfcTelecomAddress()
|
||||
address.Purpose = "OFFICE"
|
||||
subject().set_address(address)
|
||||
subject().import_attributes()
|
||||
props = bpy.context.scene.BIMOwnerProperties
|
||||
assert props.address_attributes.get("Purpose").enum_value == "OFFICE"
|
||||
assert len(props.telephone_numbers) == 0
|
||||
assert len(props.facsimile_numbers) == 0
|
||||
assert len(props.electronic_mail_addresses) == 0
|
||||
assert len(props.messaging_ids) == 0
|
||||
|
||||
|
||||
class TestClearAddress(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
ifc = ifcopenshell.file()
|
||||
address = ifc.createIfcPostalAddress()
|
||||
subject().set_address(address)
|
||||
subject().clear_address()
|
||||
assert bpy.context.scene.BIMOwnerProperties.active_address_id == 0
|
||||
|
||||
|
||||
class TestGetAddress(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc().set(ifc)
|
||||
address = ifc.createIfcPostalAddress()
|
||||
subject().set_address(address)
|
||||
assert subject().get_address() == address
|
||||
|
||||
|
||||
class TestExportAttributes(test.bim.bootstrap.NewFile):
|
||||
def test_exporting_a_postal_address(self):
|
||||
TestImportAttributes().test_importing_a_postal_address()
|
||||
assert subject().export_attributes() == {
|
||||
"Purpose": "USERDEFINED",
|
||||
"Description": "Description",
|
||||
"UserDefinedPurpose": "UserDefinedPurpose",
|
||||
"InternalLocation": "InternalLocation",
|
||||
"AddressLines": ["Address", "Lines"],
|
||||
"PostalBox": "PostalBox",
|
||||
"Town": "Town",
|
||||
"Region": "Region",
|
||||
"PostalCode": "PostalCode",
|
||||
"Country": "Country",
|
||||
}
|
||||
|
||||
def test_exporting_a_telecom_address(self):
|
||||
TestImportAttributes().test_importing_a_telecom_address()
|
||||
assert subject().export_attributes() == {
|
||||
"Purpose": "USERDEFINED",
|
||||
"Description": "Description",
|
||||
"UserDefinedPurpose": "UserDefinedPurpose",
|
||||
"TelephoneNumbers": ["Telephone", "Numbers"],
|
||||
"FacsimileNumbers": ["Facsimile", "Numbers"],
|
||||
"PagerNumber": "PagerNumber",
|
||||
"ElectronicMailAddresses": ["Electronic", "Mail", "Addresses"],
|
||||
"WWWHomePageURL": "WWWHomePageURL",
|
||||
"MessagingIDs": ["Messaging", "IDs"],
|
||||
}
|
||||
|
||||
|
||||
class TestAddAttribute(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
subject().add_attribute("AddressLines")
|
||||
subject().add_attribute("TelephoneNumbers")
|
||||
subject().add_attribute("FacsimileNumbers")
|
||||
subject().add_attribute("ElectronicMailAddresses")
|
||||
subject().add_attribute("MessagingIDs")
|
||||
props = bpy.context.scene.BIMOwnerProperties
|
||||
assert len(props.address_lines) == 1
|
||||
assert len(props.telephone_numbers) == 1
|
||||
assert len(props.facsimile_numbers) == 1
|
||||
assert len(props.electronic_mail_addresses) == 1
|
||||
assert len(props.messaging_ids) == 1
|
||||
|
||||
|
||||
class TestRemoveAddress(test.bim.bootstrap.NewFile):
|
||||
TestAddAttribute().test_run()
|
||||
subject().remove_attribute("AddressLines", 0)
|
||||
subject().remove_attribute("TelephoneNumbers", 0)
|
||||
subject().remove_attribute("FacsimileNumbers", 0)
|
||||
subject().remove_attribute("ElectronicMailAddresses", 0)
|
||||
subject().remove_attribute("MessagingIDs", 0)
|
||||
props = bpy.context.scene.BIMOwnerProperties
|
||||
assert len(props.address_lines) == 0
|
||||
assert len(props.telephone_numbers) == 0
|
||||
assert len(props.facsimile_numbers) == 0
|
||||
assert len(props.electronic_mail_addresses) == 0
|
||||
assert len(props.messaging_ids) == 0
|
||||
@@ -0,0 +1,17 @@
|
||||
# BlenderBIM Add-on - OpenBIM Blender Add-on
|
||||
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
||||
#
|
||||
# This file is part of BlenderBIM Add-on.
|
||||
#
|
||||
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# BlenderBIM Add-on is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||
@@ -0,0 +1,58 @@
|
||||
# BlenderBIM Add-on - OpenBIM Blender Add-on
|
||||
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
||||
#
|
||||
# This file is part of BlenderBIM Add-on.
|
||||
#
|
||||
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# BlenderBIM Add-on is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import bpy
|
||||
import ifcopenshell
|
||||
import test.bim.bootstrap
|
||||
from blenderbim.tool import Ifc as subject
|
||||
|
||||
|
||||
class TestSet(test.bim.bootstrap.NewFile):
|
||||
def test_setting_an_ifc_data(self):
|
||||
ifc = ifcopenshell.file()
|
||||
subject().set(ifc)
|
||||
assert subject().get() == ifc
|
||||
|
||||
|
||||
class TestGet(test.bim.bootstrap.NewFile):
|
||||
def test_getting_an_ifc_dataset_from_a_ifc_spf_filepath(self):
|
||||
assert subject().get() is None
|
||||
bpy.context.scene.BIMProperties.ifc_file = "test/files/basic.ifc"
|
||||
result = subject().get()
|
||||
assert isinstance(result, ifcopenshell.file)
|
||||
|
||||
def test_getting_the_active_ifc_dataset_regardless_of_ifc_path(self):
|
||||
bpy.context.scene.BIMProperties.ifc_file = "test/files/basic.ifc"
|
||||
ifc = ifcopenshell.file()
|
||||
subject().set(ifc)
|
||||
assert subject().get() == ifc
|
||||
|
||||
|
||||
class TestRun(test.bim.bootstrap.NewFile):
|
||||
def test_running_a_command_on_the_active_ifc_dataset(self):
|
||||
ifc = ifcopenshell.file()
|
||||
subject().set(ifc)
|
||||
wall = subject().run("root.create_entity", ifc_class="IfcWall")
|
||||
assert subject().get().by_type("IfcWall")[0] == wall
|
||||
|
||||
|
||||
class TestGetSchema(test.bim.bootstrap.NewFile):
|
||||
def test_getting_the_schema_version_identifier(self):
|
||||
ifc = ifcopenshell.file(schema="IFC4")
|
||||
subject().set(ifc)
|
||||
assert subject().get_schema() == "IFC4"
|
||||
@@ -0,0 +1,152 @@
|
||||
# BlenderBIM Add-on - OpenBIM Blender Add-on
|
||||
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
||||
#
|
||||
# This file is part of BlenderBIM Add-on.
|
||||
#
|
||||
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# BlenderBIM Add-on is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import bpy
|
||||
import ifcopenshell
|
||||
import test.bim.bootstrap
|
||||
import blenderbim.core.tool
|
||||
import blenderbim.tool as tool
|
||||
from blenderbim.tool.person_editor import PersonEditor as subject
|
||||
|
||||
|
||||
class TestImplementsTool(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
assert isinstance(subject(), blenderbim.core.tool.person_editor.PersonEditor)
|
||||
|
||||
|
||||
class TestSetPerson(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
person = ifcopenshell.file().createIfcPerson()
|
||||
subject().set_person(person)
|
||||
assert bpy.context.scene.BIMOwnerProperties.active_person_id == person.id()
|
||||
|
||||
|
||||
class TestImportAttributes(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc().set(ifc)
|
||||
person = ifc.createIfcPerson()
|
||||
person.Identification = "identification"
|
||||
person.GivenName = "given_name"
|
||||
person.FamilyName = "family_name"
|
||||
person.MiddleNames = ("middle", "names")
|
||||
person.PrefixTitles = ("prefix", "titles")
|
||||
person.SuffixTitles = ("suffix", "titles")
|
||||
subject().set_person(person)
|
||||
subject().import_attributes()
|
||||
props = bpy.context.scene.BIMOwnerProperties
|
||||
assert props.person_attributes.get("Identification").string_value == "identification"
|
||||
assert props.person_attributes.get("GivenName").string_value == "given_name"
|
||||
assert props.person_attributes.get("FamilyName").string_value == "family_name"
|
||||
assert len(props.middle_names) == 2
|
||||
assert props.middle_names[0].name == "middle"
|
||||
assert props.middle_names[1].name == "names"
|
||||
assert len(props.prefix_titles) == 2
|
||||
assert props.prefix_titles[0].name == "prefix"
|
||||
assert props.prefix_titles[1].name == "titles"
|
||||
assert len(props.suffix_titles) == 2
|
||||
assert props.suffix_titles[0].name == "suffix"
|
||||
assert props.suffix_titles[1].name == "titles"
|
||||
|
||||
def test_overwriting_a_previous_import(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc().set(ifc)
|
||||
person = ifc.createIfcPerson()
|
||||
person.Identification = "identification"
|
||||
person.GivenName = "given_name"
|
||||
subject().set_person(person)
|
||||
subject().import_attributes()
|
||||
person.Identification = "identification2"
|
||||
person.GivenName = None
|
||||
subject().import_attributes()
|
||||
props = bpy.context.scene.BIMOwnerProperties
|
||||
assert props.person_attributes.get("Identification").string_value == "identification2"
|
||||
assert props.person_attributes.get("GivenName").string_value == ""
|
||||
|
||||
|
||||
class TestClearPerson(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
props = bpy.context.scene.BIMOwnerProperties
|
||||
props.active_person_id = 1
|
||||
subject().clear_person()
|
||||
assert props.active_person_id == 0
|
||||
|
||||
|
||||
class TestExportAttributes(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc().set(ifc)
|
||||
person = ifc.createIfcPerson()
|
||||
person.Identification = "identification"
|
||||
person.GivenName = "given_name"
|
||||
person.FamilyName = "family_name"
|
||||
person.MiddleNames = ("middle", "names")
|
||||
person.PrefixTitles = ("prefix", "titles")
|
||||
person.SuffixTitles = ("suffix", "titles")
|
||||
subject().set_person(person)
|
||||
subject().import_attributes()
|
||||
assert subject().export_attributes() == {
|
||||
"Identification": "identification",
|
||||
"GivenName": "given_name",
|
||||
"FamilyName": "family_name",
|
||||
"MiddleNames": ["middle", "names"],
|
||||
"PrefixTitles": ["prefix", "titles"],
|
||||
"SuffixTitles": ["suffix", "titles"],
|
||||
}
|
||||
|
||||
def test_getting_empty_list_attributes_as_none(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc().set(ifc)
|
||||
result = subject().export_attributes()
|
||||
assert result["MiddleNames"] is None
|
||||
assert result["PrefixTitles"] is None
|
||||
assert result["SuffixTitles"] is None
|
||||
|
||||
|
||||
class TestGetPerson(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc().set(ifc)
|
||||
person = ifc.createIfcPerson()
|
||||
subject().set_person(person)
|
||||
assert subject().get_person() == person
|
||||
|
||||
|
||||
class TestAddAttribute(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
subject().add_attribute("MiddleNames")
|
||||
subject().add_attribute("PrefixTitles")
|
||||
subject().add_attribute("SuffixTitles")
|
||||
props = bpy.context.scene.BIMOwnerProperties
|
||||
assert len(props.middle_names) == 1
|
||||
assert len(props.prefix_titles) == 1
|
||||
assert len(props.suffix_titles) == 1
|
||||
|
||||
|
||||
class TestRemoveAttribute(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
subject().add_attribute("MiddleNames")
|
||||
subject().remove_attribute("MiddleNames", 0)
|
||||
subject().add_attribute("PrefixTitles")
|
||||
subject().remove_attribute("PrefixTitles", 0)
|
||||
subject().add_attribute("SuffixTitles")
|
||||
subject().remove_attribute("SuffixTitles", 0)
|
||||
props = bpy.context.scene.BIMOwnerProperties
|
||||
assert len(props.middle_names) == 0
|
||||
assert len(props.prefix_titles) == 0
|
||||
assert len(props.suffix_titles) == 0
|
||||
@@ -0,0 +1,98 @@
|
||||
# BlenderBIM Add-on - OpenBIM Blender Add-on
|
||||
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
||||
#
|
||||
# This file is part of BlenderBIM Add-on.
|
||||
#
|
||||
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# BlenderBIM Add-on is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import bpy
|
||||
import ifcopenshell
|
||||
import test.bim.bootstrap
|
||||
import blenderbim.core.tool
|
||||
import blenderbim.tool as tool
|
||||
from blenderbim.tool.role_editor import RoleEditor as subject
|
||||
|
||||
|
||||
class TestImplementsTool(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
assert isinstance(subject(), blenderbim.core.tool.role_editor.RoleEditor)
|
||||
|
||||
|
||||
class TestSetRole(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
role = ifcopenshell.file().createIfcActorRole()
|
||||
subject().set_role(role)
|
||||
assert bpy.context.scene.BIMOwnerProperties.active_role_id == role.id()
|
||||
|
||||
|
||||
class TestImportAttributes(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc().set(ifc)
|
||||
role = ifc.createIfcActorRole()
|
||||
role.Role = "USERDEFINED"
|
||||
role.UserDefinedRole = "UserDefinedRole"
|
||||
role.Description = "Description"
|
||||
subject().set_role(role)
|
||||
subject().import_attributes()
|
||||
props = bpy.context.scene.BIMOwnerProperties
|
||||
assert props.role_attributes.get("Role").enum_value == "USERDEFINED"
|
||||
assert props.role_attributes.get("UserDefinedRole").string_value == "UserDefinedRole"
|
||||
assert props.role_attributes.get("Description").string_value == "Description"
|
||||
|
||||
def test_importing_twice(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc().set(ifc)
|
||||
role = ifc.createIfcActorRole()
|
||||
role.Role = "USERDEFINED"
|
||||
subject().set_role(role)
|
||||
subject().import_attributes()
|
||||
role.Role = "ARCHITECT"
|
||||
subject().import_attributes()
|
||||
props = bpy.context.scene.BIMOwnerProperties
|
||||
assert props.role_attributes.get("Role").enum_value == "ARCHITECT"
|
||||
|
||||
|
||||
class TestClearRole(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
role = ifcopenshell.file().createIfcActorRole()
|
||||
subject().set_role(role)
|
||||
subject().clear_role()
|
||||
assert bpy.context.scene.BIMOwnerProperties.active_role_id == 0
|
||||
|
||||
|
||||
class TestGetRole(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc().set(ifc)
|
||||
role = ifc.createIfcActorRole()
|
||||
subject().set_role(role)
|
||||
assert subject().get_role() == role
|
||||
|
||||
|
||||
class TestExportAttributes(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc().set(ifc)
|
||||
role = ifc.createIfcActorRole()
|
||||
role.Role = "USERDEFINED"
|
||||
role.UserDefinedRole = "UserDefinedRole"
|
||||
role.Description = "Description"
|
||||
subject().set_role(role)
|
||||
subject().import_attributes()
|
||||
assert subject().export_attributes() == {
|
||||
"Role": "USERDEFINED",
|
||||
"UserDefinedRole": "UserDefinedRole",
|
||||
"Description": "Description",
|
||||
}
|
||||
Reference in New Issue
Block a user