-
Notifications
You must be signed in to change notification settings - Fork 529
/
test_basic_client.py
110 lines (98 loc) · 4.25 KB
/
test_basic_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# -*- coding: utf-8 -*-
"""
The obspy.clients.seedlink.basic_client test suite.
"""
import unittest
import pytest
from obspy import UTCDateTime
from obspy.clients.seedlink.basic_client import Client
pytestmark = pytest.mark.network
class ClientTestCase(unittest.TestCase):
def setUp(self):
self.client = Client("rtserver.ipgp.fr")
def test_get_waveform(self):
def _test_offset_from_realtime(offset):
t = UTCDateTime() - offset
request = ["G", "FDFM", "00", "LHN", t, t + 20]
st = self.client.get_waveforms(*request)
self.assertGreater(len(st), 0)
for tr in st:
self.assertEqual(tr.id, ".".join(request[:4]))
self.assertTrue(any([len(tr) > 0 for tr in st]))
st.merge(1)
self.assertTrue(abs(tr.stats.starttime - request[4]) < 1)
self.assertTrue(abs(tr.stats.endtime - request[5]) < 1)
# getting a result depends on two things.. how long backwards the ring
# buffer stores data and how close to realtime the data is available,
# so check some different offsets and see if we get some data
for offset in (3600, 2000, 1000, 500):
try:
_test_offset_from_realtime(offset)
except AssertionError:
continue
else:
break
else:
raise
def test_get_info(self):
"""
Test fetching station information
"""
client = self.client
info = client.get_info(station='F*')
self.assertIn(('G', 'FDFM'), info)
# should have at least 7 stations
self.assertTrue(len(info) > 2)
# only fetch one station
info = client.get_info(network='G', station='FDFM')
self.assertEqual([('G', 'FDFM')], info)
# check that we have a cache on station level
self.assertIn(('G', 'FDFM'), client._station_cache)
self.assertTrue(len(client._station_cache) > 20)
self.assertEqual(client._station_cache_level, "station")
def test_multiple_waveform_requests_with_multiple_info_requests(self):
"""
This test a combination of waveform requests that internally do
multiple info requests on increasing detail levels
"""
def _test_offset_from_realtime(offset):
# need to reinit to clean out any caches
self.setUp()
t = UTCDateTime() - offset
# first do a request that needs an info request on station level
# only
st = self.client.get_waveforms("*", "F?FM", "??", "B??", t, t + 5)
self.assertGreater(len(st), 2)
self.assertTrue(len(self.client._station_cache) > 20)
station_cache_size = len(self.client._station_cache)
self.assertIn(("G", "FDFM"), self.client._station_cache)
self.assertEqual(self.client._station_cache_level, "station")
for tr in st:
self.assertEqual(tr.stats.network, "G")
self.assertEqual(tr.stats.station, "FDFM")
self.assertEqual(tr.stats.channel[0], "B")
# now make a subsequent request that needs an info request on
# channel level
st = self.client.get_waveforms("*", "F?FM", "*", "B*", t, t + 5)
self.assertGreater(len(st), 2)
self.assertTrue(
len(self.client._station_cache) > station_cache_size)
self.assertIn(("G", "FDFM", "00", "BHZ"),
self.client._station_cache)
self.assertEqual(self.client._station_cache_level, "channel")
for tr in st:
self.assertEqual(tr.stats.network, "G")
self.assertEqual(tr.stats.station, "FDFM")
self.assertEqual(tr.stats.channel[0], "B")
# getting a result depends on two things.. how long backwards the ring
# buffer stores data and how close to realtime the data is available,
# so check some different offsets and see if we get some data
for offset in (3600, 2000, 1000, 500):
try:
_test_offset_from_realtime(offset)
except AssertionError:
continue
else:
break
else:
raise