Fix failing tests and optimise brick tests.

This commit is contained in:
Dion Moult
2023-08-25 16:51:14 +10:00
parent 356bc18078
commit 66decc604e
12 changed files with 107 additions and 72 deletions
+8 -4
View File
@@ -221,7 +221,9 @@ class IfcStore:
blenderbim.bim.handler.subscribe_to(obj, "diffuse_color", blenderbim.bim.handler.color_callback)
elif isinstance(obj, bpy.types.Object):
blenderbim.bim.handler.subscribe_to(obj, "mode", blenderbim.bim.handler.mode_callback)
blenderbim.bim.handler.subscribe_to(obj, "active_material_index", blenderbim.bim.handler.active_material_index_callback)
blenderbim.bim.handler.subscribe_to(
obj, "active_material_index", blenderbim.bim.handler.active_material_index_callback
)
if IfcStore.history:
data = {"id": element.id(), "guid": getattr(element, "GlobalId", None), "obj": obj.name}
@@ -248,7 +250,9 @@ class IfcStore:
blenderbim.bim.handler.subscribe_to(obj, "diffuse_color", blenderbim.bim.handler.color_callback)
elif isinstance(obj, bpy.types.Object):
blenderbim.bim.handler.subscribe_to(obj, "mode", blenderbim.bim.handler.mode_callback)
blenderbim.bim.handler.subscribe_to(obj, "active_material_index", blenderbim.bim.handler.active_material_index_callback)
blenderbim.bim.handler.subscribe_to(
obj, "active_material_index", blenderbim.bim.handler.active_material_index_callback
)
# TODO Listeners are not re-registered. Does this cause nasty problems to debug later on?
# TODO We're handling id_map and guid_map, but what about edited_objs? This might cause big problems.
@@ -321,7 +325,7 @@ class IfcStore:
IfcStore.begin_transaction(operator)
if tool.Ifc.get():
tool.Ifc.get().begin_transaction()
if BrickStore.graph:
if BrickStore.graph is not None: # `if BrickStore.graph` by itself takes ages.
BrickStore.begin_transaction()
# This empty transaction ensures that each operator has at least one transaction
IfcStore.add_transaction_operation(operator, rollback=lambda data: True, commit=lambda data: True)
@@ -339,7 +343,7 @@ class IfcStore:
IfcStore.add_transaction_operation(
operator, rollback=lambda d: tool.Ifc.get().undo(), commit=lambda d: tool.Ifc.get().redo()
)
if BrickStore.graph:
if BrickStore.graph is not None: # `if BrickStore.graph` by itself takes ages.
BrickStore.end_transaction()
IfcStore.end_transaction(operator)
blenderbim.bim.handler.refresh_ui_data()
@@ -46,7 +46,7 @@ class BrickschemaData:
@classmethod
def get_is_loaded(cls):
return BrickStore.graph is not None
return BrickStore.graph is not None # `if BrickStore.graph` by itself takes ages.
@classmethod
def active_relations(cls):
@@ -50,6 +50,8 @@ class ProfileData:
@classmethod
def active_profile_users(cls):
profiles_props = bpy.context.scene.BIMProfileProperties
if profiles_props.active_profile_index >= len(profiles_props.profiles):
return 0
profile_prop = profiles_props.profiles[profiles_props.active_profile_index]
profile_ifc = tool.Ifc.get().by_id(profile_prop.ifc_definition_id)
return tool.Ifc.get().get_total_inverses(profile_ifc)
+3 -3
View File
@@ -298,7 +298,7 @@ class BIM_PT_tabs(Panel):
self.draw_tab_entry(row, "NETWORK_DRIVE", "SERVICES", is_ifc_project, aprops.tab == "SERVICES")
self.draw_tab_entry(row, "EDITMODE_HLT", "STRUCTURE", is_ifc_project, aprops.tab == "STRUCTURE")
self.draw_tab_entry(row, "NLA", "SCHEDULING", is_ifc_project, aprops.tab == "SCHEDULING")
self.draw_tab_entry(row, "PACKAGE", "FM", is_ifc_project, aprops.tab == "FM")
self.draw_tab_entry(row, "PACKAGE", "FM", True, aprops.tab == "FM")
self.draw_tab_entry(row, "COMMUNITY", "QUALITY", True, aprops.tab == "QUALITY")
self.draw_tab_entry(row, "BLENDER", "BLENDER", True, aprops.tab == "BLENDER")
row.operator("bim.switch_tab", text="", emboss=False, icon="UV_SYNC_SELECT")
@@ -669,7 +669,7 @@ class BIM_PT_tab_handover(Panel):
@classmethod
def poll(cls, context):
return tool.Blender.is_tab(context, "FM") and tool.Ifc.get()
return tool.Blender.is_tab(context, "FM")
def draw(self, context):
pass
@@ -684,7 +684,7 @@ class BIM_PT_tab_operations(Panel):
@classmethod
def poll(cls, context):
return tool.Blender.is_tab(context, "FM") and tool.Ifc.get()
return tool.Blender.is_tab(context, "FM")
def draw(self, context):
pass
+2 -2
View File
@@ -144,8 +144,8 @@ class Brick(blenderbim.core.tool.Brick):
query = BrickStore.graph.query(
"""
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?label {
<{brick_uri}> rdfs:label ?label .
SELECT ?label {
<{brick_uri}> rdfs:label ?label .
}
LIMIT 1
""".replace("{brick_uri}", brick_uri))
+29 -5
View File
@@ -3,28 +3,33 @@ Feature: Brick
Scenario: Create Brick project
Given an empty Blender session
And the Brickschema is stubbed
When I press "bim.new_brick_file"
Then nothing happens
Scenario: Load Brick project
Given an empty Blender session
And the Brickschema is stubbed
When I press "bim.load_brick_project(filepath='{cwd}/test/files/spaces.ttl')"
Then nothing happens
Scenario: View Brick class
Given an empty Blender session
And the Brickschema is stubbed
And I press "bim.load_brick_project(filepath='{cwd}/test/files/spaces.ttl')"
When I press "bim.view_brick_class(brick_class='Building')"
Then nothing happens
Scenario: View Brick item
Given an empty Blender session
And the Brickschema is stubbed
And I press "bim.load_brick_project(filepath='{cwd}/test/files/spaces.ttl')"
When I press "bim.view_brick_item(item='https://example.org/digitaltwin#lighting_zone_1')"
Then nothing happens
Scenario: Rewind Brick class
Given an empty Blender session
And the Brickschema is stubbed
And I press "bim.load_brick_project(filepath='{cwd}/test/files/spaces.ttl')"
And I press "bim.view_brick_class(brick_class='Building')"
When I press "bim.rewind_brick_class"
@@ -32,19 +37,23 @@ Scenario: Rewind Brick class
Scenario: Close Brick project
Given an empty Blender session
And the Brickschema is stubbed
And I press "bim.load_brick_project(filepath='{cwd}/test/files/spaces.ttl')"
When I press "bim.close_brick_project"
Then nothing happens
Scenario: Close Brick project then create Brick project
Given an empty Blender session
And the Brickschema is stubbed
And I press "bim.load_brick_project(filepath='{cwd}/test/files/spaces.ttl')"
And I press "bim.close_brick_project"
And the Brickschema is stubbed
When I press "bim.new_brick_file"
Then nothing happens
Then nothing happens
Scenario: Add Brick - vanilla Brick with no IFC
Given an empty Blender session
And the Brickschema is stubbed
And I press "bim.new_brick_file"
And I set "scene.BIMBrickProperties.namespace" to "https://example.org/digitaltwin#"
And I set "scene.BIMBrickProperties.new_brick_label" to "abc123"
@@ -53,6 +62,7 @@ Scenario: Add Brick - vanilla Brick with no IFC
Scenario: Add Brick - from geometry without a Brick IFC library
Given an empty IFC project
And the Brickschema is stubbed
And I press "bim.new_brick_file"
And I add a cube
And the object "Cube" is selected
@@ -66,6 +76,7 @@ Scenario: Add Brick - from geometry without a Brick IFC library
Scenario: Add Brick - from geometry with a Brick IFC library
Given an empty IFC project
And the Brickschema is stubbed
And I add a cube
And the object "Cube" is selected
And I set "scene.BIMRootProperties.ifc_class" to "IfcChiller"
@@ -79,12 +90,14 @@ Scenario: Add Brick - from geometry with a Brick IFC library
Scenario: Refresh Brick viewer
Given an empty Blender session
And the Brickschema is stubbed
And I press "bim.new_brick_file"
When I press "bim.refresh_brick_viewer"
Then nothing happens
Scenario: Add Brick relation - vanilla Brick with no IFC
Given an empty Blender session
And the Brickschema is stubbed
And I press "bim.load_brick_project(filepath='{cwd}/test/files/spaces.ttl')"
And I set "scene.BIMBrickProperties.namespace" to "https://example.org/digitaltwin#"
And I press "bim.view_brick_class(brick_class='Lighting_Zone')"
@@ -96,16 +109,17 @@ Scenario: Add Brick relation - vanilla Brick with no IFC
Scenario: Add Brick relation - vanilla Brick with no IFC and with split screen
Given an empty Blender session
And the Brickschema is stubbed
And I press "bim.load_brick_project(filepath='{cwd}/test/files/spaces.ttl')"
And I set "scene.BIMBrickProperties.namespace" to "https://example.org/digitaltwin#"
And I set "scene.BIMBrickProperties.brick_entity_create_type" to "Location"
And I set "scene.BIMBrickProperties.new_brick_label" to "abc123"
And I set "scene.BIMBrickProperties.brick_entity_class" to "https://brickschema.org/schema/Brick#Room"
And I set "scene.BIMBrickProperties.brick_entity_class" to "https://brickschema.org/schema/Brick#Building"
And I press "bim.add_brick"
And I press "bim.view_brick_class(brick_class='Lighting_Zone')"
And I set "scene.BIMBrickProperties.active_brick_index" to "0"
And I set "scene.BIMBrickProperties.split_screen_toggled" to "True"
And I press "bim.view_brick_class(brick_class='Room', split_screen=True)"
And I press "bim.view_brick_class(brick_class='Building', split_screen=True)"
And I set "scene.BIMBrickProperties.split_screen_active_brick_index" to "0"
And I set "scene.BIMBrickProperties.brick_create_relations_toggled" to "True"
When I press "bim.add_brick_relation"
@@ -113,6 +127,7 @@ Scenario: Add Brick relation - vanilla Brick with no IFC and with split screen
Scenario: Remove Brick - vanilla Brick
Given an empty Blender session
And the Brickschema is stubbed
And I press "bim.load_brick_project(filepath='{cwd}/test/files/spaces.ttl')"
And I press "bim.view_brick_class(brick_class='Lighting_Zone')"
And I set "scene.BIMBrickProperties.active_brick_index" to "0"
@@ -121,6 +136,7 @@ Scenario: Remove Brick - vanilla Brick
Scenario: Remove Brick - with a Brick IFC library reference
Given an empty IFC project
And the Brickschema is stubbed
And I add a cube
And the object "Cube" is selected
And I set "scene.BIMRootProperties.ifc_class" to "IfcChiller"
@@ -129,13 +145,14 @@ Scenario: Remove Brick - with a Brick IFC library reference
And the object "IfcChiller/Cube" is selected
And I set "scene.BIMBrickProperties.namespace" to "https://example.org/digitaltwin#"
And I press "bim.add_brick"
And I press "bim.view_brick_class(brick_class='Chiller')"
And I press "bim.view_brick_class(brick_class='Equipment')"
And I set "scene.BIMBrickProperties.active_brick_index" to "0"
When I press "bim.remove_brick"
Then nothing happens
Scenario: Change viewer list root
Given an empty Blender session
And the Brickschema is stubbed
And I press "bim.load_brick_project(filepath='{cwd}/test/files/spaces.ttl')"
And I set "scene.BIMBrickProperties.set_list_root_toggled" to "True"
When I set "scene.BIMBrickProperties.brick_list_root" to "Location"
@@ -143,6 +160,7 @@ Scenario: Change viewer list root
Scenario: Change viewer list root - split screen
Given an empty Blender session
And the Brickschema is stubbed
And I press "bim.load_brick_project(filepath='{cwd}/test/files/spaces.ttl')"
And I set "scene.BIMBrickProperties.set_list_root_toggled" to "True"
And I set "scene.BIMBrickProperties.split_screen_toggled" to "True"
@@ -151,17 +169,20 @@ Scenario: Change viewer list root - split screen
Scenario: Toggle split screen
Given an empty Blender session
And the Brickschema is stubbed
And I press "bim.load_brick_project(filepath='{cwd}/test/files/spaces.ttl')"
When I set "scene.BIMBrickProperties.split_screen_toggled" to "True"
Then nothing happens
Scenario: Set active namespace
Given an empty Blender session
And the Brickschema is stubbed
When I set "scene.BIMBrickProperties.namespace" to "https://example.org/digitaltwin#"
Then nothing happens
Scenario: Bind new namespace
Given an empty Blender session
And the Brickschema is stubbed
And I set "scene.BIMBrickProperties.new_brick_namespace_alias" to "digitaltwin2"
And I set "scene.BIMBrickProperties.new_brick_namespace_uri" to "https://example.org/digitaltwin2#"
When I press "bim.add_brick_namespace"
@@ -169,12 +190,14 @@ Scenario: Bind new namespace
Scenario: Convert brick project
Given an empty IFC project
And the Brickschema is stubbed
And I press "bim.load_brick_project(filepath='{cwd}/test/files/spaces.ttl')"
When I press "bim.convert_brick_project"
Then nothing happens
Scenario: Convert IFC to brick
Given an empty IFC project
And the Brickschema is stubbed
And I press "bim.load_brick_project(filepath='{cwd}/test/files/spaces.ttl')"
And I press "bim.convert_brick_project"
And I set "scene.BIMBrickProperties.namespace" to "https://example.org/digitaltwin#"
@@ -188,6 +211,7 @@ Scenario: Convert IFC to brick
Scenario: Assign brick reference
Given an empty IFC project
And the Brickschema is stubbed
And I press "bim.load_brick_project(filepath='{cwd}/test/files/spaces.ttl')"
And I set "scene.BIMBrickProperties.namespace" to "https://example.org/digitaltwin#"
And I set "scene.BIMBrickProperties.brick_entity_class" to "https://brickschema.org/schema/Brick#Chiller"
@@ -201,4 +225,4 @@ Scenario: Assign brick reference
And the object "IfcChiller/Cube" is selected
And I press "bim.convert_brick_project"
When I press "bim.assign_brick_reference"
Then nothing happens
Then nothing happens
@@ -47,6 +47,7 @@ Scenario: Add representation - add a representation with a scale factor applied
And I add a cube
And the object "Cube" is selected
When the object "Cube" is scaled to "2"
And I set "scene.BIMRootProperties.ifc_product" to "IfcElement"
And I set "scene.BIMRootProperties.ifc_class" to "IfcWall"
And I press "bim.assign_class"
Then the object "IfcWall/Cube" has no scale
@@ -58,6 +59,7 @@ Scenario: Add representation - add a representation with a scale factor removed
And I press "object.duplicate_move_linked"
And the object "Cube" is selected
When the object "Cube" is scaled to "2"
And I set "scene.BIMRootProperties.ifc_product" to "IfcElement"
And I set "scene.BIMRootProperties.ifc_class" to "IfcWall"
And I press "bim.assign_class"
Then the object "IfcWall/Cube" has no scale
@@ -179,6 +181,7 @@ Scenario: Update representation - updating a tessellation
Given an empty IFC project
And I add a cube
And the object "Cube" is selected
And I set "scene.BIMRootProperties.ifc_product" to "IfcElement"
And I set "scene.BIMRootProperties.ifc_class" to "IfcWall"
And I press "bim.assign_class"
And I press "bim.update_representation(obj='IfcWall/Cube')"
@@ -188,6 +191,7 @@ Scenario: Update representation - updating a layered extrusion
Given an empty IFC project
And I add a cube
And the object "Cube" is selected
And I set "scene.BIMRootProperties.ifc_product" to "IfcElement"
And I set "scene.BIMRootProperties.ifc_class" to "IfcWall"
And I press "bim.assign_class"
And I add an empty
@@ -318,7 +322,7 @@ Scenario: Override duplicate move - copying a coloured representation
When I duplicate the selected objects
And I press "export_ifc.bim(filepath='{cwd}/test/files/temp/export.ifc')"
And an empty Blender session is started
And I press "bim.load_project(filepath='{cwd}/test/files/temp/export.ifc')"
And I press "bim.load_project(filepath='{cwd}/test/files/temp/export.ifc', should_start_fresh_session=False)"
Then the material "Material" colour is "1,0,0,1"
And the object "IfcWall/Cube" has the material "Material"
And the object "IfcWall/Cube.001" has the material "Material"
@@ -456,7 +456,7 @@ Scenario: Export IFC - with changed style colour synchronised
When the material "Material" colour is set to "1,0,0,1"
And I press "export_ifc.bim(filepath='{cwd}/test/files/temp/export.ifc')"
And an empty Blender session is started
And I press "bim.load_project(filepath='{cwd}/test/files/temp/export.ifc')"
And I press "bim.load_project(filepath='{cwd}/test/files/temp/export.ifc', should_start_fresh_session=False)"
Then the material "Material" colour is "1,0,0,1"
Scenario: Export IFC - with changed style element synchronised
@@ -471,5 +471,5 @@ Scenario: Export IFC - with changed style element synchronised
And the material "Material.001" colour is set to "1,0,0,1"
And I press "export_ifc.bim(filepath='{cwd}/test/files/temp/export.ifc')"
And an empty Blender session is started
And I press "bim.load_project(filepath='{cwd}/test/files/temp/export.ifc')"
And I press "bim.load_project(filepath='{cwd}/test/files/temp/export.ifc', should_start_fresh_session=False)"
Then the material "Material.001" colour is "1,0,0,1"
+10
View File
@@ -24,6 +24,7 @@ import ifcopenshell
import blenderbim.tool as tool
import blenderbim.bim
from blenderbim.bim.ifc import IfcStore
from blenderbim.tool.brick import BrickStore
from blenderbim.bim.module.model.data import AuthoringData
from pytest_bdd import scenarios, given, when, then, parsers
from mathutils import Vector
@@ -71,6 +72,8 @@ def an_empty_blender_session():
if len(bpy.data.objects) > 0:
bpy.data.batch_remove(bpy.data.objects)
bpy.ops.outliner.orphans_purge(do_local_ids=True, do_linked_ids=True, do_recursive=True)
if len(bpy.data.materials) > 0:
bpy.data.batch_remove(bpy.data.materials)
# default project settings
bpy.context.scene.unit_settings.system = "METRIC"
@@ -92,6 +95,13 @@ def an_empty_ifc_2x3_project():
bpy.ops.bim.create_project()
@given("the Brickschema is stubbed")
def the_brickschema_is_stubbed():
# This makes things run faster since we don't need to load the entire brick schema
cwd = os.path.dirname(os.path.realpath(__file__))
BrickStore.schema = os.path.join(cwd, "..", "files", "BrickStub.ttl")
@when("I load a new pset template file")
def i_load_a_new_pset_template_file():
IfcStore.pset_template_path = bpy.context.scene.BIMPsetTemplateProperties.pset_template_files
+13
View File
@@ -22,3 +22,16 @@ brick:Location a owl:Class ;
brick:Building a owl:Class ;
rdfs:subClassOf brick:Class, brick:Location .
brick:Chiller a owl:Class,
sh:NodeShape ;
rdfs:subClassOf brick:HVAC_Equipment .
brick:HVAC_Equipment a owl:Class,
sh:NodeShape ;
rdfs:subClassOf brick:Equipment .
brick:Equipment a owl:Class,
sh:NodeShape ;
rdfs:subClassOf brick:Class,
brick:Entity .
+32 -47
View File
@@ -39,12 +39,12 @@ class TestImplementsTool(NewFile):
class TestAddBrick(NewFile):
def test_run(self):
BrickStore.graph = brickschema.persistent.VersionedGraphCollection("sqlite://")
result = subject.add_brick("https://example.org/digitaltwin#", "https://brickschema.org/schema/Brick#Equipment", "label")
result = subject.add_brick(
"https://example.org/digitaltwin#", "https://brickschema.org/schema/Brick#Equipment", "label"
)
assert "https://example.org/digitaltwin#" in result
assert list(
BrickStore.graph.triples(
(URIRef(result), A, URIRef("https://brickschema.org/schema/Brick#Equipment"))
)
BrickStore.graph.triples((URIRef(result), A, URIRef("https://brickschema.org/schema/Brick#Equipment")))
)
assert list(
BrickStore.graph.triples(
@@ -89,7 +89,7 @@ class TestAddBrickFromElement(NewFile):
(URIRef(uri), URIRef("http://www.w3.org/2000/01/rdf-schema#label"), Literal("Chiller"))
)
)
def test_run_no_element_name(self):
ifc = ifcopenshell.file()
element = ifc.createIfcChiller()
@@ -120,18 +120,10 @@ class TestAddBrickifcProject(NewFile):
result = subject.add_brickifc_project("http://example.org/digitaltwin#")
assert result == f"http://example.org/digitaltwin#{project.GlobalId}"
brick = URIRef(result)
assert list(BrickStore.graph.triples((brick, A, REF.ifcProject)))
assert list(BrickStore.graph.triples((brick, REF.ifcProjectID, Literal(project.GlobalId))))
assert list(
BrickStore.graph.triples((brick, A, REF.ifcProject))
)
assert list(
BrickStore.graph.triples(
(brick, REF.ifcProjectID, Literal(project.GlobalId))
)
)
assert list(
BrickStore.graph.triples(
(brick, REF.ifcFileLocation, Literal(bpy.context.scene.BIMProperties.ifc_file))
)
BrickStore.graph.triples((brick, REF.ifcFileLocation, Literal(bpy.context.scene.BIMProperties.ifc_file)))
)
assert list(
BrickStore.graph.triples(
@@ -148,38 +140,20 @@ class TestAddBrickifcReference(NewFile):
project = URIRef(f"http://example.org/digitaltwin#{tool.Ifc.get().by_type('IfcProject')[0].GlobalId}")
subject.add_brickifc_reference("http://example.org/digitaltwin#foo", element, project)
brick = URIRef("http://example.org/digitaltwin#foo")
bnode = list(
BrickStore.graph.triples((brick, A, REF.IFCReference))
)
assert list(
BrickStore.graph.triples(
(bnode, REF.hasIfcProjectReference, URIRef(project))
)
)
assert list(
BrickStore.graph.triples(
(bnode, REF.ifcGlobalID, Literal(element.GlobalId))
)
)
assert list(
BrickStore.graph.triples(
(bnode, REF.ifcName, Literal(element.Name))
)
)
bnode = list(BrickStore.graph.triples((brick, A, REF.IFCReference)))
assert list(BrickStore.graph.triples((bnode, REF.hasIfcProjectReference, URIRef(project))))
assert list(BrickStore.graph.triples((bnode, REF.ifcGlobalID, Literal(element.GlobalId))))
assert list(BrickStore.graph.triples((bnode, REF.ifcName, Literal(element.Name))))
class TestAddRelation(NewFile):
def test_run(self):
BrickStore.graph = brickschema.persistent.VersionedGraphCollection("sqlite://")
source = subject.add_brick(
"http://example.org/digitaltwin#",
"https://brickschema.org/schema/Brick#Equipment",
"source"
"http://example.org/digitaltwin#", "https://brickschema.org/schema/Brick#Equipment", "source"
)
destination = subject.add_brick(
"http://example.org/digitaltwin#",
"https://brickschema.org/schema/Brick#Equipment",
"destination"
"http://example.org/digitaltwin#", "https://brickschema.org/schema/Brick#Equipment", "destination"
)
subject.add_relation(source, "https://brickschema.org/schema/Brick#feeds", destination)
assert list(
@@ -196,7 +170,9 @@ class TestAddRelation(NewFile):
class TestRemoveRelation(NewFile):
def test_run(self):
TestAddRelation().test_run()
source, relation, destination = list(BrickStore.graph.triples((None, URIRef("https://brickschema.org/schema/Brick#feeds"), None)))[0]
source, relation, destination = list(
BrickStore.graph.triples((None, URIRef("https://brickschema.org/schema/Brick#feeds"), None))
)[0]
subject.remove_relation(source, relation, destination)
assert not list(
BrickStore.graph.triples(
@@ -214,7 +190,7 @@ class TestClearBrickBrowser(NewFile):
bpy.context.scene.BIMBrickProperties.bricks.add()
subject.clear_brick_browser()
assert len(bpy.context.scene.BIMBrickProperties.bricks) == 0
def test_run_split_screen(self):
bpy.context.scene.BIMBrickProperties.split_screen_bricks.add()
subject.clear_brick_browser(split_screen=True)
@@ -235,7 +211,9 @@ class TestClearProject(NewFile):
class TestExportBrickAttributes(NewFile):
def test_run(self):
BrickStore.graph = brickschema.persistent.VersionedGraphCollection("sqlite://")
brick = subject.add_brick("https://example.org/digitaltwin#", "https://brickschema.org/schema/Brick#Equipment", "name")
brick = subject.add_brick(
"https://example.org/digitaltwin#", "https://brickschema.org/schema/Brick#Equipment", "name"
)
assert subject.export_brick_attributes(brick) == {
"Identification": brick,
"Name": "name",
@@ -243,7 +221,9 @@ class TestExportBrickAttributes(NewFile):
def test_run_ifc2x3(self):
BrickStore.graph = brickschema.persistent.VersionedGraphCollection("sqlite://")
brick = subject.add_brick("https://example.org/digitaltwin#", "https://brickschema.org/schema/Brick#Equipment", "name")
brick = subject.add_brick(
"https://example.org/digitaltwin#", "https://brickschema.org/schema/Brick#Equipment", "name"
)
tool.Ifc.set(ifcopenshell.file(schema="IFC2X3"))
assert subject.export_brick_attributes(brick) == {
"ItemReference": brick,
@@ -345,6 +325,7 @@ class TestGetParentSpace(NewFile):
assert subject.get_parent_space(subelement) == element
assert subject.get_parent_space(element) is None
class TestGetElementContainer(NewFile):
def test_nothing(cls):
pass
@@ -491,13 +472,17 @@ class TestPopBrickBreadcrumb(NewFile):
class TestRemoveBrick(NewFile):
def test_run(self):
BrickStore.graph = brickschema.persistent.VersionedGraphCollection("sqlite://")
result = subject.add_brick("http://example.org/digitaltwin#", "https://brickschema.org/schema/Brick#Equipment", "label")
result = subject.add_brick(
"http://example.org/digitaltwin#", "https://brickschema.org/schema/Brick#Equipment", "label"
)
subject.remove_brick(result)
assert not list(BrickStore.graph.triples((URIRef(result), None, None)))
def test_run_with_bnode(self):
BrickStore.graph = brickschema.persistent.VersionedGraphCollection("sqlite://")
result = subject.add_brick("http://example.org/digitaltwin#", "https://brickschema.org/schema/Brick#Equipment", "label")
result = subject.add_brick(
"http://example.org/digitaltwin#", "https://brickschema.org/schema/Brick#Equipment", "label"
)
TestAddBrickifcProject().test_run()
element = tool.Ifc.get().createIfcChiller(ifcopenshell.guid.new())
element.Name = "Chiller"
@@ -550,4 +535,4 @@ class TestAddNamespace(NewFile):
def test_run(self):
BrickStore.graph = brickschema.persistent.VersionedGraphCollection("sqlite://")
subject.add_namespace("digitaltwin", "http://example.org/digitaltwin")
assert ("digitaltwin", "http://example.org/digitaltwin") in BrickStore.namespaces
assert ("digitaltwin", "http://example.org/digitaltwin") in BrickStore.namespaces
@@ -38,10 +38,3 @@ class TestGetBrickTypeIFC2X3(test.bootstrap.IFC2X3):
type_element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcAirTerminalBoxType")
ifcopenshell.api.run("type.assign_type", self.file, related_object=element, relating_type=type_element)
assert subject.get_brick_type(element) == "https://brickschema.org/schema/Brick#TerminalUnit"
class TestGetBrickElementsIFC4(test.bootstrap.IFC4):
def test_run(self):
element = self.file.createIfcAirTerminalBox()
self.file.createIfcWall()
assert subject.get_brick_elements(self.file) == {element}