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.
+54 −20
Diff settings

Always

Just for now

Viewing a subset of changes. View all

omits two UserWarnings + another missing Exception

  • Loading branch information...
barsch authored and krischer committed Sep 13, 2017
commit fc8eccd66a39e39272084d1ef3d620c59627d754
View
@@ -104,7 +104,7 @@ def _internal_is_scardec(buf):
try:
_internal_read_single_scardec(buf)
return True
except:
except Exception:
return False
@@ -118,7 +118,7 @@ def _read_scardec(filename_or_buf, **kwargs):
return _buffer_proxy(filename_or_buf, _internal_read_scardec, **kwargs)
def _internal_read_scardec(buf, **kwargs):
def _internal_read_scardec(buf, **kwargs): # @UnusedVariable
"""
Reads a SCARDEC file to a :class:`~obspy.core.event.Catalog` object.
@@ -331,7 +331,7 @@ def _write_scardec(catalog, filename_or_buf, **kwargs):
file_mode="wb", catalog=catalog, **kwargs)
def _internal_write_scardec(buf, catalog, **kwargs):
def _internal_write_scardec(buf, catalog, **kwargs): # @UnusedVariable
"""
Write events to a file.
@@ -350,7 +350,7 @@ def _internal_write_scardec(buf, catalog, **kwargs):
buf.write(b"\n")
def _internal_write_single_scardec(buf, event, **kwargs):
def _internal_write_single_scardec(buf, event, **kwargs): # @UnusedVariable
"""
Write an event to a file.
@@ -2,17 +2,19 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)
from future.builtins import * # NOQA @UnusedWildImport
import inspect
import io
import os
import unittest
import numpy as np
import obspy
from obspy.core.util.base import NamedTemporaryFile
from obspy.io.scardec.core import _is_scardec
import os
import unittest
import warnings
from future.builtins import * # NOQA @UnusedWildImport
import numpy as np
class ScardecTestCase(unittest.TestCase):
@@ -46,7 +48,18 @@ def test_read_and_write_scardec_from_files(self):
temp_filename = tf.name
try:
cat.write(temp_filename, format="SCARDEC")
# raises two UserWarnings
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always', UserWarning)
cat.write(temp_filename, format="SCARDEC")
self.assertEqual(len(w), 2)
self.assertEqual(w[0].category, UserWarning)
self.assertIn('No moment wave magnitude found', str(w[0]))
self.assertEqual(w[1].category, UserWarning)
self.assertIn('No derived origin attached', str(w[1]))
with open(temp_filename, "rb") as fh:
new_data = fh.read()
finally:
@@ -82,9 +95,19 @@ def test_read_and_write_scardec_from_open_files(self):
cat = obspy.read_events(fh)
with NamedTemporaryFile() as tf:
cat.write(tf, format="SCARDEC")
tf.seek(0, 0)
new_data = tf.read()
# raises two UserWarnings
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always', UserWarning)
cat.write(tf, format="SCARDEC")
tf.seek(0, 0)
new_data = tf.read()
self.assertEqual(len(w), 2)
self.assertEqual(w[0].category, UserWarning)
self.assertIn('No moment wave magnitude found', str(w[0]))
self.assertEqual(w[1].category, UserWarning)
self.assertIn('No derived origin attached', str(w[1]))
# Test file header
self.assertEqual(data.decode().splitlines()[0:2],
@@ -107,19 +130,30 @@ def test_read_and_write_scardec_from_bytes_io(self):
This time it tests reading from and writing to BytesIO objects.
"""
filename = os.path.join(self.datapath, "test.scardec")
with open(filename, "rb") as fh:
buf = io.BytesIO(fh.read())
data = buf.read()
buf.seek(0, 0)
with buf:
buf.seek(0, 0)
cat = obspy.read_events(buf)
with buf:
buf.seek(0, 0)
cat = obspy.read_events(buf)
# raises two UserWarnings
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always', UserWarning)
with io.BytesIO() as buf2:
cat.write(buf2, format="SCARDEC")
buf2.seek(0, 0)
new_data = buf2.read()
with io.BytesIO() as buf2:
cat.write(buf2, format="SCARDEC")
buf2.seek(0, 0)
new_data = buf2.read()
self.assertEqual(len(w), 2)
self.assertEqual(w[0].category, UserWarning)
self.assertIn('No moment wave magnitude found', str(w[0]))
self.assertEqual(w[1].category, UserWarning)
self.assertIn('No derived origin attached', str(w[1]))
# Test file header
self.assertEqual(data.decode().splitlines()[0:2],
ProTip! Use n and p to navigate between commits in a pull request.