New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mission "clean test logs" - handles all kind of userwarnings/deprecation warnings #1888

Merged
merged 21 commits into from Sep 22, 2017
Commits
Jump to file or symbol
Failed to load files and symbols.
+9 −3
Diff settings

Always

Just for now

Viewing a subset of changes. View all

fixes ResourceWarning: unclosed file <_io.BufferedReader ...

  • Loading branch information...
barsch authored and krischer committed Sep 13, 2017
commit 24ebcb32a13617f3037de1ac2a310ab75be2b452
View
@@ -138,6 +138,8 @@ def read_sac(source, headonly=False, byteorder=None, checksize=False):
if not is_valid_byteorder(hi):
if is_byteorder_specified:
if is_file_name:
f.close()
# specified but not valid. you dun messed up.
raise SacIOError("Incorrect byteorder {}".format(byteorder))
else:
@@ -153,7 +155,7 @@ def read_sac(source, headonly=False, byteorder=None, checksize=False):
# check header lengths
if len(hf) != 70 or len(hi) != 40 or len(hs) != 24:
hf = hi = hs = None
if not is_file_name:
if is_file_name:
f.close()
raise SacIOError("Cannot read all header values")
@@ -167,6 +169,8 @@ def read_sac(source, headonly=False, byteorder=None, checksize=False):
f.seek(cur_pos, os.SEEK_SET)
th_length = (632 + 4 * int(npts))
if length != th_length:
if is_file_name:
f.close()
msg = "Actual and theoretical file size are inconsistent.\n" \
"Actual/Theoretical: {}/{}\n" \
"Check that headers are consistent with time series."
@@ -182,7 +186,8 @@ def read_sac(source, headonly=False, byteorder=None, checksize=False):
dtype=native_str(endian_str + 'f4'))
if len(data) != npts:
f.close()
if is_file_name:
f.close()
raise SacIOError("Cannot read all data points")
if is_file_name:
@@ -414,7 +419,8 @@ def write_sac_ascii(dest, hf, hi, hs, data=None):
fmt=native_str("%#15.7g"), delimiter='')
np.savetxt(f, data[5 * rows:], delimiter=b'\t')
except Exception:
f.close()
if is_file_name:
f.close()
raise SacIOError("Cannot write trace values: " + f.name)
if is_file_name:
ProTip! Use n and p to navigate between commits in a pull request.