Newer
Older
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
import unittest
from sohstationviewer.database.extractData import (
getChanPlotInfo,
getWFPlotInfo,
getChanLabel,
signatureChannels,
getColorDef,
getColorRanges,
)
class TestExtractData(unittest.TestCase):
def test_get_chan_plot_info_good_channel_and_data_type(self):
"""
Test basic functionality of getChanPlotInfo - channel and data type
combination exists in database table `Channels`
"""
expected_result = {'channel': 'SOH/Data Def',
'plotType': 'upDownDots',
'height': 2,
'unit': '',
'linkedChan': None,
'convertFactor': 1,
'label': 'SOH/Data Def',
'fixPoint': 0,
'valueColors': '0:W|1:C'}
self.assertDictEqual(getChanPlotInfo('SOH/Data Def', 'RT130'),
expected_result)
def test_get_chan_plot_info_data_type_is_unknown(self):
"""
Test basic functionality of getChanPlotInfo - data type is the string
'Unknown'.
"""
# Channel does not exist in database
expected_result = {'channel': 'DEFAULT',
'plotType': 'linesDots',
'height': 2,
'unit': '',
'linkedChan': None,
'convertFactor': 1,
'label': 'DEFAULT-Bad Channel ID',
'fixPoint': '0',
'valueColors': None}
self.assertDictEqual(getChanPlotInfo('Bad Channel ID', 'Unknown'),
expected_result)
# Channel exist in database
expected_result = {'channel': 'LCE',
'plotType': 'linesDots',
'height': 3,
'unit': 'us',
'linkedChan': None,
'convertFactor': 1,
'label': 'LCE-PhaseError',
'fixPoint': 0,
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
self.assertDictEqual(getChanPlotInfo('LCE', 'Unknown'),
expected_result)
def test_get_chan_plot_info_bad_channel_or_data_type(self):
"""
Test basic functionality of getChanPlotInfo - channel and data type
combination does not exist in database table Channels and data type is
not the string 'Unknown'.
"""
# noinspection PyDictCreation
expected_result = {'channel': 'DEFAULT',
'plotType': 'linesDots',
'height': 2,
'unit': '',
'linkedChan': None,
'convertFactor': 1,
'label': None, # Change for each test case
'fixPoint': '0',
'valueColors': None}
# Data type has None value. None value comes from
# controller.processing.detectDataType.
expected_result['label'] = 'DEFAULT-SOH/Data Def'
self.assertDictEqual(getChanPlotInfo('SOH/Data Def', None),
expected_result)
# Channel and data type are empty strings
expected_result['label'] = 'DEFAULT-'
self.assertDictEqual(getChanPlotInfo('', ''), expected_result)
# Channel exists in database but data type does not
expected_result['label'] = 'DEFAULT-SOH/Data Def'
self.assertDictEqual(getChanPlotInfo('SOH/Data Def', 'Bad Data Type'),
expected_result)
# Data type exists in database but channel does not
expected_result['label'] = 'DEFAULT-Bad Channel ID'
self.assertDictEqual(getChanPlotInfo('Bad Channel ID', 'RT130'),
expected_result)
# Both channel and data type exists in database but not their
# combination
expected_result['label'] = 'DEFAULT-SOH/Data Def'
self.assertDictEqual(getChanPlotInfo('SOH/Data Def', 'Q330'),
expected_result)
def test_get_wf_plot_info(self):
"""
Test basic functionality of getWFPlotInfo - ensures returned dictionary
contains all the needed key. Bad channel IDs cases are handled in tests
for getChanLabel.
"""
result = getWFPlotInfo('CH1')
expected_keys = ('param', 'plotType', 'valueColors', 'height',
'label', 'unit', 'channel')
self.assertTupleEqual(tuple(result.keys()), expected_keys)
def test_get_chan_label_good_channel_id(self):
"""
Test basic functionality of getChanLabel - channel ID ends in one
of the keys in conf.dbSettings.dbConf['seisLabel'] or starts with 'DS'
"""
# Channel ID does not start with 'DS'
self.assertEqual(getChanLabel('CH1'), 'CH1-NS')
self.assertEqual(getChanLabel('CH2'), 'CH2-EW')
# Channel ID starts with 'DS'
self.assertEqual(getChanLabel('DS-TEST-CHANNEL'), 'DS-TEST-CHANNEL')
def test_get_chan_label_bad_channel_id(self):
"""
Test basic functionality of getChanLabel - channel ID does not end in
one of the keys in conf.dbSettings.dbConf['seisLabel'] or is the empty
string.
"""
self.assertRaises(KeyError, getChanLabel, 'CHG')
self.assertRaises(IndexError, getChanLabel, '')
def test_signature_channels(self):
"""Test basic functionality of signatureChannels"""
self.assertIsInstance(signatureChannels(), dict)
def test_get_color_def(self):
"""Test basic functionality of getColorDef"""
colors = getColorDef()
expected_colors = ['K', 'U', 'C', 'G', 'Y', 'R', 'M', 'E']
self.assertListEqual(colors, expected_colors)
def test_get_color_ranges(self):
"""Test basic functionality of getColorDef"""
names, all_counts, all_display_strings = getColorRanges()
num_color_def = 7
expected_names = ['antarctica', 'low', 'med', 'high']
self.assertEqual(names, expected_names)
# Check that each name correspond to a list of counts and list of
# of strings to display
self.assertEqual(len(names), len(all_counts))
self.assertEqual(len(names), len(all_display_strings))
# Check that each list of counts have enough items
for counts in all_counts:
self.assertEqual(len(counts), num_color_def)
# Check that each list of strings to display have enough items
for display_strings in all_display_strings:
self.assertEqual(len(display_strings), num_color_def + 1)