mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-24 22:27:55 -05:00
#14772 Create the export folder on demand in exportCompletions and exportMswCompletions
The legacy exportMsw and exportWellPathCompletions commands relied on the export implementation creating the folder (RicWellPathExportCompletionsFileTools::openFileForExport), so the default <project>/completions folder worked on a fresh project. The new Rimc methods rejected a non-existent folder up front. Create it instead, and only fail if that fails.
This commit is contained in:
1 parent
7cb5ee4363
commit
4148e7a5b1
2 files changed
+22
-4
No files matched your search
@@ -796,8 +796,12 @@ std::expected<caf::PdmObjectHandle*, QString> 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<caf::PdmObjectHandle*, QString> 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<RimWellPath*> wellPaths = m_wellPaths.ptrReferencedObjectsByType();
|
||||
if ( wellPaths.empty() ) return std::unexpected( "No well paths specified." );
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in new issue
Block a user