Skip to content

Commit

Permalink
change tests layout
Browse files Browse the repository at this point in the history
  • Loading branch information
payetvin committed Dec 24, 2024
1 parent 4c42da5 commit 4dd06fa
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 2 additions & 3 deletions src/solver/modeler/parameters/parseModelerParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ModelerParameters>();
}

Expand Down
1 change: 0 additions & 1 deletion src/tests/src/solver/modeler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
add_subdirectory(api)
add_subdirectory(loadFiles)
add_subdirectory(parameters)
21 changes: 8 additions & 13 deletions src/tests/src/solver/modeler/loadFiles/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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"(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,56 +21,46 @@
#define WIN32_LEAN_AND_MEAN

#include <fstream>
#define BOOST_TEST_MODULE parse modeler parameters

#include <boost/test/unit_test.hpp>

#include <antares/solver/modeler/parameters/parseModelerParameters.h>
#include <antares/solver/modeler/loadFiles/loadFiles.h>

#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()
7 changes: 0 additions & 7 deletions src/tests/src/solver/modeler/parameters/CMakeLists.txt

This file was deleted.

0 comments on commit 4dd06fa

Please sign in to comment.