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.
+26 −21
Diff settings

Always

Just for now

Viewing a subset of changes. View all

ignore UserWarning

  • Loading branch information...
barsch authored and krischer committed Sep 13, 2017
commit c2906c0eca9abe317dbcee1c97b27abb571528d1
@@ -8,10 +8,12 @@
import sys
import tempfile
import unittest
import warnings
import obspy.core.util.misc as misc
from obspy import UTCDateTime, read
from obspy.core.compatibility import mock
from obspy.core.util.misc import CatchOutput, get_window_times, \
_ENTRY_POINT_CACHE
class UtilMiscTestCase(unittest.TestCase):
@@ -24,7 +26,7 @@ def test_supress_output(self):
Tests that CatchOutput suppresses messages
"""
# this should write nothing to console
with misc.CatchOutput():
with CatchOutput():
sys.stdout.write("test_suppress_output #1 failed")
sys.stderr.write("test_suppress_output #2 failed")
print("test_suppress_output #3 failed")
@@ -35,25 +37,25 @@ def test_catch_output(self):
"""
Tests that CatchOutput catches messages
"""
with misc.CatchOutput() as out:
with CatchOutput() as out:
sys.stdout.write("test_catch_output #1")
sys.stderr.write("test_catch_output #2")
self.assertEqual(out.stdout, 'test_catch_output #1')
self.assertEqual(out.stderr, 'test_catch_output #2')
with misc.CatchOutput() as out:
with CatchOutput() as out:
print("test_catch_output #3")
self.assertEqual(out.stdout, 'test_catch_output #3\n')
self.assertEqual(out.stderr, '')
with misc.CatchOutput() as out:
with CatchOutput() as out:
print("test_catch_output #4", file=sys.stdout)
print("test_catch_output #5", file=sys.stderr)
self.assertEqual(out.stdout, 'test_catch_output #4\n')
self.assertEqual(out.stderr, 'test_catch_output #5\n')
def test_catch_output_bytes(self):
with misc.CatchOutput() as out:
with CatchOutput() as out:
if PY2:
sys.stdout.write(b"test_catch_output_bytes #1")
sys.stderr.write(b"test_catch_output_bytes #2")
@@ -68,7 +70,7 @@ def test_catch_output_io(self):
"""
Tests that CatchOutput context manager does not break I/O.
"""
with misc.CatchOutput():
with CatchOutput():
fn = tempfile.TemporaryFile(prefix='obspy')
try:
@@ -108,7 +110,7 @@ def test_get_window_times(self):
"""
# Basic windows. 4 pieces.
self.assertEqual(
misc.get_window_times(
get_window_times(
starttime=UTCDateTime(0),
endtime=UTCDateTime(20),
window_length=5.0,
@@ -125,7 +127,7 @@ def test_get_window_times(self):
# Different step size.
self.assertEqual(
misc.get_window_times(
get_window_times(
starttime=UTCDateTime(0),
endtime=UTCDateTime(20),
window_length=5.0,
@@ -140,7 +142,7 @@ def test_get_window_times(self):
# With offset.
self.assertEqual(
misc.get_window_times(
get_window_times(
starttime=UTCDateTime(0),
endtime=UTCDateTime(20),
window_length=5.0,
@@ -155,7 +157,7 @@ def test_get_window_times(self):
# Don't return partial windows.
self.assertEqual(
misc.get_window_times(
get_window_times(
starttime=UTCDateTime(0),
endtime=UTCDateTime(20),
window_length=15.0,
@@ -169,7 +171,7 @@ def test_get_window_times(self):
# Return partial windows.
self.assertEqual(
misc.get_window_times(
get_window_times(
starttime=UTCDateTime(0),
endtime=UTCDateTime(20),
window_length=15.0,
@@ -184,7 +186,7 @@ def test_get_window_times(self):
# Negative step length has to be used together with an offset.
self.assertEqual(
misc.get_window_times(
get_window_times(
starttime=UTCDateTime(0),
endtime=UTCDateTime(20),
window_length=5.0,
@@ -201,7 +203,7 @@ def test_get_window_times(self):
# Negative step length and not partial windows.
self.assertEqual(
misc.get_window_times(
get_window_times(
starttime=UTCDateTime(0),
endtime=UTCDateTime(20),
window_length=15.0,
@@ -215,7 +217,7 @@ def test_get_window_times(self):
# Negative step length with partial windows.
self.assertEqual(
misc.get_window_times(
get_window_times(
starttime=UTCDateTime(0),
endtime=UTCDateTime(20),
window_length=15.0,
@@ -230,7 +232,7 @@ def test_get_window_times(self):
# Smaller step than window.
self.assertEqual(
misc.get_window_times(
get_window_times(
starttime=UTCDateTime(0),
endtime=UTCDateTime(2),
window_length=1.0,
@@ -250,12 +252,15 @@ def test_entry_point_buffer(self):
"""
Ensure the entry point buffer caches results from load_entry_point
"""
with mock.patch.dict(misc._ENTRY_POINT_CACHE, clear=True):
with mock.patch.dict(_ENTRY_POINT_CACHE, clear=True):
with mock.patch('obspy.core.util.misc.load_entry_point') as p:
st = read()
st.write('temp.mseed', 'mseed')
st.write('temp.mseed', 'mseed')
self.assertEqual(p.call_count, len(misc._ENTRY_POINT_CACHE))
# raises UserWarning: No matching response information found.
with warnings.catch_warnings(record=True):
warnings.simplefilter('ignore', UserWarning)
st = read()
st.write('temp.mseed', 'mseed')
self.assertEqual(len(_ENTRY_POINT_CACHE), 3)
self.assertEqual(p.call_count, 3)
def suite():
ProTip! Use n and p to navigate between commits in a pull request.