-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest_ph5validate.py
executable file
·618 lines (563 loc) · 26.3 KB
/
test_ph5validate.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
'''
Tests for ph5validate
'''
import unittest
import os
import sys
import logging
import shutil
from StringIO import StringIO
from mock import patch
from testfixtures import OutputCapture, LogCapture
from ph5.utilities import ph5validate, segd2ph5, nuke_table, kef2ph5
from ph5.core import ph5api
from ph5.core.tests.test_base import LogTestCase, TempDirTestCase, kef_to_ph5
class TestPH5Validate_response_info(LogTestCase, TempDirTestCase):
def setUp(self):
super(TestPH5Validate_response_info, self).setUp()
# copy ph5 data and tweak sensor model and sample rate in array 9
# to test for inconsistencies between filenames and info
orgph5path = os.path.join(self.home, "ph5/test_data/ph5")
shutil.copy(os.path.join(orgph5path, 'master.ph5'),
os.path.join(self.tmpdir, 'master.ph5'))
shutil.copy(os.path.join(orgph5path, 'miniPH5_00001.ph5'),
os.path.join(self.tmpdir, 'miniPH5_00001.ph5'))
testargs = ['delete_table', '-n', 'master.ph5', '-A', '9']
with patch.object(sys, 'argv', testargs):
with OutputCapture():
f = StringIO('y')
sys.stdin = f
nuke_table.main()
f.close()
kefpath = os.path.join(
self.home,
'ph5/test_data/metadata/array_9_test_resp_filename.kef')
testargs = ['keftoph5', '-n', 'master.ph5', '-k', kefpath]
with patch.object(sys, 'argv', testargs):
kef2ph5.main()
self.ph5API_object = ph5api.PH5(path=self.tmpdir,
nickname='master.ph5')
self.ph5validate = ph5validate.PH5Validate(self.ph5API_object, '.')
def tearDown(self):
self.ph5API_object.close()
super(TestPH5Validate_response_info, self).tearDown()
def test_check_array_t(self):
# change response_file_sensor_a to
# test for No response data loaded for gs11
response_t = self.ph5validate.ph5.get_response_t_by_n_i(4)
response_t['response_file_sensor_a'] = '/Experiment_g/Responses_g/gs11'
with LogCapture():
ret = self.ph5validate.check_array_t()
for r in ret:
if 'Station 9001' in r.heading:
self.assertEqual(r.heading,
"-=-=-=-=-=-=-=-=-\n"
"Array_t_009 Station 9001 Channel 1\n"
"4 error, 1 warning, 0 info\n"
"-=-=-=-=-=-=-=-=-\n"
)
# this error causes by changing samplerate
errors = [
"No data found for das serial number 12183 during "
"this station's time. You may need to reload the "
"raw data for this station.",
'Response_t[4]:No response data loaded for gs11.',
"Response_t[4]:response_file_das_a 'rt125a_500_1_32' is "
"inconsistent with Array_t_009:sr=100. Please check with "
"resp_load format [das_model]_[sr]_[srm]_[gain].",
"Response_t[4]:response_file_sensor_a 'gs11' is "
"inconsistent with Array_t_009:sensor_model=cmg3t."]
self.assertEqual(
set(r.error),
set(errors))
self.assertEqual(
r.warning,
['No station description found.'])
if 'Station 0407 Channel -2' in r.heading:
self.assertEqual(r.heading,
"-=-=-=-=-=-=-=-=-\n"
"Array_t_004 Station 0407 Channel -2\n"
"1 error, 2 warning, 0 info\n"
"-=-=-=-=-=-=-=-=-\n"
)
self.assertEqual(
r.error,
['Response_t[-1]:'
'Metadata response with n_i=-1 has no response data.'])
# sample rate for station 0407 in array 4 is 0
self.assertEqual(
r.warning,
['No station description found.',
'Sample rate seems to be 0. Is this correct???'])
class TestPh5Validate_main_detect_data(TempDirTestCase, LogTestCase):
def setUp(self):
super(TestPh5Validate_main_detect_data, self).setUp()
kef_to_ph5(
self.tmpdir, 'master.ph5',
os.path.join(self.home, 'ph5/test_data'),
['rt125a/das_t_12183.kef', 'metadata/array_t_9_validate.kef'],
das_sn_list=['12183'])
def test_main(self):
# test invalid level
testargs = ['ph5_validate', '-n', 'master.ph5', '-p', self.tmpdir,
'-l', 'WARN']
with patch.object(sys, 'argv', testargs):
with OutputCapture() as out:
self.assertRaises(SystemExit, ph5validate.main)
output = out.captured.strip().split('\n')
self.assertEqual(
output[1],
"ph5_validate: error: argument -l/--level: invalid choice: "
"'WARN' (choose from 'ERROR', 'WARNING', 'INFO')")
# test WARNING level
testargs = ['ph5_validate', '-n', 'master.ph5', '-p', self.tmpdir,
'-l', 'WARNING']
with patch.object(sys, 'argv', testargs):
with OutputCapture():
ph5validate.main()
with open('ph5_validate.log') as f:
all_logs = f.read().split("-=-=-=-=-=-=-=-=-\n")
self.assertEqual(
all_logs[2],
'ERROR: Experiment_t does not exist. '
'run experiment_t_gen to create table\n')
self.assertEqual(
all_logs[3],
'Array_t_009 Station 9001 Channel 1\n'
'2 error, 3 warning, 0 info\n')
self.assertEqual(
all_logs[4],
'ERROR: No Response table found. Have you run resp_load yet?\n'
'ERROR: Response_t has no entry for n_i=7\n'
'WARNING: No station description found.\n'
'WARNING: Data exists before deploy time: 7 seconds.\n'
'WARNING: Station 9001 [1550849950, 1550850034] is repeated '
'2 time(s)\n')
self.assertEqual(
all_logs[5],
'Array_t_009 Station 9002 Channel 1\n2 error, 2 warning, 0 info\n')
self.assertEqual(
all_logs[6],
'ERROR: No Response table found. Have you run resp_load yet?\n'
'ERROR: Response_t has no entry for n_i=7\n'
'WARNING: No station description found.\n'
'WARNING: Data exists after pickup time: 36 seconds.\n')
self.assertEqual(
all_logs[7],
'Array_t_009 Station 9003 Channel 1\n2 error, 2 warning, 0 info\n')
self.assertEqual(
all_logs[8],
'ERROR: No Response table found. Have you run resp_load yet?\n'
'ERROR: Response_t has no entry for n_i=7\n'
'WARNING: No station description found.\n'
'WARNING: Data exists after pickup time: 2 seconds.\n')
# test ERROR level
testargs = ['ph5_validate', '-n', 'master.ph5', '-p', self.tmpdir,
'-l', 'ERROR']
with patch.object(sys, 'argv', testargs):
with OutputCapture():
ph5validate.main()
with open('ph5_validate.log') as f:
all_logs = f.read().split("-=-=-=-=-=-=-=-=-\n")
self.assertEqual(
all_logs[2],
'ERROR: Experiment_t does not exist. '
'run experiment_t_gen to create table\n')
self.assertEqual(
all_logs[3],
'Array_t_009 Station 9001 Channel 1\n2 error, 3 warning, 0 info\n')
self.assertEqual(
all_logs[4],
'ERROR: No Response table found. Have you run resp_load yet?\n'
'ERROR: Response_t has no entry for n_i=7\n')
self.assertEqual(
all_logs[5],
'Array_t_009 Station 9002 Channel 1\n2 error, 2 warning, 0 info\n')
self.assertEqual(
all_logs[6],
'ERROR: No Response table found. Have you run resp_load yet?\n'
'ERROR: Response_t has no entry for n_i=7\n')
self.assertEqual(
all_logs[7],
'Array_t_009 Station 9003 Channel 1\n2 error, 2 warning, 0 info\n')
self.assertEqual(
all_logs[8],
'ERROR: No Response table found. Have you run resp_load yet?\n'
'ERROR: Response_t has no entry for n_i=7\n')
def test_get_args(self):
testargs = ['ph5_validate', '-n', 'master.ph5', '-p', self.tmpdir,
'-l', 'WARN']
with patch.object(sys, 'argv', testargs):
with OutputCapture() as out:
self.assertRaises(SystemExit, ph5validate.get_args)
output = out.captured.strip().split('\n')
self.assertEqual(
output[1],
"ph5_validate: error: argument -l/--level: invalid choice: "
"'WARN' (choose from 'ERROR', 'WARNING', 'INFO')")
testargs = ['ph5_validate', '-n', 'master.ph5', '-p', self.tmpdir,
'-l', 'WARNING']
with patch.object(sys, 'argv', testargs):
ret = ph5validate.get_args()
self.assertEqual(ret.level, 'WARNING')
self.assertEqual(ret.nickname, 'master.ph5')
self.assertEqual(ret.outfile, 'ph5_validate.log')
self.assertEqual(ret.ph5path, self.tmpdir)
self.assertEqual(ret.verbose, False)
class TestPh5Validate_conflict_time(TempDirTestCase, LogTestCase):
"""
Check conflict times between array_t and das_t
"""
def setUp(self):
super(TestPh5Validate_conflict_time, self).setUp()
kef_to_ph5(
self.tmpdir, 'master.ph5',
os.path.join(self.home, 'ph5/test_data'),
['rt125a/das_t_12183.kef', 'metadata/array_t_9_validate.kef'],
das_sn_list=['12183'])
self.ph5_object = ph5api.PH5(path=self.tmpdir, nickname='master.ph5')
self.ph5validate = ph5validate.PH5Validate(
self.ph5_object, self.tmpdir)
def tearDown(self):
self.ph5_object.ph5close()
super(TestPh5Validate_conflict_time, self).tearDown()
def test_check_array_t(self):
"""
check log messages, das_time and validation block return
"""
with LogCapture() as log:
log.setLevel(logging.INFO)
vb = self.ph5validate.check_array_t()
self.assertEqual(log.records[0].msg, "Validating Array_t")
self.assertEqual(
self.ph5validate.das_time,
{('12183', 1, 500):
{'max_pickup_time': [1550850187],
'time_windows': [(1550849950, 1550850034, '9001'),
(1550849950, 1550850034, '9001'),
(1550849950, 1550850034, '9001'),
(1550850043, 1550850093, '9002'),
(1550850125, 1550850187, '9003')],
'min_deploy_time':
[1550849950,
'Data exists before deploy time: 7 seconds.']}}
)
self.assertEqual(vb[0].heading,
'-=-=-=-=-=-=-=-=-\n'
'Array_t_009 Station 9001 Channel 1\n'
'2 error, 3 warning, 0 info\n-=-=-=-=-=-=-=-=-\n')
self.assertEqual(vb[0].info, [])
self.assertEqual(
vb[0].warning,
['No station description found.',
'Data exists before deploy time: 7 seconds.',
'Station 9001 [1550849950, 1550850034] is repeated 2 time(s)'])
self.assertEqual(
vb[0].error,
['No Response table found. Have you run resp_load yet?',
'Response_t has no entry for n_i=7']
)
self.assertEqual(vb[1].heading,
'-=-=-=-=-=-=-=-=-\n'
'Array_t_009 Station 9002 Channel 1\n'
'2 error, 2 warning, 0 info\n-=-=-=-=-=-=-=-=-\n')
self.assertEqual(vb[1].info, [])
self.assertEqual(
vb[1].warning,
['No station description found.',
'Data exists after pickup time: 36 seconds.'])
self.assertEqual(
vb[1].error,
['No Response table found. Have you run resp_load yet?',
'Response_t has no entry for n_i=7']
)
self.assertEqual(vb[2].heading,
'-=-=-=-=-=-=-=-=-\n'
'Array_t_009 Station 9003 Channel 1\n'
'2 error, 2 warning, 0 info\n-=-=-=-=-=-=-=-=-\n')
self.assertEqual(vb[2].info, [])
self.assertEqual(
vb[2].warning,
['No station description found.',
'Data exists after pickup time: 2 seconds.'])
self.assertEqual(
vb[2].error,
['No Response table found. Have you run resp_load yet?',
'Response_t has no entry for n_i=7']
)
def test_analyze_time(self):
"""
+ check if das_time created has all time and station info
+ check if it catch the case data exists before the whole time range
"""
self.ph5validate.analyze_time()
self.assertEqual(self.ph5validate.das_time.keys(), [('12183', 1, 500)])
Dtime = self.ph5validate.das_time[('12183', 1, 500)]
# 3 different deploy time
self.assertEqual(len(Dtime['time_windows']), 5)
# station 9001
self.assertEqual(Dtime['time_windows'][0],
(1550849950, 1550850034, '9001'))
self.assertEqual(Dtime['time_windows'][1],
(1550849950, 1550850034, '9001'))
self.assertEqual(Dtime['time_windows'][2],
(1550849950, 1550850034, '9001'))
# station 9002
self.assertEqual(Dtime['time_windows'][3],
(1550850043, 1550850093, '9002'))
# station 9003
self.assertEqual(Dtime['time_windows'][4],
(1550850125, 1550850187, '9003'))
self.assertEqual(Dtime['min_deploy_time'],
[1550849950,
'Data exists before deploy time: 7 seconds.'])
def test_check_station_completeness(self):
self.ph5validate.das_time = {
('12183', 1, 500):
{'time_windows': [(1550849950, 1550850034, '9001'),
(1550849950, 1550850034, '9001'),
(1550849950, 1550850034, '9001'),
(1550849950, 1550850034, '9001'),
(1550850043, 1550850093, '9002'),
(1550850125, 1550850187, '9003')],
'min_deploy_time': [1550849950,
'Data exists before deploy time: 7 seconds.'],
}
}
self.ph5validate.read_arrays('Array_t_009')
arraybyid = self.ph5validate.ph5.Array_t['Array_t_009']['byid']
DT = self.ph5validate.das_time[('12183', 1, 500)]
# check lon/lat not in range
# check warning data exist before min_deploy_time
station = arraybyid.get('9001')[1][0]
station['location/X/value_d'] = 190.0
station['location/X/units_s'] = 'degrees'
station['location/Y/value_d'] = -100.0
station['location/Y/units_s'] = 'degrees'
station['location/Z/value_d'] = 1403
station['location/Z/units_s'] = 'm'
ret = self.ph5validate.check_station_completeness(station)
warnings = ret[1]
self.assertEqual(
warnings,
['No station description found.',
'Data exists before deploy time: 7 seconds.',
'Station 9001 [1550849950, 1550850034] is repeated 3 time(s)'])
errors = ret[2]
self.assertEqual(
errors,
['No Response table found. Have you run resp_load yet?',
'Channel longitude 190.0 not in range [-180,180]',
'Channel latitude -100.0 not in range [-90,90]'])
# check lon/lat = 0, no units, no elevation value
# check warning data after pickup time
station = arraybyid.get('9002')[1][0]
station['location/X/value_d'] = 0
station['location/X/units_s'] = ''
station['location/Y/value_d'] = 0
station['location/Y/units_s'] = None
station['location/Z/value_d'] = None
station['location/Z/units_s'] = ''
ret = self.ph5validate.check_station_completeness(station)
warnings = ret[1]
self.assertEqual(
warnings,
['No station description found.',
'Channel longitude seems to be 0. Is this correct???',
'No Station location/X/units_s value found.',
'Channel latitude seems to be 0. Is this correct???',
'No Station location/Y/units_s value found.',
'No Station location/Z/units_s value found.',
'Data exists after pickup time: 36 seconds.'])
errors = ret[2]
self.assertEqual(
errors,
['No Response table found. Have you run resp_load yet?'])
# check error overlaping
# => change deploy time of the 3rd station
DT['time_windows'][5] = (1550850090, 1550850187, '9003')
ret = self.ph5validate.check_station_completeness(station)
errors = ret[2]
self.assertIn('Overlap time on station(s): 9002, 9003', errors)
# check no data found for array's time
# => change array's time to where there is no data
station = arraybyid.get('9003')[1][0]
station['deploy_time/epoch_l'] = 1550850190
station['pickup_time/epoch_l'] = 1550850191
DT['time_windows'][5] = (1550850190, 1550850191, '9003')
ret = self.ph5validate.check_station_completeness(station)
errors = ret[2]
self.assertIn("No data found for das serial number 12183 during this "
"station's time. You may need to reload the raw data "
"for this station.",
errors)
# check no data found errors
station = arraybyid.get('9002')[1][0]
station['das/serial_number_s'] = '1218'
self.ph5validate.das_time[
('1218', 1, 500)] = self.ph5validate.das_time[('12183', 1, 500)]
ret = self.ph5validate.check_station_completeness(station)
errors = ret[2]
self.assertIn("No data found for das serial number 1218. "
"You may need to reload the raw data for this station.",
errors)
class TestPh5Validate_currPH5(TempDirTestCase, LogTestCase):
def setUp(self):
super(TestPh5Validate_currPH5, self).setUp()
ph5path = os.path.join(self.home, 'ph5/test_data/ph5')
self.ph5_object = ph5api.PH5(
path=ph5path, nickname='master.ph5')
self.ph5validate = ph5validate.PH5Validate(
self.ph5_object, ph5path)
def tearDown(self):
self.ph5_object.ph5close()
super(TestPh5Validate_currPH5, self).tearDown()
def test_check_experiment_t(self):
# check no net_code_s
experiment_t = self.ph5_object.Experiment_t['rows']
experiment_t[0]['net_code_s'] = ''
info, warning, error = \
self.ph5validate.check_experiment_t_completeness(experiment_t)
self.assertIn('Network code was not found: '
'A 2 character network code is required.',
error)
def test_check_station_completeness(self):
self.ph5validate.analyze_time()
das_time = self.ph5validate.das_time
station = self.ph5_object.Array_t['Array_t_008']['byid']['8001'][1][0]
# id_s isn't a whole number => error
das_time[('9EEF', 1, 100)]['time_windows'][0] = \
(1463568480, 1463568540, '33a33')
station['id_s'] = '33a33'
inf, warn, err = self.ph5validate.check_station_completeness(station)
self.assertIn("Station ID '33a33' not a whole number "
"between 0 and 65535.",
err)
# id_s not in range [0,65535] => error
das_time[('9EEF', 1, 100)]['time_windows'][0] = \
(1463568480, 1463568540, '65536')
station['id_s'] = '65536'
inf, warn, err = self.ph5validate.check_station_completeness(station)
self.assertIn("Station ID '65536' not between 0 and 65535.",
err)
# id_s in range [32768, 65534] => warning
das_time[('9EEF', 1, 100)]['time_windows'][0] = \
(1463568480, 1463568540, '33333')
station['id_s'] = '33333'
inf, warn, err = self.ph5validate.check_station_completeness(station)
self.assertIn("Station ID '33333' is more than 32767. "
"Not compatible with SEGY revision 1.",
warn)
# sample_rate=0 => warning
das_time[('12183', 1, 0)] = das_time[('12183', 1, 500)]
station = self.ph5_object.Array_t['Array_t_009']['byid']['9001'][1][0]
station['sample_rate_i'] = 0
inf, warn, err = self.ph5validate.check_station_completeness(station)
self.assertIn("Sample rate seems to be 0. Is this correct???",
warn)
# sample_rate<0 => error
das_time[('12183', 1, -1)] = das_time[('12183', 1, 500)]
station['sample_rate_i'] = -1
inf, warn, err = self.ph5validate.check_station_completeness(station)
self.assertIn("Sample rate = -1 not positive.",
err)
# sample_rate_multiplier_i isn't a integer => error
station['sample_rate_i'] = 500
station['sample_rate_multiplier_i'] = 1.1
inf, warn, err = self.ph5validate.check_station_completeness(station)
self.assertIn("Sample rate multiplier = 1.1 is not an"
" integer greater than 1.",
err)
# sample_rate_multiplier_i<1 => error
station['sample_rate_multiplier_i'] = 0
inf, warn, err = self.ph5validate.check_station_completeness(station)
self.assertIn("Sample rate multiplier = 0 is not an integer "
"greater than 1.",
err)
def test_check_event_t_completeness(self):
self.ph5_object.read_event_t('Event_t_001')
event = self.ph5_object.Event_t['Event_t_001']['byid']['7001']
# id_s isn't a whole number => error
event['id_s'] = '7a001'
inf, warn, err = self.ph5validate.check_event_t_completeness(event)
self.assertIn("Event ID '7a001' not a whole "
"number between 0 and 65535.",
err)
# id_s isn't in range [0, 65535] => error
event['id_s'] = '65536'
inf, warn, err = self.ph5validate.check_event_t_completeness(event)
self.assertIn("Event ID '65536' not between 0 and 65535.",
err)
# id_s in range [32768, 65534] => warning
event['id_s'] = '32769'
inf, warn, err = self.ph5validate.check_event_t_completeness(event)
self.assertIn("Event ID '32769' is more than 32767. "
"Not compatible with SEGY revision 1.",
warn)
# no log for location/coordinate_system_s, projection_s, ellipsoid_s,
# ellipsoid_s
# warning for location/X,Y,Z/units_s
event['id_s'] = '7001'
event['location/coordinate_system_s'] = ''
event['location/projection_s'] = ''
event['location/ellipsoid_s'] = ''
event['location/description_s'] = ''
event['location/X/units_s'] = ''
event['location/Y/units_s'] = ''
event['location/Z/units_s'] = ''
inf, warn, err = self.ph5validate.check_event_t_completeness(event)
self.assertEqual((inf, warn, err),
([],
['Event description is missing.',
'No Event location/X/units_s value found.',
'No Event location/Y/units_s value found.',
'No Event location/Z/units_s value found.'],
[])
)
class TestPh5Validate_noEvent(TempDirTestCase, LogTestCase):
def tearDown(self):
self.ph5_object.ph5close()
super(TestPh5Validate_noEvent, self).tearDown()
def test_check_no_event(self):
testargs = ['segd2ph5', '-n', 'master.ph5', '-r',
os.path.join(self.home, 'ph5/test_data/segd/fairfield/'
'1111.1.0.fcnt')]
with patch.object(sys, 'argv', testargs):
segd2ph5.main()
self.ph5_object = ph5api.PH5(
path=self.tmpdir, nickname='master.ph5')
self.ph5validate = ph5validate.PH5Validate(
self.ph5_object, self.tmpdir)
vbs = self.ph5validate.check_event_t()
self.assertEqual(len(vbs), 1)
self.assertIn("Event_t table not found. "
"Did this experiment have shots???",
vbs[0]. warning)
class TestPH5Validate_no_response_filename(LogTestCase, TempDirTestCase):
def tearDown(self):
self.ph5API_object.close()
super(TestPH5Validate_no_response_filename, self).tearDown()
def test_check_response_t(self):
testargs = ['segdtoph5', '-n', 'master.ph5', '-U', '13N', '-r',
os.path.join(self.home,
'ph5/test_data/segd/fairfield/3ch.fcnt')]
with patch.object(sys, 'argv', testargs):
segd2ph5.main()
self.ph5API_object = ph5api.PH5(path=self.tmpdir,
nickname='master.ph5')
self.ph5validate = ph5validate.PH5Validate(self.ph5API_object, '.')
with LogCapture() as log:
log.setLevel(logging.ERROR)
ret = self.ph5validate.check_response_t()
self.assertEqual(
ret[0].error,
["Response table does not contain any response file names. "
"Check if resp_load has been run or if metadatatoph5 input "
"contained response information."])
self.assertEqual(
log.records[0].msg,
"Response table does not contain any response file names. "
"Check if resp_load has been run or if metadatatoph5 input "
"contained response information.")
if __name__ == "__main__":
unittest.main()