test_qto.py black format

This commit is contained in:
Andrej730
2023-04-19 19:05:11 +05:00
parent 57cb062d48
commit 4aa26b613b
+35 -18
View File
@@ -29,24 +29,32 @@ class TestImplementsTool(test.bim.bootstrap.NewFile):
def test_run(self):
assert isinstance(subject(), blenderbim.core.tool.Qto)
class TestGetRadiusOfSelectedVertices(test.bim.bootstrap.NewFile):
def test_run(self):
bpy.ops.mesh.primitive_circle_add()
assert round(subject.get_radius_of_selected_vertices(bpy.data.objects.get("Circle")), 3) == 1
class TestSetQtoResult(test.bim.bootstrap.NewFile):
def test_run(self):
subject.set_qto_result(123.4567)
assert bpy.context.scene.BIMQtoProperties.qto_result == "123.457"
class TestGetApplicableQuantityNames(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
schema = ifc.schema
properties_templates = ifcopenshell.util.pset.PsetQto(schema).get_by_name('Qto_WallBaseQuantities').get_info()['HasPropertyTemplates']
properties_templates = (
ifcopenshell.util.pset.PsetQto(schema)
.get_by_name("Qto_WallBaseQuantities")
.get_info()["HasPropertyTemplates"]
)
applicable_quantity_names = [a.Name for a in properties_templates]
assert subject.get_applicable_quantity_names('Qto_WallBaseQuantities') == applicable_quantity_names
assert subject.get_applicable_quantity_names("Qto_WallBaseQuantities") == applicable_quantity_names
class TestGetApplicableBaseQuantityName(test.bim.bootstrap.NewFile):
def test_run(self):
@@ -58,15 +66,17 @@ class TestGetApplicableBaseQuantityName(test.bim.bootstrap.NewFile):
def test_no_base_quantity(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
ifcopenshell.api.run("root.create_entity", ifc, ifc_class = "IfcProject")
product = ifc.by_type('IfcProject')[0]
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
product = ifc.by_type("IfcProject")[0]
assert subject.get_applicable_base_quantity_name(product) == None
class TestGetRoundedValue(test.bim.bootstrap.NewFile):
def test_run(self):
quantity = 1.2345
assert subject.get_rounded_value(quantity) == 1.234
class TestGetCalculatedObjectQuantities(test.bim.bootstrap.NewFile):
def setup_file(self):
self.ifc = ifcopenshell.file()
@@ -166,17 +176,20 @@ class TestAddObjectBaseQto(test.bim.bootstrap.NewFile):
tool.Ifc.set(ifc)
project = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject", name="My Project")
context = ifcopenshell.api.run("context.add_context", ifc, context_type="Model")
bpy.ops.mesh.primitive_cube_add(location=(0.0,0.0,0.0), size = 2)
bpy.ops.mesh.primitive_cube_add(location=(0.0, 0.0, 0.0), size=2)
obj = bpy.context.active_object
element = blenderbim.core.root.assign_class(tool.Ifc,
tool.Collector,
tool.Root,
obj=obj,
ifc_class="IfcWall",
predefined_type = "ELEMENTEDWALL",
context = context)
element = blenderbim.core.root.assign_class(
tool.Ifc,
tool.Collector,
tool.Root,
obj=obj,
ifc_class="IfcWall",
predefined_type="ELEMENTEDWALL",
context=context,
)
assert subject.add_object_base_qto(obj).Name == "Qto_WallBaseQuantities"
class TestAddProductBaseQto(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
@@ -185,6 +198,7 @@ class TestAddProductBaseQto(test.bim.bootstrap.NewFile):
base_qto = subject.add_product_base_qto(wall)
assert base_qto.Name == "Qto_WallBaseQuantities"
class TestGetBaseQto(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
@@ -194,7 +208,7 @@ class TestGetBaseQto(test.bim.bootstrap.NewFile):
tool.Ifc.link(wall, wall_obj)
product = tool.Ifc.get_entity(wall_obj)
pset_qto = ifcopenshell.api.run("pset.add_qto", ifc, product=wall, name="Qto_Basefoo")
assert subject.get_base_qto(product).id() == pset_qto.get_info()['id']
assert subject.get_base_qto(product).id() == pset_qto.get_info()["id"]
assert subject.get_base_qto(product).Name == pset_qto.Name
def test_isempty(self):
@@ -206,6 +220,7 @@ class TestGetBaseQto(test.bim.bootstrap.NewFile):
product = tool.Ifc.get_entity(wall_obj)
assert not subject.get_base_qto(product) == True
class TestGetRelatedCostItemQuantities(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
@@ -217,8 +232,10 @@ class TestGetRelatedCostItemQuantities(test.bim.bootstrap.NewFile):
ifcopenshell.api.run("cost.edit_cost_item", ifc, cost_item=item, attributes={"Name": "Foo"})
qto = ifcopenshell.api.run("pset.add_qto", ifc, product=wall, name="Qto_WallBaseQuantities")
ifcopenshell.api.run("pset.edit_qto", ifc, qto=qto, properties={"NetVolume": 42.0})
ifcopenshell.api.run("cost.assign_cost_item_quantity", ifc, cost_item=item, products=[wall], prop_name="NetVolume")
assert subject.get_related_cost_item_quantities(wall)[0]['cost_item_name'] == "Foo"
assert subject.get_related_cost_item_quantities(wall)[0]['quantity_name'] == "NetVolume"
assert subject.get_related_cost_item_quantities(wall)[0]['quantity_value'] == 42
assert subject.get_related_cost_item_quantities(wall)[0]['quantity_type'] == "IfcQuantityVolume"
ifcopenshell.api.run(
"cost.assign_cost_item_quantity", ifc, cost_item=item, products=[wall], prop_name="NetVolume"
)
assert subject.get_related_cost_item_quantities(wall)[0]["cost_item_name"] == "Foo"
assert subject.get_related_cost_item_quantities(wall)[0]["quantity_name"] == "NetVolume"
assert subject.get_related_cost_item_quantities(wall)[0]["quantity_value"] == 42
assert subject.get_related_cost_item_quantities(wall)[0]["quantity_type"] == "IfcQuantityVolume"