File tree Expand file tree Collapse file tree
src/SofaPython3/Sofa/Helper Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2020
2121#include < pybind11/pybind11.h>
2222
23- #include < SofaPython3/Sofa/Helper/Binding_Utils.h>
2423#include < SofaPython3/PythonFactory.h>
24+ #include < SofaPython3/Sofa/Helper/Binding_Utils.h>
25+
26+ #include < iomanip>
27+ #include < sofa/version.h>
2528
2629#include < sofa/helper/Utils.h>
2730
@@ -44,6 +47,20 @@ void moduleAddUtils(py::module &m) {
4447 Get the directory where is stored the sofa output data such as screenshots.
4548 )doc" ;
4649 utils.def_static (" GetSofaDataDirectory" , &sofa::helper::Utils::getSofaDataDirectory, GetSofaDataDirectoryDoc);
50+
51+ utils.def_static (" GetVersion" ,
52+ []()
53+ {
54+ std::stringstream version;
55+ constexpr auto major = SOFA_VERSION / 10000 ;
56+ constexpr auto minor = SOFA_VERSION / 100 % 100 ;
57+ version << ' v'
58+ << std::setfill (' 0' ) << std::setw (2 ) << major
59+ << " ."
60+ << std::setfill (' 0' ) << std::setw (2 ) << minor;
61+ return version.str ();
62+ },
63+ " Returns the version of SOFA as a string in the format 'vMM.mm', where MM is the major version and mm is the minor version." );
4764}
4865
4966
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ set(PYTHON_FILES
2222 ${CMAKE_CURRENT_SOURCE_DIR} /Core/Mass.py
2323 ${CMAKE_CURRENT_SOURCE_DIR} /Core/MyRestShapeForceField.py
2424 ${CMAKE_CURRENT_SOURCE_DIR} /Helper/Message.py
25+ ${CMAKE_CURRENT_SOURCE_DIR} /Helper/Version.py
2526 ${CMAKE_CURRENT_SOURCE_DIR} /Simulation/Node.py
2627 ${CMAKE_CURRENT_SOURCE_DIR} /Simulation/Simulation.py
2728 ${CMAKE_CURRENT_SOURCE_DIR} /Types/BoundingBox.py
Original file line number Diff line number Diff line change 1+ import Sofa
2+ import Sofa .Helper
3+ import unittest
4+
5+ class GetVersionTest (unittest .TestCase ):
6+ """
7+ Contains unit tests for verifying the existence and format of the `GetVersion` method
8+ in the `Sofa.Helper.Utils` module.
9+
10+ Includes tests to assert that the version is correctly formatted and meets the expected
11+ structure.
12+ """
13+ def test_exist (self ):
14+ self .assertTrue (hasattr (Sofa .Helper .Utils , "GetVersion" ))
15+
16+ def test_version_format (self ):
17+ version = Sofa .Helper .Utils .GetVersion ()
18+ print (f"SOFA Version: { version } " )
19+ self .assertTrue (version .startswith ('v' ))
20+ version = version .replace ('v' , '' )
21+ self .assertTrue (version .count ('.' ) == 1 )
22+ major , minor = version .split ('.' )
23+ self .assertTrue (major .isdigit ())
24+ self .assertTrue (minor .isdigit ())
25+ self .assertEqual (len (major ), 2 )
26+ self .assertEqual (len (minor ), 2 )
You can’t perform that action at this time.
0 commit comments