Skip to content

Commit

Permalink
Added restart test to summary testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
joakim-hove committed Feb 5, 2018
1 parent b123694 commit a96e96c
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 6 deletions.
22 changes: 19 additions & 3 deletions python/ecl/test/ecl_mock/ecl_sum_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,33 @@ def mock_func(ecl_sum , key , days):
return days * 10


def createEclSum( case , keys , start = datetime.date(2010 , 1, 1) , sim_length_days = 5 * 365 , num_report_step = 5, num_mini_step = 10, dims = (20,10,5) , func_table = {}, restart_case = None):
ecl_sum = EclSum.restart_writer(case , restart_case, start , dims[0] , dims[1] , dims[2])
def createEclSum( case,
keys,
sim_start = datetime.date(2010 , 1, 1),
data_start = None,
sim_length_days = 5 * 365,
num_report_step = 5,
num_mini_step = 10,
dims = (20,10,5) ,
func_table = {},
restart_case = None):

ecl_sum = EclSum.restart_writer(case , restart_case, sim_start , dims[0] , dims[1] , dims[2])
var_list = []
for (kw,wgname,num) in keys:
var_list.append( ecl_sum.addVariable( kw , wgname = wgname , num = num) )

if data_start is None:
time_offset = 0
else:
dt = data_start - sim_start
time_offset = dt.total_seconds() / 86400.0

report_step_length = sim_length_days / num_report_step
mini_step_length = report_step_length / num_mini_step
for report_step in range(num_report_step):
for mini_step in range(num_mini_step):
days = report_step * report_step_length + mini_step * mini_step_length
days = time_offset + report_step * report_step_length + mini_step * mini_step_length
t_step = ecl_sum.addTStep( report_step + 1 , sim_days = days )

for var in var_list:
Expand Down
61 changes: 58 additions & 3 deletions python/tests/ecl_tests/test_sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
# See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
# for more details.

import os.path
import os
import inspect
import datetime
import csv
import shutil
from contextlib import contextmanager
from unittest import skipIf, skipUnless, skipIf

from ecl import EclDataType
Expand All @@ -28,6 +30,25 @@
from tests import EclTest
from ecl.test.ecl_mock import createEclSum


@contextmanager
def pushd(path):
if not os.path.isdir(path):
os.mkdir(path)
cwd = os.getcwd()
os.chdir(path)

yield

os.chdir(cwd)

def create_prediction(history, pred_path):
restart_case, _ = os.path.join( os.getcwd(), history.base)
with pushd(pred_path):
prediction = create_case( case = "PREDICTION", restart_case = restart_case, data_start = history.end_date)
prediction.fwrite()


def fopr(days):
return days

Expand All @@ -40,15 +61,17 @@ def fgpt(days):
else:
return 100 - days

def create_case():
def create_case(case = "CSV", restart_case = None, data_start = None):
length = 100
return createEclSum("CSV" , [("FOPT", None , 0) , ("FOPR" , None , 0), ("FGPT" , None , 0)],
return createEclSum(case , [("FOPT", None , 0) , ("FOPR" , None , 0), ("FGPT" , None , 0)],
sim_length_days = length,
num_report_step = 10,
num_mini_step = 10,
data_start = data_start,
func_table = {"FOPT" : fopt,
"FOPR" : fopr ,
"FGPT" : fgpt })
"FGPT" : fgpt },
restart_case = restart_case)

class SumTest(EclTest):

Expand Down Expand Up @@ -356,3 +379,35 @@ def test_resample(self):
time_vector_resample = case2.alloc_time_vector(False)
first_diff = time_vector_resample.first_neq( time_vector)
self.assertEqual( time_vector_resample, time_vector)



# The purpose of this test is to reproduce a slightly contrived error situation.
#
# 1. A history simulation is created and stored somewhere in the
# filesystem.
#
# 2. We create a prediction, which has 'RESTART' reference to
# the history case.
#
# 3. The prediction case is loaded from disk, with a cwd different from the
# location of the predition case.
#
# This configuration would previously lead to a bug in the path used to
# resolve the history case, and that silently be ignored.

def test_restart_abs_path(self):
with TestAreaContext("restart_test"):
history = create_case(case = "HISTORY")
history.fwrite()

pred_path = "prediction"
cr eate_prediction(history, pred_path)

pred = EclSum(os.path.join(pred_path, "PREDICTION"))
length = pred.sim_length
pred_times = pred.alloc_time_vector(False)
hist_times = history.alloc_time_vector(False)

for index in range(len(hist_times)):
self.assertEqual(hist_times[index], pred_times[index])

0 comments on commit a96e96c

Please sign in to comment.