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.
+190 −170
Diff settings

Always

Just for now

@@ -107,27 +107,28 @@ class Client(object):
# initializing a client with the same base URL is cheap.
__service_discovery_cache = {}
RE_UINT8 = '(?:25[0-5]|2[0-4]\d|[0-1]?\d{1,2})'
RE_HEX4 = '(?:[\d,a-f]{4}|[1-9,a-f][0-9,a-f]{0,2}|0)'
RE_UINT8 = r'(?:25[0-5]|2[0-4]\d|[0-1]?\d{1,2})'
RE_HEX4 = r'(?:[\d,a-f]{4}|[1-9,a-f][0-9,a-f]{0,2}|0)'
RE_IPv4 = '(?:' + RE_UINT8 + '(?:\.' + RE_UINT8 + '){3})'
RE_IPv4 = r'(?:' + RE_UINT8 + r'(?:\.' + RE_UINT8 + r'){3})'
RE_IPv6 = \
'(?:\[' + RE_HEX4 + '(?::' + RE_HEX4 + '){7}\]' + \
'|\[(?:' + RE_HEX4 + ':){0,5}' + RE_HEX4 + '::\]' + \
'|\[::' + RE_HEX4 + '(?::' + RE_HEX4 + '){0,5}\]' + \
'|\[::' + RE_HEX4 + '(?::' + RE_HEX4 + '){0,3}:' + RE_IPv4 + '\]' + \
'|\[' + RE_HEX4 + ':' + \
'(?:' + RE_HEX4 + ':|:' + RE_HEX4 + '){0,4}' + \
':' + RE_HEX4 + '\])'
URL_REGEX = 'https?://' + \
'(' + RE_IPv4 + \
'|' + RE_IPv6 + \
'|localhost' + \
'|\w+' + \
'|(?:\w(?:[\w-]{0,61}[\w])?\.){1,}([a-z]{2,6}))' + \
'(?::\d{2,5})?' + \
'(/[\w\.-]+)*/?$'
r'(?:\[' + RE_HEX4 + r'(?::' + RE_HEX4 + r'){7}\]' + \
r'|\[(?:' + RE_HEX4 + r':){0,5}' + RE_HEX4 + r'::\]' + \
r'|\[::' + RE_HEX4 + r'(?::' + RE_HEX4 + r'){0,5}\]' + \
r'|\[::' + RE_HEX4 + r'(?::' + RE_HEX4 + r'){0,3}:' + RE_IPv4 + \
r'\]' + \
r'|\[' + RE_HEX4 + r':' + \
r'(?:' + RE_HEX4 + r':|:' + RE_HEX4 + r'){0,4}' + \
r':' + RE_HEX4 + r'\])'
URL_REGEX = r'https?://' + \
r'(' + RE_IPv4 + \
r'|' + RE_IPv6 + \
r'|localhost' + \
r'|\w+' + \
r'|(?:\w(?:[\w-]{0,61}[\w])?\.){1,}([a-z]{2,6}))' + \
r'(?::\d{2,5})?' + \
r'(/[\w\.-]+)*/?$'
@classmethod
def _validate_base_url(cls, base_url):
@@ -278,7 +278,7 @@ def it():
while starttime < endtime:
yield (starttime, min(starttime + chunklength, endtime))
starttime += chunklength
raise StopIteration
return
return it()
View
@@ -1710,7 +1710,7 @@ def slide(self, window_length, step, offset=0,
include_partial_windows=include_partial_windows)
if len(windows) < 1:
raise StopIteration
return
for start, stop in windows:
temp = self.slice(start, stop,
@@ -1721,8 +1721,6 @@ def slide(self, window_length, step, offset=0,
continue
yield temp
raise StopIteration
def select(self, network=None, station=None, location=None, channel=None,
sampling_rate=None, npts=None, component=None, id=None):
"""
@@ -780,7 +780,10 @@ def test_merge_with_different_calibration_factors(self):
tr2 = Trace(data=np.zeros(5))
tr2.stats.calib = 2.0
st = Stream([tr1, tr2])
self.assertRaises(Exception, st.merge)
# this also emits an UserWarning
with warnings.catch_warnings():
warnings.simplefilter('ignore', UserWarning)
self.assertRaises(Exception, st.merge)
# 2 - different calibration factors for the different channels is ok
tr1 = Trace(data=np.zeros(5))
tr1.stats.calib = 2.00
@@ -807,7 +810,10 @@ def test_merge_with_different_sampling_rates(self):
tr2 = Trace(data=np.zeros(5))
tr2.stats.sampling_rate = 50
st = Stream([tr1, tr2])
self.assertRaises(Exception, st.merge)
# this also emits an UserWarning
with warnings.catch_warnings():
warnings.simplefilter('ignore', UserWarning)
self.assertRaises(Exception, st.merge)
# 2 - different sampling rates for the different channels is ok
tr1 = Trace(data=np.zeros(5))
tr1.stats.sampling_rate = 200
@@ -832,7 +838,10 @@ def test_merge_with_different_data_types(self):
tr1 = Trace(data=np.zeros(5, dtype=np.int32))
tr2 = Trace(data=np.zeros(5, dtype=np.float32))
st = Stream([tr1, tr2])
self.assertRaises(Exception, st.merge)
# this also emits an UserWarning
with warnings.catch_warnings():
warnings.simplefilter('ignore', UserWarning)
self.assertRaises(Exception, st.merge)
# 2 - different sampling rates for the different channels is ok
tr1 = Trace(data=np.zeros(5, dtype=np.int32))
tr1.stats.channel = 'EHE'
@@ -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():
View
@@ -164,7 +164,8 @@ def __setitem__(self, key, value):
elif key == 'starttime':
value = UTCDateTime(value)
elif key == 'npts':
value = int(value)
if not isinstance(value, int):
value = int(value)
# set current key
super(Stats, self).__setitem__(key, value)
# set derived value: delta
@@ -1244,14 +1245,12 @@ def slide(self, window_length, step, offset=0,
include_partial_windows=include_partial_windows)
if len(windows) < 1:
raise StopIteration
return
for start, stop in windows:
yield self.slice(start, stop,
nearest_sample=nearest_sample)
raise StopIteration
def verify(self):
"""
Verify current trace object against available meta data.
View
@@ -373,7 +373,7 @@ def linspace2(val1, val2, n):
delta = round(2. * dval / n, round_pos) / 2
new_val1 = np.ceil(val1 / delta) * delta
new_val2 = np.floor(val2 / delta) * delta
n = (new_val2 - new_val1) / delta + 1
n = int((new_val2 - new_val1) / delta + 1)
return np.linspace(new_val1, new_val2, n)
n_1 = int(np.ceil(height / max(width, height) * 8))
@@ -10,6 +10,7 @@
import unittest
import matplotlib.pyplot as plt
import numpy as np
from obspy.core.util.testing import ImageComparison
from obspy.imaging.mopad_wrapper import beach
@@ -23,6 +24,12 @@ class MopadTestCase(unittest.TestCase):
def setUp(self):
# directory where the test files are located
self.path = os.path.join(os.path.dirname(__file__), 'images')
# ignore some "RuntimeWarning: invalid value encountered in sign"
self.nperr = np.geterr()
np.seterr(all='ignore')
def tearDown(self):
np.seterr(**self.nperr)
def test_collection(self):
"""
@@ -108,19 +108,26 @@ def test_scan_save_load_npz(self):
for filename in self.all_files:
shutil.copy(filename, os.curdir)
# save via command line
obspy_scan([os.curdir, '--write', 'scan.npz'])
# save via Python
scanner.parse(os.curdir)
scanner.save_npz('scanner.npz')
scanner = Scanner()
# version string of '0.0.0+archive' raises UserWarning - ignore
with warnings.catch_warnings(record=True):
warnings.simplefilter('ignore', UserWarning)
# load via Python
scanner.load_npz('scanner.npz')
with ImageComparison(self.path, 'scan.png') as ic:
scanner.plot(ic.name)
with ImageComparison(self.path, 'scan.png') as ic:
obspy_scan(['--load', 'scan.npz', '--output', ic.name])
with ImageComparison(self.path, 'scan.png') as ic:
scanner.plot(ic.name)
# load via command line
with ImageComparison(self.path, 'scan.png') as ic:
obspy_scan(['--load', 'scan.npz', '--output', ic.name])
def test_scan_times(self):
"""
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.