Skip to content

Commit

Permalink
Deduce archive name from xpansion output name
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonMarechal25 committed Nov 2, 2023
1 parent f5f6bc8 commit 9f58e2d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
9 changes: 8 additions & 1 deletion src/cpp/lpnamer/main/ProblemGeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ std::filesystem::path ProblemGeneration::updateProblems() {

xpansion_output_dir =
deduceXpansionDirIfEmpty(xpansion_output_dir, archive_path);
if (archive_path.empty() && !xpansion_output_dir.empty()) {
archive_path = xpansion_output_dir;
auto dir_name = archive_path.stem().string();
dir_name = dir_name.substr(0, dir_name.find("-Xpansion"));
archive_path =
archive_path.replace_filename(dir_name).replace_extension(".zip");
}

const auto log_file_path =
xpansion_output_dir / "lp" / "ProblemGenerationLog.txt";
Expand All @@ -69,7 +76,7 @@ std::filesystem::path ProblemGeneration::updateProblems() {
std::filesystem::path ProblemGeneration::deduceXpansionDirIfEmpty(
std::filesystem::path xpansion_output_dir,
const std::filesystem::path& archive_path) {
if (xpansion_output_dir.string().empty() && !archive_path.string().empty()) {
if (xpansion_output_dir.empty() && !archive_path.empty()) {
auto deduced_dir = archive_path;
deduced_dir = deduced_dir.replace_filename(
deduced_dir.stem().replace_extension("").string() + "-Xpansion");
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/lpnamer/main/ProblemGenerationExeOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ProblemGenerationExeOptions::ProblemGenerationExeOptions()
AddOptions()("help,h", "produce help message")(
"output,o", po::value<std::filesystem::path>(&xpansion_output_dir_),
"antares-xpansion study output")(
"archive,a", po::value<std::filesystem::path>(&archive_path_)->required(),
"archive,a", po::value<std::filesystem::path>(&archive_path_),
"antares-xpansion study zip")(
"formulation,f",
po::value<std::string>(&master_formulation_)->default_value("relaxed"),
Expand Down
10 changes: 0 additions & 10 deletions tests/cpp/full_run/FullRunTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ class FullRunOptionsParserTestParameterizedMethod
FullRunOptionsParser full_run_options_options_parser_;
};

TEST_F(FullRunOptionsParserTest, ThatArchiveFileIsRequired) {
const char argv0[] = "full_run.exe";
std::vector<const char*> ppargv = {argv0};
try {
full_run_options_options_parser_.Parse(1, ppargv.data());
} catch (const std::exception& e) {
EXPECT_EQ(e.what(),
std::string("the option '--archive' is required but missing"));
}
}
TEST_F(FullRunOptionsParserTest, ThatBendersOptionFileIsRequired) {
const char argv0[] = "full_run.exe";
const char argv1[] = "--archive";
Expand Down
23 changes: 23 additions & 0 deletions tests/cpp/lp_namer/ProblemGenerationExeOptionsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,26 @@ TEST_F(ProblemGenerationExeOptionsTest,
EXPECT_TRUE(std::filesystem::exists(output_path));
EXPECT_TRUE(std::filesystem::exists(output_path / "lp"));
}

TEST_F(ProblemGenerationExeOptionsTest,
OutputAndArchiveParameters_deduceArchiveFromOutputDir) {
auto test_root =
std::filesystem::temp_directory_path() / std::tmpnam(nullptr);
auto archive = test_root / "study.zip";
auto output_path = test_root / "study-Xpansion";

const char argv0[] = "lp.exe ";
const char argv1[] = "--output";
auto argv2 = output_path.string();

std::vector<const char*> ppargv = {argv0, argv1, argv2.c_str()};
problem_generation_options_parser_.Parse(3, ppargv.data());

ProblemGenerationSpyAndMock pbg(problem_generation_options_parser_);
pbg.updateProblems();

EXPECT_EQ(pbg.archive_path_, archive);
EXPECT_EQ(pbg.xpansion_output_dir_, output_path);
EXPECT_TRUE(std::filesystem::exists(output_path));
EXPECT_TRUE(std::filesystem::exists(output_path / "lp"));
}

0 comments on commit 9f58e2d

Please sign in to comment.