replace api.run with static methods

This commit is contained in:
Andrej
2025-06-09 10:59:22 +05:00
parent 02d359d0e6
commit 8b4683aef1
122 changed files with 1334 additions and 1370 deletions
@@ -19,6 +19,7 @@
import pytest
import ifcopenshell.api.alignment
import ifcopenshell.api.context
import ifcopenshell.util.element
def test_add_stationing_to_alignment():
@@ -18,6 +18,8 @@
import test.bootstrap
import ifcopenshell.api.context
import ifcopenshell.api.geometry
import ifcopenshell.api.root
class TestRemoveContext(test.bootstrap.IFC4):
@@ -22,6 +22,7 @@ import ifcopenshell.api.feature
import ifcopenshell.api.root
import ifcopenshell.api.unit
import ifcopenshell.api.geometry
import ifcopenshell.util.placement
class TestAddFeature(test.bootstrap.IFC4X3):
@@ -20,6 +20,7 @@ import test.bootstrap
import ifcopenshell.api.root
import ifcopenshell.api.context
import ifcopenshell.api.geometry
import ifcopenshell.util.shape_builder
class TestAddBoolean(test.bootstrap.IFC4):
@@ -20,6 +20,7 @@ import test.bootstrap
import ifcopenshell.api.root
import ifcopenshell.api.context
import ifcopenshell.api.geometry
import ifcopenshell.util.shape_builder
class TestRemoveBoolean(test.bootstrap.IFC4):
@@ -20,6 +20,7 @@ import test.bootstrap
import ifcopenshell.api.root
import ifcopenshell.api.context
import ifcopenshell.api.geometry
import ifcopenshell.util.shape_builder
class TestValidateType(test.bootstrap.IFC4):
@@ -19,6 +19,7 @@
import time
import test.bootstrap
import ifcopenshell.api.owner
import ifcopenshell.api.owner.settings
class TestUpdateOwnerHistory(test.bootstrap.IFC4):
@@ -33,6 +34,7 @@ class TestUpdateOwnerHistory(test.bootstrap.IFC4):
element = self.file.createIfcWall()
history = ifcopenshell.api.owner.update_owner_history(self.file, element=element)
assert history
assert history.is_a("IfcOwnerHistory")
assert element.OwnerHistory == history
assert history.ChangeAction == "ADDED"
@@ -57,6 +59,7 @@ class TestUpdateOwnerHistory(test.bootstrap.IFC4):
element.OwnerHistory = old_history
new_history = ifcopenshell.api.owner.update_owner_history(self.file, element=element)
assert new_history
assert new_history == old_history
assert element.OwnerHistory == new_history
assert new_history.ChangeAction == "MODIFIED"
@@ -83,6 +86,7 @@ class TestUpdateOwnerHistory(test.bootstrap.IFC4):
element2.OwnerHistory = old_history
new_history = ifcopenshell.api.owner.update_owner_history(self.file, element=element)
assert new_history
assert new_history != old_history
assert element.OwnerHistory == new_history
assert new_history.ChangeAction == "MODIFIED"
+2
View File
@@ -76,6 +76,8 @@ def test_file_gc(args):
def test_bug_2517():
fixtures = os.path.join(os.path.dirname(__file__), "fixtures")
model: ifcopenshell.file
library: ifcopenshell.file
model = ifcopenshell.open(f"{fixtures}/bug_2517_test2.ifc")
library = ifcopenshell.open(f"{fixtures}/bug_2517_lib.ifc")
result = model.add(library.by_type("IfcClassification")[0])
@@ -18,9 +18,11 @@
import numpy as np
import ifcopenshell
import ifcopenshell.api.context
import ifcopenshell.api.geometry
import ifcopenshell.api.profile
import ifcopenshell.api.root
import ifcopenshell.api.unit
import ifcopenshell.geom
import ifcopenshell.geom
import ifcopenshell.util.unit
@@ -37,9 +39,9 @@ class TestSettings(test.bootstrap.IFC4):
builder = ShapeBuilder(ifc_file)
ifcopenshell.api.root.create_entity(ifc_file, "IfcProject")
unit = ifcopenshell.api.run("unit.add_si_unit", ifc_file, unit_type="LENGTHUNIT", prefix="MILLI")
ifcopenshell.api.run("unit.assign_unit", ifc_file, units=[unit])
model = ifcopenshell.api.run("context.add_context", ifc_file, context_type="Model")
unit = ifcopenshell.api.unit.add_si_unit(ifc_file, unit_type="LENGTHUNIT", prefix="MILLI")
ifcopenshell.api.unit.assign_unit(ifc_file, units=[unit])
model = ifcopenshell.api.context.add_context(ifc_file, context_type="Model")
# Placement.
element = ifcopenshell.api.root.create_entity(ifc_file, "IfcWall")
@@ -26,15 +26,18 @@ TEST_FILE = Path(__file__).parent / "files" / "basic.ifc"
class TestFile:
def test_run(self):
stream_file: ifcopenshell.stream
stream_file = ifcopenshell.open(TEST_FILE, should_stream=True)
assert stream_file.schema == "IFC4"
def test_by_id(self):
stream_file: ifcopenshell.stream
stream_file = ifcopenshell.open(TEST_FILE, should_stream=True)
assert (element := stream_file.by_id(1))
assert str(element) == "#1=IFCPROJECT('3kv235yMjDO9tHiTzD8QuS',$,'My Project',$,$,$,$,(#14,#26),#9);"
def test_by_type(self):
stream_file: ifcopenshell.stream
stream_file = ifcopenshell.open(TEST_FILE, should_stream=True)
assert (elements := stream_file.by_type("IfcProject"))
assert str(elements[0]) == "#1=IFCPROJECT('3kv235yMjDO9tHiTzD8QuS',$,'My Project',$,$,$,$,(#14,#26),#9);"
@@ -42,6 +45,7 @@ class TestFile:
class TestEntity:
def test_getattr(self):
stream_file: ifcopenshell.stream
stream_file = ifcopenshell.open(TEST_FILE, should_stream=True)
assert (element := stream_file.by_id(1))
assert element.Name == "My Project"
@@ -26,6 +26,8 @@ TEST_FILE_DIR = Path("../../test/input/")
class TestWrite:
model: ifcopenshell.file
def setup_method(self):
self.model = ifcopenshell.open(TEST_FILE_DIR / "WallInstance_IFC4Add2.ifc")
@@ -38,7 +38,7 @@ from typing import Any, Union
class TestMathutilsCompatibleMethods(test.bootstrap.IFC4):
def test_np_rotation_matrix(self):
from mathutils import Matrix, Vector
from mathutils import Matrix, Vector # pyright: ignore[reportMissingImports]
# 2D.
assert np.allclose(Matrix.Rotation(radians(45), 2), np_rotation_matrix(radians(45), 2))
@@ -59,7 +59,7 @@ class TestMathutilsCompatibleMethods(test.bootstrap.IFC4):
assert np.allclose(Matrix.Rotation(*rotation_vector_args), np_rotation_matrix(*rotation_vector_args))
def test_np_matrix_to_euler(self):
from mathutils import Euler
from mathutils import Euler # pyright: ignore[reportMissingImports]
# Test 3x3.
rot = Euler((0.5, 0.5, 0.5)).to_matrix()
@@ -74,7 +74,7 @@ class TestMathutilsCompatibleMethods(test.bootstrap.IFC4):
assert np.allclose(rot.to_euler(), np_matrix_to_euler(V(rot)))
def test_np_angle(self):
from mathutils import Vector
from mathutils import Vector # pyright: ignore[reportMissingImports]
v1, v2 = (1, 0, 0), (0, 1, 0)
angle = np_angle(v1, v2)
@@ -97,7 +97,7 @@ class TestMathutilsCompatibleMethods(test.bootstrap.IFC4):
assert is_x(angle, radians(90))
def test_np_normal(self):
import mathutils.geometry
import mathutils.geometry # pyright: ignore[reportMissingImports]
vectors = (0, 0, 0), (1, 0, 0), (0, 1, 0)
n = mathutils.geometry.normal(vectors)
@@ -110,7 +110,7 @@ class TestMathutilsCompatibleMethods(test.bootstrap.IFC4):
assert np.allclose(n, (0, 0, -1))
def test_np_intersect_line_line(self):
import mathutils.geometry
import mathutils.geometry # pyright: ignore[reportMissingImports]
p1, p2 = [0, 0, 0], [1, 1, 1]
q1, q2 = [0, 1, 0], [1, 0, 1]