diff --git a/ApplicationLibCode/ProjectDataModelCommands/RimcEclipseCase.cpp b/ApplicationLibCode/ProjectDataModelCommands/RimcEclipseCase.cpp index 8b1f88e974..f90efc2a5b 100644 --- a/ApplicationLibCode/ProjectDataModelCommands/RimcEclipseCase.cpp +++ b/ApplicationLibCode/ProjectDataModelCommands/RimcEclipseCase.cpp @@ -796,8 +796,12 @@ std::expected RimEclipseCase_exportCompletions:: if ( m_exportFolder().isEmpty() ) return std::unexpected( "No export folder specified." ); + // The export creates the folder on demand, matching the legacy command file behavior QDir folder( m_exportFolder() ); - if ( !folder.exists() ) return std::unexpected( QString( "The export folder '%1' does not exist." ).arg( m_exportFolder() ) ); + if ( !folder.exists() && !folder.mkpath( "." ) ) + { + return std::unexpected( QString( "The export folder '%1' does not exist and could not be created." ).arg( m_exportFolder() ) ); + } eclipseCase->ensureReservoirCaseIsOpen(); if ( !eclipseCase->eclipseCaseData() ) @@ -929,8 +933,12 @@ std::expected RimEclipseCase_exportMswCompletion if ( m_exportFolder().isEmpty() ) return std::unexpected( "No export folder specified." ); + // The export creates the folder on demand, matching the legacy command file behavior QDir folder( m_exportFolder() ); - if ( !folder.exists() ) return std::unexpected( QString( "The export folder '%1' does not exist." ).arg( m_exportFolder() ) ); + if ( !folder.exists() && !folder.mkpath( "." ) ) + { + return std::unexpected( QString( "The export folder '%1' does not exist and could not be created." ).arg( m_exportFolder() ) ); + } std::vector wellPaths = m_wellPaths.ptrReferencedObjectsByType(); if ( wellPaths.empty() ) return std::unexpected( "No well paths specified." ); diff --git a/GrpcInterface/Python/rips/tests/test_wells_path_completions.py b/GrpcInterface/Python/rips/tests/test_wells_path_completions.py index 88390cd427..d6128dca2c 100644 --- a/GrpcInterface/Python/rips/tests/test_wells_path_completions.py +++ b/GrpcInterface/Python/rips/tests/test_wells_path_completions.py @@ -56,10 +56,20 @@ def test_export_completions(rips_instance, initialize_test): files = os.listdir(tmpdirname) assert len(files) >= 1 + with tempfile.TemporaryDirectory(prefix="rips") as tmpdirname: + # A non-existent export folder is created on demand + export_folder = os.path.join(tmpdirname, "new_folder") + case.export_completions( + well_paths=[well_path], + time_step=1, + export_folder=export_folder, + file_split=rips.CompletionExportSplit.UNIFIED_FILE, + custom_file_name="created.sch", + ) + assert "created.sch" in os.listdir(export_folder) + with pytest.raises(rips.RipsError): case.export_completions(well_paths=[well_path]) - with pytest.raises(rips.RipsError): - case.export_completions(well_paths=[well_path], export_folder="/does/not/exist") def test_add_well_path_completions(rips_instance, initialize_test):