From 4dd06fa588d6fe2122fe7f59c78ed164cb777bd0 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Tue, 24 Dec 2024 15:42:45 +0100 Subject: [PATCH] change tests layout --- .../parameters/parseModelerParameters.h | 2 +- .../parameters/parseModelerParameters.cpp | 5 +- src/tests/src/solver/modeler/CMakeLists.txt | 1 - .../solver/modeler/loadFiles/CMakeLists.txt | 21 +++---- .../loadFiles/testLoadModelerFiles.cpp | 2 +- .../testParameters.cpp} | 56 ++++++++----------- .../solver/modeler/parameters/CMakeLists.txt | 7 --- 7 files changed, 35 insertions(+), 59 deletions(-) rename src/tests/src/solver/modeler/{parameters/testParametersParsing.cpp => loadFiles/testParameters.cpp} (59%) delete mode 100644 src/tests/src/solver/modeler/parameters/CMakeLists.txt diff --git a/src/solver/modeler/parameters/include/antares/solver/modeler/parameters/parseModelerParameters.h b/src/solver/modeler/parameters/include/antares/solver/modeler/parameters/parseModelerParameters.h index cccbb96b15..f0c9bd7238 100644 --- a/src/solver/modeler/parameters/include/antares/solver/modeler/parameters/parseModelerParameters.h +++ b/src/solver/modeler/parameters/include/antares/solver/modeler/parameters/parseModelerParameters.h @@ -28,6 +28,6 @@ namespace Antares::Solver::LoadFiles { -ModelerParameters parseModelerParameters(const std::filesystem::path& studyPath); +ModelerParameters parseModelerParameters(const std::string& content); } // namespace Antares::Solver::LoadFiles diff --git a/src/solver/modeler/parameters/parseModelerParameters.cpp b/src/solver/modeler/parameters/parseModelerParameters.cpp index 46782344e4..470b7a66e4 100644 --- a/src/solver/modeler/parameters/parseModelerParameters.cpp +++ b/src/solver/modeler/parameters/parseModelerParameters.cpp @@ -29,10 +29,9 @@ namespace Antares::Solver::LoadFiles { -ModelerParameters parseModelerParameters(const std::filesystem::path& filePath) +ModelerParameters parseModelerParameters(const std::string& content) { - const auto contents = Antares::IO::readFile(filePath); - YAML::Node root = YAML::Load(contents); + YAML::Node root = YAML::Load(content); return root.as(); } diff --git a/src/tests/src/solver/modeler/CMakeLists.txt b/src/tests/src/solver/modeler/CMakeLists.txt index b5d0efe1f8..d532a0a77d 100644 --- a/src/tests/src/solver/modeler/CMakeLists.txt +++ b/src/tests/src/solver/modeler/CMakeLists.txt @@ -1,3 +1,2 @@ add_subdirectory(api) add_subdirectory(loadFiles) -add_subdirectory(parameters) diff --git a/src/tests/src/solver/modeler/loadFiles/CMakeLists.txt b/src/tests/src/solver/modeler/loadFiles/CMakeLists.txt index 816e2d54f3..896c759e06 100644 --- a/src/tests/src/solver/modeler/loadFiles/CMakeLists.txt +++ b/src/tests/src/solver/modeler/loadFiles/CMakeLists.txt @@ -1,15 +1,10 @@ -add_executable(load-modeler-files - testLoadModelerFiles.cpp) +include(${CMAKE_SOURCE_DIR}/tests/macros.cmake) -target_link_libraries(load-modeler-files - PRIVATE - Boost::unit_test_framework +add_boost_test(loadFiles + SRC + testLoadModelerFiles.cpp + testParameters.cpp + LIBS + Antares::modelerParameters Antares::loadModelerFiles - Antares::modelerParameters - test_utils_unit -) - -set_target_properties(load-modeler-files PROPERTIES FOLDER Unit-tests/test-writer) - -add_test(NAME load-modeler-files COMMAND load-modeler-files) -set_tests_properties(load-modeler-files PROPERTIES LABELS unit) + test_utils_unit) diff --git a/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp b/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp index d6868fdb45..6c0d8c288a 100644 --- a/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp +++ b/src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp @@ -52,7 +52,7 @@ struct FixtureLoadFile } }; -BOOST_FIXTURE_TEST_CASE(read_one_lib_file, FixtureLoadFile) +BOOST_FIXTURE_TEST_CASE(read_one_lib_treile, FixtureLoadFile) { std::ofstream libStream(libraryDirPath / "simple.yml"); libStream << R"( diff --git a/src/tests/src/solver/modeler/parameters/testParametersParsing.cpp b/src/tests/src/solver/modeler/loadFiles/testParameters.cpp similarity index 59% rename from src/tests/src/solver/modeler/parameters/testParametersParsing.cpp rename to src/tests/src/solver/modeler/loadFiles/testParameters.cpp index 9a283cba76..20b2750134 100644 --- a/src/tests/src/solver/modeler/parameters/testParametersParsing.cpp +++ b/src/tests/src/solver/modeler/loadFiles/testParameters.cpp @@ -21,56 +21,46 @@ #define WIN32_LEAN_AND_MEAN #include -#define BOOST_TEST_MODULE parse modeler parameters - #include -#include +#include #include "files-system.h" -BOOST_AUTO_TEST_SUITE(read_modeler_parameters) - -using namespace Antares::Solver::LoadFiles; - -BOOST_AUTO_TEST_CASE(all_properties_set) +BOOST_AUTO_TEST_CASE(read_parameters) { - const auto working_tmp_dir = CREATE_TMP_DIR_BASED_ON_TEST_NAME(); - const auto fileP = working_tmp_dir / "parameters.yml"; - { - std::ofstream param(fileP); - param << R"( -solver: sirius -solver-logs: false -solver-parameters: PRESOLVE 1 -no-output: true)"; - } + auto studyPath = CREATE_TMP_DIR_BASED_ON_TEST_NAME(); + std::ofstream paramStream(studyPath / "parameters.yml"); + paramStream << R"( + solver: sirius + solver-logs: false + solver-parameters: PRESOLVE 1 + no-output: true + )"; + paramStream.close(); - auto params = parseModelerParameters(fileP); + auto params = Antares::Solver::LoadFiles::loadParameters(studyPath); BOOST_CHECK_EQUAL(params.solver, "sirius"); BOOST_CHECK_EQUAL(params.solverLogs, false); BOOST_CHECK_EQUAL(params.solverParameters, "PRESOLVE 1"); BOOST_CHECK_EQUAL(params.noOutput, true); } -BOOST_AUTO_TEST_CASE(all_properties_set_out_of_order) +BOOST_AUTO_TEST_CASE(read_parameters_out_of_order) { - const auto working_tmp_dir = CREATE_TMP_DIR_BASED_ON_TEST_NAME(); - const auto fileP = working_tmp_dir / "parameters.yml"; - { - std::ofstream param(fileP); - param << R"( -solver-logs: false -solver: sirius -solver-parameters: PRESOLVE 1 -no-output: true)"; - } + auto studyPath = CREATE_TMP_DIR_BASED_ON_TEST_NAME(); + std::ofstream paramStream(studyPath / "parameters.yml"); + paramStream << R"( + solver-logs: false + solver: sirius + solver-parameters: PRESOLVE 1 + no-output: true + )"; + paramStream.close(); - auto params = parseModelerParameters(fileP); + auto params = Antares::Solver::LoadFiles::loadParameters(studyPath); BOOST_CHECK_EQUAL(params.solver, "sirius"); BOOST_CHECK_EQUAL(params.solverLogs, false); BOOST_CHECK_EQUAL(params.solverParameters, "PRESOLVE 1"); BOOST_CHECK_EQUAL(params.noOutput, true); } - -BOOST_AUTO_TEST_SUITE_END() diff --git a/src/tests/src/solver/modeler/parameters/CMakeLists.txt b/src/tests/src/solver/modeler/parameters/CMakeLists.txt deleted file mode 100644 index 3870a14e1f..0000000000 --- a/src/tests/src/solver/modeler/parameters/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -include(${CMAKE_SOURCE_DIR}/tests/macros.cmake) - -add_boost_test(parse-parameters - SRC testParametersParsing.cpp - LIBS - Antares::modelerParameters - test_utils_unit)