small fixes after d209cc9ff, added a test

This commit is contained in:
Andrej730
2024-03-11 15:15:06 +05:00
parent a064173ffe
commit 0576914e07
2 changed files with 8 additions and 2 deletions
@@ -566,8 +566,8 @@ def convert(value, from_prefix, from_unit, to_prefix, to_unit):
return value
def calculate_unit_scale(ifc_file, unit_type='LENGTHUNIT'):
"""Returns a unit scale factor to convert to and from IFC project length units and SI meters
def calculate_unit_scale(ifc_file, unit_type="LENGTHUNIT"):
"""Returns a unit scale factor to convert to and from IFC project units and SI units.
Example:
@@ -20,6 +20,7 @@ import pytest
import test.bootstrap
import ifcopenshell.api
import ifcopenshell.util.unit as subject
from math import pi
class TestCalculateUnitScale(test.bootstrap.IFC4):
@@ -30,6 +31,11 @@ class TestCalculateUnitScale(test.bootstrap.IFC4):
ifcopenshell.api.run("unit.assign_unit", self.file, units=[length])
assert subject.calculate_unit_scale(self.file) == 0.3048 * 0.001
angle = ifcopenshell.api.run("unit.add_conversion_based_unit", self.file, name="degree")
angle.ConversionFactor.UnitComponent.Prefix = "MILLI"
ifcopenshell.api.run("unit.assign_unit", self.file, units=[angle])
assert subject.calculate_unit_scale(self.file, "PLANEANGLEUNIT") == pi / 180 * 0.001
class TestFormatLength(test.bootstrap.IFC4):
def test_run(self):