Skip to content

Commit

Permalink
First test case
Browse files Browse the repository at this point in the history
  • Loading branch information
payetvin committed Dec 19, 2024
1 parent 2fb43d6 commit ad4ca2d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#pragma once

#include <filesystem>
#include <vector>

#include <antares/study/system-model/library.h>
#include <antares/study/system-model/system.h>
Expand All @@ -32,4 +33,6 @@ namespace Antares::Solver::LoadFiles
Study::SystemModel::System loadSystem(const std::filesystem::path& studyPath,
const std::vector<Study::SystemModel::Library>& libraries);

std::vector<Study::SystemModel::Library> loadLibraries(const std::filesystem::path& studyPath);

} // namespace Antares::Solver::LoadFiles
2 changes: 1 addition & 1 deletion src/solver/modeler/loadFiles/readLibraries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ std::vector<Study::SystemModel::Library> loadLibraries(const fs::path& studyPath
const fs::path directoryPath = studyPath / "input" / "model-libraries";
for (const auto& entry: fs::directory_iterator(directoryPath))
{
if (entry.path().extension() != "yml")
if (entry.path().extension() != ".yml")
{
logs.info() << "File ignored because of wrong extension: " << entry.path();
continue;
Expand Down
51 changes: 34 additions & 17 deletions src/tests/src/solver/modeler/loadFiles/testLoadModelerFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,41 @@

BOOST_AUTO_TEST_SUITE(read_modeler_parameters)

BOOST_AUTO_TEST_CASE(all_properties_set)
namespace fs = std::filesystem;

struct FixtureLoadFile
{
fs::path studyPath;
fs::path inputPath;
fs::path libraryDirPath;

FixtureLoadFile()
{
studyPath = CREATE_TMP_DIR_BASED_ON_TEST_NAME();
inputPath = createFolder(studyPath, "input");
libraryDirPath = createFolder(inputPath, "model-libraries");
}

~FixtureLoadFile()
{
fs::remove_all(studyPath);
}
};

BOOST_FIXTURE_TEST_CASE(read_one_lib_file, FixtureLoadFile)
{
/* const auto working_tmp_dir = CREATE_TMP_DIR_BASED_ON_TEST_NAME(); */
/* const auto fileP = working_tmp_dir / "parameters.yaml"; */
/* { */
/* std::ofstream param(fileP); */
/* param << R"( */
/* solver: sirius */
/* solver-logs: false */
/* solver-parameters: PRESOLVE 1 */
/* no-output: true)"; */
/* } */

/* auto params = Antares::Solver::parseModelerParameters(fileP); */
/* 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); */
std::ofstream libStream(libraryDirPath / "simple.yml");
libStream << R"(
library:
id: lib_id
description: lib_description
port-types: []
models: []
)";
libStream.close();

auto libraries = Antares::Solver::LoadFiles::loadLibraries(studyPath);
/* BOOST_CHECK_EQUAL(libraries[0].Id(), "lib_id"); */
}

BOOST_AUTO_TEST_SUITE_END()
4 changes: 3 additions & 1 deletion src/tests/src/utils/files-system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fs::path generateAndCreateDirName(const std::string& dirName)
return working_dir;
}

void createFolder(const std::string& path, const std::string& folder_name)
fs::path createFolder(const std::string& path, const std::string& folder_name)
{
fs::path folder_path = fs::path(path.c_str()) / folder_name.c_str();

Expand All @@ -22,6 +22,8 @@ void createFolder(const std::string& path, const std::string& folder_name)
{
std::cerr << "Exception creating folder '" + folder_name + "': " + e.what() + "\n";
}

return folder_path;
}

void createFile(const std::string& folder_path, const std::string& file_name)
Expand Down
2 changes: 1 addition & 1 deletion src/tests/src/utils/files-system.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@

std::filesystem::path generateAndCreateDirName(const std::string&);

void createFolder(const std::string& path, const std::string& folder_name);
std::filesystem::path createFolder(const std::string& path, const std::string& folder_name);
void createFile(const std::string& folder_path, const std::string& file_name);
void removeFolder(std::string& path, std::string& folder_name);

0 comments on commit ad4ca2d

Please sign in to comment.