Replace all ifcopenshell.api.run with ifcopenshell.api static functions.

This commit is contained in:
Dion Moult
2024-06-28 12:36:31 +10:00
parent b5d613989e
commit 07060fc769
432 changed files with 4633 additions and 4856 deletions
@@ -17,13 +17,12 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import test.bootstrap
import ifcopenshell.api
import ifcopenshell.api.unit
class TestAddContextDependentUnit(test.bootstrap.IFC4):
def test_run(self):
unit = ifcopenshell.api.run(
"unit.add_context_dependent_unit",
unit = ifcopenshell.api.unit.add_context_dependent_unit(
self.file,
unit_type="LENGTHUNIT",
name="foobar",
@@ -17,12 +17,12 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import test.bootstrap
import ifcopenshell.api
import ifcopenshell.api.unit
class TestAddConversionBasedUnitIFC2X3(test.bootstrap.IFC2X3):
def test_run(self):
unit = ifcopenshell.api.run("unit.add_conversion_based_unit", self.file, name="foot")
unit = ifcopenshell.api.unit.add_conversion_based_unit(self.file, name="foot")
assert unit.is_a("IfcConversionBasedUnit")
assert unit.Dimensions.LengthExponent == 1
assert unit.Dimensions.MassExponent == 0
@@ -43,7 +43,7 @@ class TestAddConversionBasedUnitIFC2X3(test.bootstrap.IFC2X3):
class TestAddConversionBasedUnitIFC4(test.bootstrap.IFC4, TestAddConversionBasedUnitIFC2X3):
def test_adding_a_unit_with_offset(self):
unit = ifcopenshell.api.run("unit.add_conversion_based_unit", self.file, name="fahrenheit")
unit = ifcopenshell.api.unit.add_conversion_based_unit(self.file, name="fahrenheit")
assert unit.is_a("IfcConversionBasedUnitWithOffset")
assert unit.Dimensions.LengthExponent == 0
assert unit.Dimensions.MassExponent == 0
@@ -17,12 +17,12 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import test.bootstrap
import ifcopenshell.api
import ifcopenshell.api.unit
class TestAddMonetaryUnit(test.bootstrap.IFC4):
def test_run(self):
unit = ifcopenshell.api.run("unit.add_monetary_unit", self.file, currency="USD")
unit = ifcopenshell.api.unit.add_monetary_unit(self.file, currency="USD")
assert unit.is_a("IfcMonetaryUnit")
assert unit.Currency == "USD"
@@ -17,12 +17,12 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import test.bootstrap
import ifcopenshell.api
import ifcopenshell.api.unit
class TestAddSIUnit(test.bootstrap.IFC4):
def test_run(self):
unit = ifcopenshell.api.run("unit.add_si_unit", self.file, unit_type="LENGTHUNIT", prefix="MILLI")
unit = ifcopenshell.api.unit.add_si_unit(self.file, unit_type="LENGTHUNIT", prefix="MILLI")
assert unit.UnitType == "LENGTHUNIT"
assert unit.Name == "METRE"
assert unit.Prefix == "MILLI"
@@ -17,15 +17,15 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import test.bootstrap
import ifcopenshell.api
import ifcopenshell.api.unit
class TestAssignUnit(test.bootstrap.IFC4):
def test_run(self):
project = self.file.createIfcProject()
unit1 = ifcopenshell.api.run("unit.add_monetary_unit", self.file, currency="USD")
unit2 = ifcopenshell.api.run("unit.add_monetary_unit", self.file, currency="JPY")
assignment = ifcopenshell.api.run("unit.assign_unit", self.file, units=[unit1, unit2])
unit1 = ifcopenshell.api.unit.add_monetary_unit(self.file, currency="USD")
unit2 = ifcopenshell.api.unit.add_monetary_unit(self.file, currency="JPY")
assignment = ifcopenshell.api.unit.assign_unit(self.file, units=[unit1, unit2])
assert project.UnitsInContext == assignment
assert assignment.is_a("IfcUnitAssignment")
assert unit1 in assignment.Units
@@ -33,10 +33,10 @@ class TestAssignUnit(test.bootstrap.IFC4):
def test_assign_units_to_an_existing_assignment(self):
project = self.file.createIfcProject()
unit1 = ifcopenshell.api.run("unit.add_monetary_unit", self.file, currency="USD")
unit2 = ifcopenshell.api.run("unit.add_monetary_unit", self.file, currency="JPY")
assignment1 = ifcopenshell.api.run("unit.assign_unit", self.file, units=[unit1])
assignment2 = ifcopenshell.api.run("unit.assign_unit", self.file, units=[unit2])
unit1 = ifcopenshell.api.unit.add_monetary_unit(self.file, currency="USD")
unit2 = ifcopenshell.api.unit.add_monetary_unit(self.file, currency="JPY")
assignment1 = ifcopenshell.api.unit.assign_unit(self.file, units=[unit1])
assignment2 = ifcopenshell.api.unit.assign_unit(self.file, units=[unit2])
assert project.UnitsInContext == assignment1
assert assignment1 == assignment2
assert unit1 in assignment1.Units
@@ -17,14 +17,13 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import test.bootstrap
import ifcopenshell.api
import ifcopenshell.api.unit
class TestEditDerivedUnit(test.bootstrap.IFC4):
def test_run(self):
unit = self.file.createIfcDerivedUnit()
ifcopenshell.api.run(
"unit.edit_derived_unit",
ifcopenshell.api.unit.edit_derived_unit(
self.file,
unit=unit,
attributes={"UnitType": "USERDEFINED", "UserDefinedType": "UserDefinedType"},
@@ -17,13 +17,13 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import test.bootstrap
import ifcopenshell.api
import ifcopenshell.api.unit
class TestEditMonetaryUnit(test.bootstrap.IFC4):
def test_run(self):
unit = self.file.createIfcMonetaryUnit()
ifcopenshell.api.run("unit.edit_monetary_unit", self.file, unit=unit, attributes={"Currency": "USD"})
ifcopenshell.api.unit.edit_monetary_unit(self.file, unit=unit, attributes={"Currency": "USD"})
assert unit.Currency == "USD"
@@ -17,15 +17,14 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import test.bootstrap
import ifcopenshell.api
import ifcopenshell.api.unit
class TestEditNamedUnitIFC2X3(test.bootstrap.IFC2X3):
def test_edit_context_dependent_unit(self):
unit = self.file.createIfcContextDependentUnit()
unit.Dimensions = self.file.createIfcDimensionalExponents()
ifcopenshell.api.run(
"unit.edit_named_unit",
ifcopenshell.api.unit.edit_named_unit(
self.file,
unit=unit,
attributes={"Dimensions": (1, 2, 3, 4, 5, 6, 7), "UnitType": "LENGTHUNIT", "Name": "Name"},
@@ -36,8 +35,7 @@ class TestEditNamedUnitIFC2X3(test.bootstrap.IFC2X3):
def test_edit_si_unit(self):
unit = self.file.createIfcSIUnit()
ifcopenshell.api.run(
"unit.edit_named_unit",
ifcopenshell.api.unit.edit_named_unit(
self.file,
unit=unit,
attributes={"UnitType": "LENGTHUNIT", "Prefix": "MILLI", "Name": "METRE"},
@@ -49,8 +47,7 @@ class TestEditNamedUnitIFC2X3(test.bootstrap.IFC2X3):
def test_edit_conversion_based_unit(self):
unit = self.file.createIfcConversionBasedUnit()
unit.Dimensions = self.file.createIfcDimensionalExponents()
ifcopenshell.api.run(
"unit.edit_named_unit",
ifcopenshell.api.unit.edit_named_unit(
self.file,
unit=unit,
attributes={"Dimensions": (1, 2, 3, 4, 5, 6, 7), "UnitType": "LENGTHUNIT", "Name": "Name"},
@@ -64,8 +61,7 @@ class TestEditNamedUnitIFC4(test.bootstrap.IFC4, TestEditNamedUnitIFC2X3):
def test_edit_conversion_based_unit_with_offset(self):
unit = self.file.createIfcConversionBasedUnitWithOffset()
unit.Dimensions = self.file.createIfcDimensionalExponents()
ifcopenshell.api.run(
"unit.edit_named_unit",
ifcopenshell.api.unit.edit_named_unit(
self.file,
unit=unit,
attributes={
@@ -17,20 +17,20 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import test.bootstrap
import ifcopenshell.api
import ifcopenshell.api.unit
class TestRemoveUnit(test.bootstrap.IFC4):
def test_remove_a_single_unit(self):
unit = self.file.createIfcContextDependentUnit()
ifcopenshell.api.run("unit.remove_unit", self.file, unit=unit)
ifcopenshell.api.unit.remove_unit(self.file, unit=unit)
assert len(self.file.by_type("IfcContextDependentUnit")) == 0
def test_remove_the_only_assigned_unit(self):
self.file.createIfcProject()
unit = self.file.createIfcContextDependentUnit()
ifcopenshell.api.run("unit.assign_unit", self.file, units=[unit])
ifcopenshell.api.run("unit.remove_unit", self.file, unit=unit)
ifcopenshell.api.unit.assign_unit(self.file, units=[unit])
ifcopenshell.api.unit.remove_unit(self.file, unit=unit)
assert len(self.file.by_type("IfcContextDependentUnit")) == 0
assert len(self.file.by_type("IfcUnitAssignment")) == 0
@@ -38,14 +38,14 @@ class TestRemoveUnit(test.bootstrap.IFC4):
self.file.createIfcProject()
unit1 = self.file.createIfcContextDependentUnit()
unit2 = self.file.createIfcSIUnit()
assignment = ifcopenshell.api.run("unit.assign_unit", self.file, units=[unit1, unit2])
ifcopenshell.api.run("unit.remove_unit", self.file, unit=unit1)
assignment = ifcopenshell.api.unit.assign_unit(self.file, units=[unit1, unit2])
ifcopenshell.api.unit.remove_unit(self.file, unit=unit1)
assert len(self.file.by_type("IfcContextDependentUnit")) == 0
assert assignment.Units == (unit2,)
def test_removing_a_unit_deeply(self):
unit = ifcopenshell.api.run("unit.add_conversion_based_unit", self.file, name="foot")
ifcopenshell.api.run("unit.remove_unit", self.file, unit=unit)
unit = ifcopenshell.api.unit.add_conversion_based_unit(self.file, name="foot")
ifcopenshell.api.unit.remove_unit(self.file, unit=unit)
assert len([e for e in self.file]) == 0
@@ -17,29 +17,29 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import test.bootstrap
import ifcopenshell.api
import ifcopenshell.api.unit
class TestUnassignUnit(test.bootstrap.IFC4):
def test_run(self):
project = self.file.createIfcProject()
unit1 = ifcopenshell.api.run("unit.add_monetary_unit", self.file, currency="USD")
unit2 = ifcopenshell.api.run("unit.add_monetary_unit", self.file, currency="JPY")
assignment = ifcopenshell.api.run("unit.assign_unit", self.file, units=[unit1, unit2])
ifcopenshell.api.run("unit.unassign_unit", self.file, units=[unit1])
unit1 = ifcopenshell.api.unit.add_monetary_unit(self.file, currency="USD")
unit2 = ifcopenshell.api.unit.add_monetary_unit(self.file, currency="JPY")
assignment = ifcopenshell.api.unit.assign_unit(self.file, units=[unit1, unit2])
ifcopenshell.api.unit.unassign_unit(self.file, units=[unit1])
assert unit1 not in assignment.Units
assert unit2 in assignment.Units
def test_unassigning_the_last_unit(self):
project = self.file.createIfcProject()
unit = ifcopenshell.api.run("unit.add_monetary_unit", self.file, currency="USD")
ifcopenshell.api.run("unit.assign_unit", self.file, units=[unit])
ifcopenshell.api.run("unit.unassign_unit", self.file, units=[unit])
unit = ifcopenshell.api.unit.add_monetary_unit(self.file, currency="USD")
ifcopenshell.api.unit.assign_unit(self.file, units=[unit])
ifcopenshell.api.unit.unassign_unit(self.file, units=[unit])
assert project.UnitsInContext is None
def test_doing_nothing_if_the_unit_is_not_assigned(self):
unit = ifcopenshell.api.run("unit.add_monetary_unit", self.file, currency="USD")
assert ifcopenshell.api.run("unit.unassign_unit", self.file, units=[unit]) is None
unit = ifcopenshell.api.unit.add_monetary_unit(self.file, currency="USD")
assert ifcopenshell.api.unit.unassign_unit(self.file, units=[unit]) is None
class TestUnassignUnitIFC2X3(test.bootstrap.IFC2X3, TestUnassignUnit):