Skip to content

Commit

Permalink
refactor(autotest): refactor nightly build autotest scripts (#89)
Browse files Browse the repository at this point in the history
Refactor nightly build autotest scripts to find appropriate directories
rather than having them predefined.
  • Loading branch information
jdhughes-usgs committed Feb 14, 2019
1 parent 03dbf9b commit af67357
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 17 deletions.
16 changes: 14 additions & 2 deletions autotest/test_z01_nightly_build_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@

from simulation import Simulation

exdir = os.path.join('..', '..', 'modflow6-examples', 'mf6')
# find path to modflow6-examples directory
home = os.path.expanduser('~')
fdir = 'modflow6-examples'
exdir = None
for root, dirs, files in os.walk(home):
for d in dirs:
if d == fdir:
exdir = os.path.join(root, d, 'mf6')
break
if exdir is not None:
break
testpaths = os.path.join('..', exdir)


Expand Down Expand Up @@ -175,7 +185,9 @@ def test_mf6model():


def dir_avail():
avail = os.path.isdir(exdir)
avail = False
if exdir is not None:
avail = os.path.isdir(exdir)
if not avail:
print('"{}" does not exist'.format(exdir))
print('no need to run {}'.format(os.path.basename(__file__)))
Expand Down
17 changes: 14 additions & 3 deletions autotest/test_z02_nightly_build_mf5to6.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,17 @@

from targets import target_dict as target_dict

exdir = os.path.join('..', '..', 'modflow6-examples', 'mf5to6')
# find path to modflow6-examples directory
home = os.path.expanduser('~')
fdir = 'modflow6-examples'
exdir = None
for root, dirs, files in os.walk(home):
for d in dirs:
if d == fdir:
exdir = os.path.join(root, d, 'mf5to6')
break
if exdir is not None:
break
testpaths = os.path.join('..', exdir)

sfmt = '{:25s} - {}'
Expand Down Expand Up @@ -108,7 +118,6 @@ def get_mf5to6_models():
msg += ']'
print(msg)


return dirs


Expand Down Expand Up @@ -245,7 +254,9 @@ def test_model():


def dir_avail():
avail = os.path.isdir(exdir)
avail = False
if exdir is not None:
avail = os.path.isdir(exdir)
if not avail:
print('"{}" does not exist'.format(exdir))
print('no need to run {}'.format(os.path.basename(__file__)))
Expand Down
39 changes: 27 additions & 12 deletions autotest/test_z03_nightly_build_largeexamples.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,21 @@

from simulation import Simulation

exdir = os.path.join('..', '..', 'modflow6-largetests')
testpaths = os.path.join('..', exdir)
# find path to modflow6-largetests directory
home = os.path.expanduser('~')
fdir = 'modflow6-largetests'
exdir = None
for root, dirs, files in os.walk(home):
for d in dirs:
if d == fdir:
exdir = os.path.join(root, d)
break
if exdir is not None:
break
if exdir is not None:
testpaths = os.path.join('..', exdir)
else:
testpaths = None


def get_mf6_models():
Expand All @@ -33,14 +46,15 @@ def get_mf6_models():
'test018_NAC',
'test051_uzf1d_a')


# build list of directories with valid example files
exclude = list(exclude)
dirs = [d for d in os.listdir(exdir)
if 'test' in d and d not in exclude]
# sort in numerical order for case sensitive os
dirs = sorted(dirs, key=lambda v: (v.upper(), v[0].islower()))

if exdir is not None:
dirs = [d for d in os.listdir(exdir)
if 'test' in d and d not in exclude]
# sort in numerical order for case sensitive os
dirs = sorted(dirs, key=lambda v: (v.upper(), v[0].islower()))
else:
dirs = []

# determine if only a selection of models should be run
select_dirs = None
Expand Down Expand Up @@ -93,7 +107,6 @@ def get_mf6_models():
msg += ']'
print(msg)


return dirs


Expand All @@ -117,7 +130,7 @@ def test_mf6model():
dirtest = dir_avail()
if not dirtest:
return

# get a list of test models to run
dirs = get_mf6_models()

Expand All @@ -129,14 +142,17 @@ def test_mf6model():


def dir_avail():
avail = os.path.isdir(exdir)
avail = False
if exdir is not None:
avail = os.path.isdir(exdir)
if not avail:
print('"{}" does not exist'.format(exdir))
print('no need to run {}'.format(os.path.basename(__file__)))
if os.getenv('TRAVIS'):
avail = False
return avail


def main():
# write message
tnam = os.path.splitext(os.path.basename(__file__))[0]
Expand Down Expand Up @@ -172,4 +188,3 @@ def main():

# run main routine
main()

0 comments on commit af67357

Please sign in to comment.