Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 101 additions & 69 deletions autotest/t001_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,82 +21,114 @@
testdir_previous = os.path.join(testdir, pd_previous.dirname)
target_previous = os.path.join(testdir, key_previous)

if sys.platform.lower() == 'win32':
target_release += '.exe'
target_previous += '.exe'

exdir = 'test-run'
testpaths = [os.path.join(testdir, pd_release.dirname, exdir)]
exclude = ('MNW2-Fig28', 'swi2ex4sww', 'testsfr2_tab', 'UZFtest2')

def mf2005_namefiles():
if os.path.isdir(testpaths[0]):
namefiles = get_namefiles(testpaths[0], exclude=exclude)
else:
namefiles = [None]
return namefiles


def run_mf2005(namefile, regression=True):
"""
Run the simulation.

"""

# Set root as the directory name where namefile is located
testname = pymake.get_sim_name(namefile, rootpth=testpaths[0])[0]

# Set nam as namefile name without path
nam = os.path.basename(namefile)

# Setup
testpth = os.path.join(testdir, testname)
pymake.setup(namefile, testpth)

# run test models
print('running model...{}'.format(testname))
exe_name = os.path.abspath(target_release)
success, buff = flopy.run_model(exe_name, nam, model_ws=testpth,
silent=True)

assert success, 'base model {} '.format(nam) + 'did not run.'

# If it is a regression run, then setup and run the model with the
# release target and the reference target
success_reg = True
if regression:
testname_reg = os.path.basename(target_previous)
testpth_reg = os.path.join(testpth, testname_reg)
pymake.setup(namefile, testpth_reg)
print('running regression model...{}'.format(testname_reg))
exe_name = os.path.abspath(target_previous)
success_reg, buff = flopy.run_model(exe_name, nam,
model_ws=testpth_reg,
silent=False)

assert success_reg, 'regression model {} '.format(nam) + 'did not run.'
if namefile is not None:
# Set root as the directory name where namefile is located
testname = pymake.get_sim_name(namefile, rootpth=testpaths[0])[0]

# Set nam as namefile name without path
nam = os.path.basename(namefile)

# Setup
testpth = os.path.join(testdir, testname)
pymake.setup(namefile, testpth)

# run test models
exe_name = os.path.abspath(target_release)
msg = 'running model...{}'.format(testname) + \
' using {}'.format(exe_name)
print(msg)
if os.path.exists(exe_name):
success, buff = flopy.run_model(exe_name, nam, model_ws=testpth,
silent=True)
else:
success = False

assert success, 'base model {} '.format(nam) + 'did not run.'

# If it is a regression run, then setup and run the model with the
# release target and the reference target
success_reg = True
if regression:
testname_reg = os.path.basename(target_previous)
testpth_reg = os.path.join(testpth, testname_reg)
pymake.setup(namefile, testpth_reg)
# exe_name = os.path.abspath(target_previous)
msg = 'running regression model...{}'.format(testname_reg) + \
' using {}'.format(exe_name)
print(msg)

if os.path.exists(exe_name):
success_reg, buff = flopy.run_model(exe_name, nam,
model_ws=testpth_reg,
silent=False)
else:
success_reg = False

assert success_reg, 'regression model {} '.format(nam) + \
'did not run.'

# compare results
outfile1 = os.path.join(os.path.split(os.path.join(testpth, nam))[0],
'bud.cmp')
outfile2 = os.path.join(os.path.split(os.path.join(testpth, nam))[0],
'hds.cmp')
success_reg = pymake.compare(os.path.join(testpth, nam),
os.path.join(testpth_reg, nam),
precision='single',
max_cumpd=0.01, max_incpd=0.01,
htol=0.001,
outfile1=outfile1, outfile2=outfile2)

# Clean things up
if not retain:
pymake.teardown(testpth)

return


def test_compile_prev():
# Compile reference version of the program from the source.

# Remove the existing distribution directory if it exists
if os.path.isdir(testdir_previous):
print('Removing folder ' + testdir_previous)
shutil.rmtree(testdir_previous)

pymake.build_program(target=key_previous, fflags='-O3', cflags='-O3',
download_dir=testdir,
exe_name=target_previous)
if success and success_reg:
fpth = os.path.split(os.path.join(testpth, nam))[0]
outfile1 = os.path.join(fpth, 'bud.cmp')
fpth = os.path.split(os.path.join(testpth, nam))[0]
outfile2 = os.path.join(fpth, 'hds.cmp')
success_reg = pymake.compare(os.path.join(testpth, nam),
os.path.join(testpth_reg, nam),
precision='single',
max_cumpd=0.01, max_incpd=0.01,
htol=0.001,
outfile1=outfile1, outfile2=outfile2)
# Clean things up
if success_reg:
if not retain:
pymake.teardown(testpth)
else:
success = False
errmsg = 'could not run...{}'.format(os.path.basename(nam))
else:
success = False
errmsg = '{} does not exist'.format(target_release)

assert success, errmsg

return
#
#
# def test_compile_prev():
# # Compile reference version of the program from the source.
#
# # Remove the existing distribution directory if it exists
# if os.path.isdir(testdir_previous):
# print('Removing folder ' + testdir_previous)
# shutil.rmtree(testdir_previous)
#
# pymake.build_program(target=key_previous, fflags='-O3', cflags='-O3',
# download_dir=testdir,
# exe_name=target_previous)
#
# return


def test_compile_ref():
Expand All @@ -108,6 +140,7 @@ def test_compile_ref():
shutil.rmtree(testdir_release)

pymake.build_program(target=key_release,
fc='gfortran', cc='gcc',
fflags='-O3 -fbacktrace', cflags='-O3',
download_dir=testdir,
exe_name=target_release)
Expand All @@ -116,13 +149,12 @@ def test_compile_ref():


def test_mf2005():
namefiles = get_namefiles(testpaths[0], exclude=exclude)
for namefile in namefiles:
for namefile in mf2005_namefiles():
yield run_mf2005, namefile
return


def test_teardown():
def test_cleanup():
ext = ''
if sys.platform == 'win32':
ext = '.exe'
Expand Down Expand Up @@ -153,10 +185,10 @@ def test_teardown():

if __name__ == '__main__':
test_compile_ref()
test_compile_prev()
# test_compile_prev()

namefiles = get_namefiles(testpaths[0], exclude=exclude)
for namefile in namefiles:
for namefile in mf2005_namefiles():
run_mf2005(namefile)

test_teardown()
test_mf2005()
test_cleanup()
90 changes: 56 additions & 34 deletions autotest/t002_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

# define program data
target = 'swtv4'
if sys.platform.lower() == 'win32':
target += '.exe'

# get program dictionary
prog_dict = pymake.usgs_program_data.get_target(target)

# set up paths
Expand All @@ -22,10 +26,6 @@
srcpth = os.path.join(swtpth, prog_dict.srcdir)
epth = os.path.abspath(os.path.join(dstpth, target))

# add exe for windows
if sys.platform == 'win32':
epth += '.exe'


def edit_namefile(namefile):
# read existing namefile
Expand All @@ -42,9 +42,13 @@ def edit_namefile(namefile):


def get_namefiles():
exclude_tests = ('7_swtv4_ex', '6_rotation')
namefiles = pymake.get_namefiles(expth, exclude=exclude_tests)
simname = pymake.get_sim_name(namefiles, rootpth=expth)
if os.path.exists(epth):
exclude_tests = ('7_swtv4_ex', '6_rotation')
namefiles = pymake.get_namefiles(expth, exclude=exclude_tests)
simname = pymake.get_sim_name(namefiles, rootpth=expth)
else:
namefiles = [None]
simname = [None]
return zip(namefiles, simname)


Expand All @@ -68,48 +72,66 @@ def compile_code():
def clean_up():
# clean up downloaded directory
print('Removing folder ' + swtpth)
shutil.rmtree(swtpth)
if os.path.isdir(swtpth):
shutil.rmtree(swtpth)

# clean up target
print('Removing ' + target)
os.remove(epth)
if os.path.isfile(epth):
os.remove(epth)

return


def run_seawat(namepth, dst):
print('running...{}'.format(dst))
if namepth is not None:
print('running...{}'.format(dst))
# setup
testpth = os.path.join(dstpth, dst)
pymake.setup(namepth, testpth)

# edit name file
pth = os.path.join(testpth, os.path.basename(namepth))
edit_namefile(pth)

# run test models
if os.path.exists(epth):
print('running model...{}'.format(os.path.basename(namepth)))
success, buff = flopy.run_model(epth, os.path.basename(namepth),
model_ws=testpth, silent=True)
if success:
pymake.teardown(testpth)
else:
errmsg = 'could not run...{}'.format(os.path.basename(namepth))
else:
success = False
errmsg = '{} does not exist'.format(epth)

assert success, errmsg

# setup
testpth = os.path.join(dstpth, dst)
pymake.setup(namepth, testpth)
return

# edit name file
pth = os.path.join(testpth, os.path.basename(namepth))
edit_namefile(pth)

# run test models
print('running model...{}'.format(os.path.basename(namepth)))
success, buff = flopy.run_model(epth, os.path.basename(namepth),
model_ws=testpth, silent=True)
if success:
pymake.teardown(testpth)
assert success is True
def build_seawat_dependency_graphs():
if os.path.exists(epth):

return
# build dependencies output directory
if not os.path.exists(deppth):
os.makedirs(deppth)

# build dependency graphs
print('building dependency graphs')
pymake.visualize.make_plots(srcpth, deppth)

def build_seawat_dependency_graphs():
# build dependencies output directory
if not os.path.exists(deppth):
os.makedirs(deppth)
# test that the dependency figure for the SEAWAT main exists
findf = os.path.join(deppth, 'swt_v4.f.png')
success = os.path.isfile(findf)
assert success, 'could not find {}'.format(findf)
else:
success = False

# build dependency graphs
print('building dependency graphs')
pymake.visualize.make_plots(srcpth, deppth)
assert success, 'could not build dependency graphs'

# test that the dependency figure for the SEAWAT main exists
findf = os.path.join(deppth, 'swt_v4.f.png')
assert os.path.isfile(findf) is True
return


Expand Down
Loading