From b8adddc6488065d26d8ced1cb8b64ee1ed6cf2b9 Mon Sep 17 00:00:00 2001 From: Esteban Dugueperoux <43169544+EstebanDugueperoux2@users.noreply.github.com> Date: Tue, 11 Nov 2025 18:25:00 +0100 Subject: [PATCH] fix test_number_formatting tests and add cases (#7332) --- src/ifcopenshell-python/ifcopenshell/util/selector.py | 3 ++- src/ifcopenshell-python/test/util/test_selector.py | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/selector.py b/src/ifcopenshell-python/ifcopenshell/util/selector.py index 6e94fb1d06..5cc0eb6091 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/selector.py +++ b/src/ifcopenshell-python/ifcopenshell/util/selector.py @@ -259,6 +259,7 @@ class FormatTransformer(lark.Transformer): ) def imperial_length(self, args): + args = list(filter(lambda x: x is not None, args)) if len(args) == 2: input_unit, output_unit = "foot", "foot" value, precision = args @@ -279,7 +280,7 @@ class FormatTransformer(lark.Transformer): return ifcopenshell.util.unit.format_length( float(value), int(precision), - suppress_zero_inches=suppress_zero_inches, + suppress_zero_inches=(suppress_zero_inches if suppress_zero_inches is not None else False), unit_system="imperial", input_unit=input_unit, output_unit=output_unit, diff --git a/src/ifcopenshell-python/test/util/test_selector.py b/src/ifcopenshell-python/test/util/test_selector.py index 36d200539a..7869d1c645 100644 --- a/src/ifcopenshell-python/test/util/test_selector.py +++ b/src/ifcopenshell-python/test/util/test_selector.py @@ -73,6 +73,10 @@ class TestFormat: assert subject.format('imperial_length("3.123", 2)') == "3' - 1 1/2\"" assert subject.format('imperial_length("123.123", 2, "inch", "foot")') == "10' - 3\"" assert subject.format('imperial_length("123.123", 2, "inch", "inch")') == '123"' + assert subject.format('imperial_length(3.0, 4, "foot", "foot", true)') == "3'" + assert subject.format('imperial_length(3.0, 4, "foot", "foot", True)') == "3'" + assert subject.format('imperial_length(3.0, 4, "foot", "foot", false)') == "3' - 0\"" + assert subject.format('imperial_length(3.0, 4, "foot", "foot", False)') == "3' - 0\"" class TestGetElementValue(test.bootstrap.IFC4):