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
6 changes: 3 additions & 3 deletions autotest/t003_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_loadoc():
return


@raises(IOError)
@raises(OSError)
def test_loadoc_lenfail():
ws = os.path.join("temp", "t003")
ml = flopy.modflow.Modflow(model_ws=ws)
Expand Down Expand Up @@ -111,12 +111,12 @@ def test_loadoc_nstpfail():
return


@raises(IOError)
@raises(OSError)
def test_load_nam_mf_nonexistant_file():
ml = flopy.modflow.Modflow.load("nonexistant.nam")


@raises(IOError)
@raises(OSError)
def test_load_nam_mt_nonexistant_file():
ml = flopy.mt3d.Mt3dms.load("nonexistant.nam")

Expand Down
8 changes: 4 additions & 4 deletions autotest/t017_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_formattedfile_read():
fname = os.path.join(cpth, "empty.githds")
with open(fname, "w"):
pass
with assert_raises(IOError):
with assert_raises(ValueError):
flopy.utils.FormattedHeadFile(fname)

return
Expand Down Expand Up @@ -86,9 +86,9 @@ def test_binaryfile_read():
fname = os.path.join(cpth, "empty.githds")
with open(fname, "w"):
pass
with assert_raises(IOError):
with assert_raises(ValueError):
flopy.utils.HeadFile(fname)
with assert_raises(IOError):
with assert_raises(ValueError):
flopy.utils.HeadFile(fname, "head", "single")

return
Expand Down Expand Up @@ -210,7 +210,7 @@ def test_cellbudgetfile_position():
fname = os.path.join(cpth, "empty.gitcbc")
with open(fname, "w"):
pass
with assert_raises(IOError):
with assert_raises(ValueError):
flopy.utils.CellBudgetFile(fname)

return
Expand Down
4 changes: 2 additions & 2 deletions flopy/mf6/mfpackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1844,7 +1844,7 @@ def _update_size_defs(self):
for key in dataset.get_active_key_list():
try:
data = dataset.get_data(key=key[0])
except (IOError, OSError, MFDataException):
except (OSError, MFDataException):
# TODO: Handle case where external file
# path has been moved
data = None
Expand All @@ -1857,7 +1857,7 @@ def _update_size_defs(self):
new_size = -1
try:
data = dataset.get_data()
except (IOError, OSError, MFDataException):
except (OSError, MFDataException):
# TODO: Handle case where external file
# path has been moved
data = None
Expand Down
10 changes: 5 additions & 5 deletions flopy/mf6/utils/output_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def get_layerfile_data(self, f=data, text=rectype):
try:
f = os.path.join(self._sim_ws, f)
return HeadFile(f, text=text)
except (IOError, FileNotFoundError):
except OSError:
return

setattr(self.__class__, rectype, get_layerfile_data)
Expand Down Expand Up @@ -270,7 +270,7 @@ def __budget(self, precision="double"):
try:
budget_file = os.path.join(self._sim_ws, self._budget[0])
return CellBudgetFile(budget_file, precision=precision)
except (IOError, FileNotFoundError):
except OSError:
return None

def __obs(self, f=None):
Expand All @@ -290,7 +290,7 @@ def __obs(self, f=None):
try:
obs_file = os.path.join(self._sim_ws, obs_file)
return Mf6Obs(obs_file)
except (IOError, FileNotFoundError):
except OSError:
return None

def __csv(self, f=None):
Expand All @@ -310,7 +310,7 @@ def __csv(self, f=None):
try:
csv_file = os.path.join(self._sim_ws, csv_file)
return CsvFile(csv_file)
except (IOError, FileNotFoundError):
except OSError:
return None

def __list(self):
Expand All @@ -325,7 +325,7 @@ def __list(self):
try:
list_file = os.path.join(self._sim_ws, self._lst)
return Mf6ListBudget(list_file)
except (AssertionError, IOError, FileNotFoundError):
except (AssertionError, OSError):
return None

def __mulitfile_handler(self, f, flist):
Expand Down
4 changes: 2 additions & 2 deletions flopy/modflow/mf.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ def load(
):
namefile_path += ".nam"
if not os.path.isfile(namefile_path):
raise IOError(f"cannot find name file: {namefile_path}")
raise OSError(f"cannot find name file: {namefile_path}")

# Determine model name from 'f', without any extension or path
modelname = os.path.splitext(os.path.basename(f))[0]
Expand Down Expand Up @@ -950,7 +950,7 @@ def load(
print(f" {os.path.basename(fname)}")
if len(files_not_loaded) > 0:
print(
" The following {len(files_not_loaded)} packages "
f" The following {len(files_not_loaded)} packages "
"were not loaded."
)
for fname in files_not_loaded:
Expand Down
2 changes: 1 addition & 1 deletion flopy/modflow/mfoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ def load(

# validate the size of nstp
if len(nstp) != nper:
raise IOError(
raise OSError(
f"nstp must be a list with {nper} entries, "
f"provided nstp list has {len(nstp)} entries."
)
Expand Down
2 changes: 1 addition & 1 deletion flopy/mt3d/mt.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ def load(
# read name file
namefile_path = os.path.join(mt.model_ws, f)
if not os.path.isfile(namefile_path):
raise IOError(f"cannot find name file: {namefile_path}")
raise FileNotFoundError(f"cannot find name file: {namefile_path}")
try:
ext_unit_dict = mfreadnam.parsenamefile(
namefile_path, mt.mfnam_packages, verbose=verbose
Expand Down
6 changes: 3 additions & 3 deletions flopy/utils/binaryfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def get_headfile_precision(filename):
f.seek(0, 0) # reset to beginning
assert f.tell() == 0
if totalbytes == 0:
raise IOError(f"datafile error: file is empty: {filename}")
raise ValueError(f"datafile error: file is empty: {filename}")

# first try single
vartype = [
Expand Down Expand Up @@ -260,7 +260,7 @@ def get_headfile_precision(filename):
result = "double"
except:
f.close()
raise IOError(
raise ValueError(
f"Could not determine the precision of the headfile {filename}"
)

Expand Down Expand Up @@ -610,7 +610,7 @@ def __init__(self, filename, precision="auto", verbose=False, **kwargs):
self.file.seek(0, 0) # reset to beginning
assert self.file.tell() == 0
if totalbytes == 0:
raise IOError(f"datafile error: file is empty: {filename}")
raise ValueError(f"datafile error: file is empty: {filename}")
self.nrow = 0
self.ncol = 0
self.nlay = 0
Expand Down
2 changes: 1 addition & 1 deletion flopy/utils/datafile.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def __init__(self, filename, precision, verbose, kwargs):
self.file.seek(0, 0) # reset to beginning
assert self.file.tell() == 0
if totalbytes == 0:
raise IOError(f"datafile error: file is empty: {filename}")
raise ValueError(f"datafile error: file is empty: {filename}")
self.nrow = 0
self.ncol = 0
self.nlay = 0
Expand Down
4 changes: 2 additions & 2 deletions flopy/utils/flopy_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,9 @@ def ulstrd(f, nlist, ra, model, sfac_columns, ext_unit_dict):
namdata = ext_unit_dict[inunit]
file_handle = namdata.filehandle
else:
raise IOError(errmsg)
raise OSError(errmsg)
else:
raise IOError(errmsg)
raise OSError(errmsg)
if namdata.filetype == "DATA(BINARY)":
binary = True
if not binary:
Expand Down
8 changes: 4 additions & 4 deletions flopy/utils/mfreadnam.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ def parsenamefile(namfilename, packages, verbose=True):

Raises
------
IOError:
FileNotFoundError
If namfilename does not exist in the directory.
ValueError:
ValueError
For lines that cannot be parsed.
"""
# initiate the ext_unit_dict dictionary
Expand All @@ -125,7 +125,7 @@ def parsenamefile(namfilename, packages, verbose=True):

if not os.path.isfile(namfilename):
# help diagnose the namfile and directory
raise IOError(
raise FileNotFoundError(
f"Could not find {namfilename} "
f"in directory {os.path.dirname(namfilename)}"
)
Expand Down Expand Up @@ -179,7 +179,7 @@ def parsenamefile(namfilename, packages, verbose=True):
kwargs["errors"] = "replace"
try:
filehandle = open(fname, openmode, **kwargs)
except IOError:
except OSError:
if verbose:
print(f"could not set filehandle to {fpath}")
filehandle = None
Expand Down
2 changes: 1 addition & 1 deletion flopy/utils/observationfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def __init__(self, filename, verbose=False, isBinary="auto"):
isBinary = True
else:
err = "Could not determine if file is binary or ascii"
raise IOError(err)
raise ValueError(err)
if isBinary:
# --open binary head file
self.file = open(filename, "rb")
Expand Down
5 changes: 2 additions & 3 deletions flopy/utils/optionblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,10 @@ def load_options(cls, options, package):
if openfile:
try:
options = open(options, "r")
except IOError:
err_msg = (
except OSError:
raise TypeError(
f"Unrecognized type for options variable: {type(options)}"
)
raise TypeError(err_msg)

option_line = ""
while True:
Expand Down
7 changes: 3 additions & 4 deletions flopy/utils/util_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -2911,10 +2911,9 @@ def load(
elif cr_dict["type"] == "external":
ext_unit = ext_unit_dict[cr_dict["nunit"]]
if ext_unit.filehandle is None:
raise IOError(
"cannot read unit {0}, filename: {1}".format(
cr_dict["nunit"], ext_unit.filename
)
raise OSError(
f"cannot read unit {cr_dict['nunit']}, "
f"filename: {ext_unit.filename}"
)
elif "binary" not in str(cr_dict["fmtin"].lower()):
assert cr_dict["nunit"] in list(ext_unit_dict.keys())
Expand Down
6 changes: 2 additions & 4 deletions release/make-release.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ def update_version():
name_pos = idx + 1

except:
msg = "There was a problem updating the version file"
raise IOError(msg)
raise OSError("There was a problem updating the version file")

try:
# write new version file
Expand All @@ -204,8 +203,7 @@ def update_version():
f.close()
print("Successfully updated version.py")
except:
msg = "There was a problem updating the version file"
raise IOError(msg)
raise OSError("There was a problem updating the version file")

# update README.md with new version information
update_readme_markdown(vmajor, vminor, vmicro)
Expand Down