Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion bindings/Sofa/src/SofaPython3/Sofa/Helper/Binding_Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@

#include <pybind11/pybind11.h>

#include <SofaPython3/Sofa/Helper/Binding_Utils.h>
#include <SofaPython3/PythonFactory.h>
#include <SofaPython3/Sofa/Helper/Binding_Utils.h>

#include <iomanip>
#include <sofa/version.h>

#include <sofa/helper/Utils.h>

Expand All @@ -44,6 +47,20 @@ void moduleAddUtils(py::module &m) {
Get the directory where is stored the sofa output data such as screenshots.
)doc";
utils.def_static("GetSofaDataDirectory", &sofa::helper::Utils::getSofaDataDirectory, GetSofaDataDirectoryDoc);

utils.def_static("GetVersion",
[]()
{
std::stringstream version;
constexpr auto major = SOFA_VERSION / 10000;
constexpr auto minor = SOFA_VERSION / 100 % 100;
version << 'v'
<< std::setfill('0') << std::setw(2) << major
<< "."
<< std::setfill('0') << std::setw(2) << minor;
return version.str();
},
"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.");
}


Expand Down
1 change: 1 addition & 0 deletions bindings/Sofa/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ set(PYTHON_FILES
${CMAKE_CURRENT_SOURCE_DIR}/Core/Mass.py
${CMAKE_CURRENT_SOURCE_DIR}/Core/MyRestShapeForceField.py
${CMAKE_CURRENT_SOURCE_DIR}/Helper/Message.py
${CMAKE_CURRENT_SOURCE_DIR}/Helper/Version.py
${CMAKE_CURRENT_SOURCE_DIR}/Simulation/Node.py
${CMAKE_CURRENT_SOURCE_DIR}/Simulation/Simulation.py
${CMAKE_CURRENT_SOURCE_DIR}/Types/BoundingBox.py
Expand Down
26 changes: 26 additions & 0 deletions bindings/Sofa/tests/Helper/Version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Sofa
import Sofa.Helper
import unittest

class GetVersionTest(unittest.TestCase):
"""
Contains unit tests for verifying the existence and format of the `GetVersion` method
in the `Sofa.Helper.Utils` module.

Includes tests to assert that the version is correctly formatted and meets the expected
structure.
"""
def test_exist(self):
self.assertTrue(hasattr(Sofa.Helper.Utils, "GetVersion"))

def test_version_format(self):
version = Sofa.Helper.Utils.GetVersion()
print(f"SOFA Version: {version}")
self.assertTrue(version.startswith('v'))
version = version.replace('v', '')
self.assertTrue(version.count('.') == 1)
major, minor = version.split('.')
self.assertTrue(major.isdigit())
self.assertTrue(minor.isdigit())
self.assertEqual(len(major), 2)
self.assertEqual(len(minor), 2)
Loading