mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-24 22:27:55 -05:00
Python: Reject overwriting source summary vectors
This commit is contained in:
1 parent
dc1cc8e243
commit
ef1ad39723
2 files changed
+32
-5
No files matched your search
@@ -22,6 +22,7 @@
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaPreferencesSummary.h"
|
||||
|
||||
#include "RifEclipseSummaryAddress.h"
|
||||
#include "RifEclipseSummaryTools.h"
|
||||
#include "RifMultipleSummaryReaders.h"
|
||||
#include "RifOpmCommonSummary.h"
|
||||
@@ -358,6 +359,17 @@ std::expected<void, QString>
|
||||
return std::unexpected( errorMsg );
|
||||
}
|
||||
|
||||
auto address = RifEclipseSummaryAddress::fromEclipseTextAddressParseErrorTokens( keyword );
|
||||
auto fileReader = m_multiSummaryReader->findReader( m_fileSummaryReaderId );
|
||||
if ( fileReader && fileReader->hasAddress( address ) )
|
||||
{
|
||||
QString errorMsg = QString( "Cannot set summary values for '%1' because the vector comes from the source summary file. "
|
||||
"Use a new summary vector address instead." )
|
||||
.arg( QString::fromStdString( keyword ) );
|
||||
RiaLogging::error( errorMsg.toStdString() );
|
||||
return std::unexpected( errorMsg );
|
||||
}
|
||||
|
||||
// Validate value count matches main summary file
|
||||
size_t mainSummaryFileValueCount = m_multiSummaryReader->timeSteps( RifEclipseSummaryAddress() ).size();
|
||||
if ( values.size() != mainSummaryFileValueCount )
|
||||
|
||||
@@ -102,16 +102,31 @@ def test_summary_set_values(rips_instance, initialize_test):
|
||||
summary_data = summary_case.summary_vector_values("FOPT")
|
||||
assert len(summary_data.values) == 60
|
||||
|
||||
summary_case.set_summary_values("FOPT_1", "", summary_data.values)
|
||||
generated_summary_data = summary_case.summary_vector_values("FOPT_1")
|
||||
assert len(generated_summary_data.values) == 60
|
||||
# Vectors from the source summary file cannot be overwritten
|
||||
original_values = list(summary_data.values)
|
||||
with pytest.raises(Exception) as exc_info:
|
||||
summary_case.set_summary_values("FOPT", "", [1.0] * len(original_values))
|
||||
assert "source summary file" in str(exc_info.value).lower()
|
||||
assert summary_case.summary_vector_values("FOPT").values == pytest.approx(
|
||||
original_values
|
||||
)
|
||||
|
||||
generated_values = [value + 1.0 for value in original_values]
|
||||
summary_case.set_summary_values("FOPT_1", "", generated_values)
|
||||
assert summary_case.summary_vector_values("FOPT_1").values == pytest.approx(
|
||||
generated_values
|
||||
)
|
||||
|
||||
addresses = summary_case.available_addresses()
|
||||
current_keyword_count = len(addresses.values)
|
||||
assert current_keyword_count == original_keyword_count + 1
|
||||
|
||||
# Using existing keyword will overwrite existing data
|
||||
summary_case.set_summary_values("FOPT_1", "", summary_data.values)
|
||||
# A previously generated vector can be overwritten
|
||||
overwritten_values = [value + 2.0 for value in original_values]
|
||||
summary_case.set_summary_values("FOPT_1", "", overwritten_values)
|
||||
assert summary_case.summary_vector_values("FOPT_1").values == pytest.approx(
|
||||
overwritten_values
|
||||
)
|
||||
addresses = summary_case.available_addresses()
|
||||
current_keyword_count = len(addresses.values)
|
||||
assert current_keyword_count == original_keyword_count + 1
|
||||
|
||||
Reference in new issue
Block a user