Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

falken10vdl
Copy link
Contributor

This is a proposal to address issue #7073
Cheers!

@Andrej730
Copy link
Contributor

@falken10vdl

Looks good in general, a few things I've noticed.

  1. Some Bonsai tests are now failing.

  2. add_conversion_based_unit - if unit_type == "MASSUNIT": this will never be true for ton units, since they're not present in imperial_types. I think we can just add it to that dictionary, but probably should spell it as "tonne" - it seems to be the established way to spell "metric ton" https://en.wikipedia.org/wiki/Tonne

  3. Need to add tests for new behaviour in add_conversion_based_unit.

  4. unit.assign_unit - I'm not sure if we should introduce any arguments and code to handle them to assign_unit, since it's basically going to duplicate code from add_si_unit / add_conversion_based_unit and we were planning to deprecate existing length, area, volume arguments.

@falken10vdl
Copy link
Contributor Author

@Andrej730 Thanks a lot for the feedback. I have changed the error by adding TONNE as suggested. I have also added tests.
I add them here how to run them for my own reference ;)

falken10vdl@monster:~/bonsaiDevel/IfcOpenShell/src/ifcopenshell-python$ python -m pytest test/util/test_unit.py -v
Blender 4.5.2 LTS (hash ab25eae04993 built 2025-08-20 02:11:19)
module changed on disk: '/home/falken10vdl/.config/blender/4.5/extensions/blender_org/sun_position/__init__.py' reloading...

----------------------------------------------

No module named 'blenderbim'
Archipack ifc export fallback
Archipack PRO 2.8.2 : ready 

----------------------------------------------

🔄 blenderkit: Verbose is enabled
🔄 blenderkit: Read in JSON settings from file
ℹ️  blenderkit: Ports reordered so first port is now 62485 (previous index was 0) [20:21:44.910, client_lib.py:125]
Created history step c5fc304c-c138-49b8-96a0-eb97658ac250
ℹ️  blenderkit: Created new search history step [20:21:44.938, search.py:1736]
========================================================================================================================================== test session starts ==========================================================================================================================================
platform linux -- Python 3.11.11, pytest-8.4.1, pluggy-1.6.0 -- /home/falken10vdl/.local/share/applications/blender-4.5.2-linux-x64/4.5/python/bin/python3.11
cachedir: .pytest_cache
rootdir: /home/falken10vdl/bonsaiDevel/IfcOpenShell/src/ifcopenshell-python
configfile: pyproject.toml
plugins: bdd-8.1.0
collected 38 items                                                                                                                                                                                                                                                                                      

test/util/test_unit.py::TestCacheUnits::test_run PASSED                                                                                                                                                                                                                                           [  2%]
test/util/test_unit.py::TestClearUnitCache::test_run PASSED                                                                                                                                                                                                                                       [  5%]
test/util/test_unit.py::TestGetProjectUnit::test_run PASSED                                                                                                                                                                                                                                       [  7%]
test/util/test_unit.py::TestGetProjectUnit::test_using_a_cache PASSED                                                                                                                                                                                                                             [ 10%]
test/util/test_unit.py::TestGetPropertyUnit::test_no_unit PASSED                                                                                                                                                                                                                                  [ 13%]
test/util/test_unit.py::TestGetPropertyUnit::test_simple_quantity PASSED                                                                                                                                                                                                                          [ 15%]
test/util/test_unit.py::TestGetPropertyUnit::test_single_value PASSED                                                                                                                                                                                                                             [ 18%]
test/util/test_unit.py::TestGetPropertyUnit::test_enumerated_value PASSED                                                                                                                                                                                                                         [ 21%]
test/util/test_unit.py::TestGetPropertyUnit::test_list_value PASSED                                                                                                                                                                                                                               [ 23%]
test/util/test_unit.py::TestGetPropertyUnit::test_bounded_value PASSED                                                                                                                                                                                                                            [ 26%]
test/util/test_unit.py::TestConvert::test_run PASSED                                                                                                                                                                                                                                              [ 28%]
test/util/test_unit.py::TestCalculateUnitScale::test_prefix_and_conversion_based_units_are_considered PASSED                                                                                                                                                                                      [ 31%]
test/util/test_unit.py::TestFormatLength::test_run PASSED                                                                                                                                                                                                                                         [ 34%]
test/util/test_unit.py::TestIsAttrType::test_run PASSED                                                                                                                                                                                                                                           [ 36%]
test/util/test_unit.py::TestConvertFileLengthUnits::test_run PASSED                                                                                                                                                                                                                               [ 39%]
test/util/test_unit.py::TestConvertFileLengthUnits::test_attribute_conversion PASSED                                                                                                                                                                                                              [ 42%]
test/util/test_unit.py::TestConvertFileLengthUnits::test_converting_map_conversion_if_there_is_no_map_unit PASSED                                                                                                                                                                                 [ 44%]
test/util/test_unit.py::TestConvertFileLengthUnits::test_preserving_enh_if_there_is_a_map_unit PASSED                                                                                                                                                                                             [ 47%]
test/util/test_unit.py::TestConvertFileLengthUnits::test_preserving_enh_if_there_is_a_map_unit_which_is_also_the_project_default PASSED                                                                                                                                                           [ 50%]
test/util/test_unit.py::TestConvertFileLengthUnitsIFC4::test_run PASSED                                                                                                                                                                                                                           [ 52%]
test/util/test_unit.py::TestConvertFileLengthUnitsIFC4::test_attribute_conversion PASSED                                                                                                                                                                                                          [ 55%]
test/util/test_unit.py::TestConvertFileLengthUnitsIFC4::test_converting_map_conversion_if_there_is_no_map_unit PASSED                                                                                                                                                                             [ 57%]
test/util/test_unit.py::TestConvertFileLengthUnitsIFC4::test_preserving_enh_if_there_is_a_map_unit PASSED                                                                                                                                                                                         [ 60%]
test/util/test_unit.py::TestConvertFileLengthUnitsIFC4::test_preserving_enh_if_there_is_a_map_unit_which_is_also_the_project_default PASSED                                                                                                                                                       [ 63%]
test/util/test_unit.py::TestConvertFileLengthUnitsIFC4X3::test_run PASSED                                                                                                                                                                                                                         [ 65%]
test/util/test_unit.py::TestConvertFileLengthUnitsIFC4X3::test_attribute_conversion PASSED                                                                                                                                                                                                        [ 68%]
test/util/test_unit.py::TestConvertFileLengthUnitsIFC4X3::test_converting_map_conversion_if_there_is_no_map_unit PASSED                                                                                                                                                                           [ 71%]
test/util/test_unit.py::TestConvertFileLengthUnitsIFC4X3::test_preserving_enh_if_there_is_a_map_unit PASSED                                                                                                                                                                                       [ 73%]
test/util/test_unit.py::TestConvertFileLengthUnitsIFC4X3::test_preserving_enh_if_there_is_a_map_unit_which_is_also_the_project_default PASSED                                                                                                                                                     [ 76%]
test/util/test_unit.py::TestAddConversionBasedUnitMassAndTime::test_adding_mass_units_creates_proper_massunit PASSED                                                                                                                                                                              [ 78%]
test/util/test_unit.py::TestAddConversionBasedUnitMassAndTime::test_adding_time_units_creates_proper_timeunit PASSED                                                                                                                                                                              [ 81%]
test/util/test_unit.py::TestAddConversionBasedUnitMassAndTime::test_mass_unit_integration_with_project PASSED                                                                                                                                                                                     [ 84%]
test/util/test_unit.py::TestAddConversionBasedUnitMassAndTime::test_time_unit_integration_with_project PASSED                                                                                                                                                                                     [ 86%]
test/util/test_unit.py::TestAddConversionBasedUnitMassAndTime::test_multiple_unit_types_can_coexist PASSED                                                                                                                                                                                        [ 89%]
test/util/test_unit.py::TestAddConversionBasedUnitMassAndTime::test_unknown_mass_or_time_units_fall_back_to_userdefined PASSED                                                                                                                                                                    [ 92%]
test/util/test_unit.py::TestAddConversionBasedUnitMassAndTime::test_mass_units_individually PASSED                                                                                                                                                                                                [ 94%]
test/util/test_unit.py::TestAddConversionBasedUnitMassAndTime::test_time_units_individually PASSED                                                                                                                                                                                                [ 97%]
test/util/test_unit.py::TestMassAndTimeUnitDictionaries::test_mass_units_in_imperial_types PASSED                                                                                                                                                                                                 [100%]

========================================================================================================================================== 38 passed in 0.16s ===========================================================================================================================================
ℹ️  blenderkit: Unregistering BlenderKit add-on [20:21:45.628, __init__.py:2553]
falken10vdl@monster:~/bonsaiDevel/IfcOpenShell/src/ifcopenshell-python$ cd -
/home/falken10vdl/bonsaiDevel/IfcOpenShell/src/bonsai
falken10vdl@monster:~/bonsaiDevel/IfcOpenShell/src/bonsai$ pytest -p no:pytest-blender test/core/test_unit.py 
========================================================================================================================================== test session starts ==========================================================================================================================================
platform linux -- Python 3.11.13, pytest-8.4.1, pluggy-1.6.0
rootdir: /home/falken10vdl/bonsaiDevel/IfcOpenShell/src/bonsai
configfile: pytest.ini
plugins: blender-3.0.7, bdd-8.1.0
collected 30 items                                                                                                                                                                                                                                                                                      

test/core/test_unit.py ..............................                                                                                                                                                                                                                                             [100%]

========================================================================================================================================== 30 passed in 0.03s ===========================================================================================================================================
falken10vdl@monster:~/bonsaiDevel/IfcOpenShell/src/bonsai$ python -m pytest test/tool/test_unit.py
Blender 4.5.2 LTS (hash ab25eae04993 built 2025-08-20 02:11:19)
module changed on disk: '/home/falken10vdl/.config/blender/4.5/extensions/blender_org/sun_position/__init__.py' reloading...

----------------------------------------------

No module named 'blenderbim'
Archipack ifc export fallback
Archipack PRO 2.8.2 : ready 

----------------------------------------------

🔄 blenderkit: Verbose is enabled
🔄 blenderkit: Read in JSON settings from file
ℹ️  blenderkit: Ports reordered so first port is now 62485 (previous index was 0) [20:22:08.426, client_lib.py:125]
Created history step 30aaa3b4-eb65-444b-acc7-8eaaf7d2f141
ℹ️  blenderkit: Created new search history step [20:22:08.455, search.py:1736]
========================================================================================================================================== test session starts ==========================================================================================================================================
platform linux -- Python 3.11.11, pytest-8.4.1, pluggy-1.6.0
rootdir: /home/falken10vdl/bonsaiDevel/IfcOpenShell/src/bonsai
configfile: pytest.ini
plugins: blender-3.0.7, bdd-8.1.0
collected 29 items                                                                                                                                                                                                                                                                                      

test/tool/test_unit.py .............................                                                                                                                                                                                                                                              [100%]

========================================================================================================================================== 29 passed in 0.75s ===========================================================================================================================================
ℹ️  blenderkit: Unregistering BlenderKit add-on [20:22:09.735, __init__.py:2553]
falken10vdl@monster:~/bonsaiDevel/IfcOpenShell/src/bonsai$ ^C
falken10vdl@monster:~/bonsaiDevel/IfcOpenShell/src/bonsai$ 


unit.assign_unit - I'm not sure if we should introduce any arguments and code to handle them to assign_unit, since it's basically going to duplicate code from add_si_unit / add_conversion_based_unit and we were planning to deprecate existing length, area, volume arguments.

I just followed the pattern for length, area, volume arguments. What would you suggest to do?

Thanks!

@Andrej730
Copy link
Contributor

@falken10vdl

  1. src/ifcopenshell-python/test/util/test_unit.py - it's a wrong place for add_conversion_based_unit tests, we typically use api package for api tests - https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.8.0/src/ifcopenshell-python/test/api/unit/test_add_conversion_based_unit.py

  2. I just followed the pattern for length, area, volume arguments. What would you suggest to do?

    To avoid adding new arguments, since we plan to deprecate previous ones.

  3. TestMassAndTimeUnitDictionaries - there's misindentation, so test_mass_units_in_imperial_types and other methods are considered to be local to test_mass_units_in_imperial_types and never actually executed.

    And what's the idea for those tests? It seems they're just rechecking the values of the constants that already defined in the dictionaries.

  4. test_mass_unit_integration_with_project, test_time_unit_integration_with_project, test_multiple_unit_types_can_coexist - those tests seems to be unrelated to add_conversion_based_unit.

  5. test_unknown_mass_or_time_units_fall_back_to_userdefined - why checking it twice if there's no distinction between mass and time units in this case?

  6. test_mass_units_individually, test_time_units_individually - those do exactly the same as test_adding_mass_units_creates_proper_massunit and test_adding_time_units_creates_proper_timeunit.

@falken10vdl
Copy link
Contributor Author

@Andrej730

src/ifcopenshell-python/test/util/test_unit.py - it's a wrong place for add_conversion_based_unit tests, we typically use api package for api tests - https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.8.0/src/ifcopenshell-python/test/api/unit/test_add_conversion_based_unit.py

ok removed form test_unit.py and moved to test_add_conversion_based_unit.py

To avoid adding new arguments, since we plan to deprecate previous ones.

I have removed the parameters

TestMassAndTimeUnitDictionaries - there's misindentation, so test_mass_units_in_imperial_types and other methods are considered to be local to test_mass_units_in_imperial_types and never actually executed. And what's the idea for those tests? It seems they're just rechecking the values of the constants that already defined in the dictionaries.

Yes, those follow under the category of "testing constants". I agree that probably do not make much sense since the dictionary team and the testing team are the same developers :) I can remove them if that is creating confusion

test_mass_unit_integration_with_project, test_time_unit_integration_with_project, test_multiple_unit_types_can_coexist - those tests seems to be unrelated to add_conversion_based_unit.

Yes I removed them (may be more related to assing_unit)

test_unknown_mass_or_time_units_fall_back_to_userdefined - why checking it twice if there's no distinction between mass and time units in this case?

Agree. Reduced to one

test_mass_units_individually, test_time_units_individually - those do exactly the same as test_adding_mass_units_creates_proper_massunit and test_adding_time_units_creates_proper_timeunit.

Agree. Reduced

@Andrej730
Copy link
Contributor

@falken10vdl

moved to test_add_conversion_based_unit.py

Tests are added only to IFC4 test class, they should be added to IFC2X3 test class so they would be executed for both IFC2X3 and IFC4.

I have removed the parameters

They're still present in assign_unit doc-string.

Yes, those follow under the category of "testing constants". I agree that probably do not make much sense since the dictionary team and the testing team are the same developers :) I can remove them if that is creating confusion

I don't think we need them. Also, those constants are already checked in test_adding_mass_units_creates_proper_massunit, test_adding_time_units_creates_proper_timeunit.

@falken10vdl
Copy link
Contributor Author

@Andrej730

Tests are added only to IFC4 test class, they should be added to IFC2X3 test class so they would be executed for both IFC2X3 and IFC4.

Done

They're still present in assign_unit doc-string.

I just put an example but not provided as explicit parameter

I don't think we need them. Also, those constants are already checked in test_adding_mass_units_creates_proper_massunit, test_adding_time_units_creates_proper_timeunit.

Removed

@Moult
Copy link
Contributor

Moult commented Sep 16, 2025

Is it worth having this in the wizard? Mass and time are not used by everyone. It's not hard to add later on in the units panel.

@falken10vdl
Copy link
Contributor Author

As you wish. I think this was brought by @steverugi which is something useful for Costing and Scheduling. Maybe moving it to that panel would make sense?
Cheers!

@steverugi
Copy link

steverugi commented Sep 16, 2025

@Moult , @falken10vdl
I agree both are not indispensable, just convenient for those who need them, if a problem to have them as default they can be added later

@falken10vdl
Copy link
Contributor Author

@Moult @steverugi Maybe an option is to just add a toggle to add or remove mass&time units. By defualt it is off.
Something like this:

Kooha-2025-09-16-17-45-12.mp4

Cheers!

@steverugi
Copy link

@Moult @steverugi Maybe an option is to just add a toggle to add or remove mass&time units. By defualt it is off. Something like this:

Cheers!

Love it! thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants