From 2f1c008eaddbb1a15aed57ee5d887dab731ccf84 Mon Sep 17 00:00:00 2001 From: Jason Marechal Date: Wed, 11 Oct 2023 11:26:06 +0200 Subject: [PATCH] Expect error if output path does not exist --- src/cpp/lpnamer/main/RunProblemGeneration.cpp | 3 ++- tests/cpp/lp_namer/ProblemGenerationTest.cpp | 16 ++++++++++++++++ tests/python/test_problem_generator_driver.py | 6 ------ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/cpp/lpnamer/main/RunProblemGeneration.cpp b/src/cpp/lpnamer/main/RunProblemGeneration.cpp index 8a880860dc..c54e451c8f 100644 --- a/src/cpp/lpnamer/main/RunProblemGeneration.cpp +++ b/src/cpp/lpnamer/main/RunProblemGeneration.cpp @@ -159,7 +159,8 @@ void RunProblemGeneration( << "Launching Problem Generation" << std::endl; if (!CreateDirectories( xpansion_output_dir, logger.get())) { - return; + throw LogUtils::XpansionError( + "Error creating LP directory", LOGLOCATION); } validateMasterFormulation(master_formulation, logger); std::string solver_name = "CBC"; // TODO Use solver selected by user diff --git a/tests/cpp/lp_namer/ProblemGenerationTest.cpp b/tests/cpp/lp_namer/ProblemGenerationTest.cpp index d5558b40a5..18f16faf46 100644 --- a/tests/cpp/lp_namer/ProblemGenerationTest.cpp +++ b/tests/cpp/lp_namer/ProblemGenerationTest.cpp @@ -45,4 +45,20 @@ TEST(InitializationTest, FoldersAreEmpty) { ArchiveIOGeneralException); EXPECT_FALSE(std::filesystem::exists(simulationDirectory / "garbage.txt")); +} + +TEST(InitializationTest, ErrorIfSimulationPathDoesNotExists) { + auto workingDirectory = + std::filesystem::temp_directory_path() / std::tmpnam(nullptr); + auto simulationDirectory = workingDirectory / "output" / "simulation"; + auto logger = emptyLogger(); + + EXPECT_THROW( + RunProblemGeneration(simulationDirectory, "integer", "", "", logger, + simulationDirectory / "logs.txt", "", false), + LogUtils::XpansionError); + auto lp = (simulationDirectory.parent_path() / + (simulationDirectory.filename().string() + "-Xpansion")) / + "lp"; + EXPECT_FALSE(std::filesystem::exists(lp)); } \ No newline at end of file diff --git a/tests/python/test_problem_generator_driver.py b/tests/python/test_problem_generator_driver.py index 40d0b2479e..21ae640e40 100644 --- a/tests/python/test_problem_generator_driver.py +++ b/tests/python/test_problem_generator_driver.py @@ -39,12 +39,6 @@ def test_problem_generator_data(self): assert problem_generator_driver.user_weights_file_path == self.empty_pblm_gen_data.user_weights_file_path assert problem_generator_driver.lp_namer_exe_path == self.empty_pblm_gen_data.lp_namer_exe_path - def test_output_path(self, tmp_path): - problem_generator_driver = ProblemGeneratorDriver( - self.empty_pblm_gen_data) - with pytest.raises(ProblemGeneratorDriver.OutputPathError): - problem_generator_driver.launch(tmp_path / "i_don_t_exist", False) - def test_lp_namer_exe_does_not_exit(self, tmp_path): self._create_empty_area_file(tmp_path)