Newer
Older
from sohstationviewer.database.extract_data import (
get_chan_plot_info,
get_signature_channels,
get_color_def,
get_color_ranges,
convert_actual_channel_to_db_channel_w_question_mark,
get_convert_factor
class TestGetChanPlotInfo(unittest.TestCase):
def test_good_soh_channel_and_data_type(self):
Test basic functionality of get_chan_plot_info - 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(get_chan_plot_info('SOH/Data Def', 'RT130'),
expected_result)
def test_masspos_channel(self):
with self.subTest("Mass position 'VM'"):
expected_result = {'channel': 'VM1',
'plotType': 'linesMasspos',
'height': 4,
'unit': 'V',
'linkedChan': None,
'convertFactor': 0.1,
'label': 'VM1-MassPos',
'fixPoint': 1,
'valueColors': None}
self.assertDictEqual(get_chan_plot_info('VM1', 'Q330'),
expected_result)
with self.subTest("Mass position 'MassPos'"):
expected_result = {'channel': 'MassPos1',
'plotType': 'linesMasspos',
'height': 4,
'unit': 'V',
'linkedChan': None,
'convertFactor': 1,
'label': 'MassPos1',
'fixPoint': 1,
'valueColors': None}
self.assertDictEqual(get_chan_plot_info('MassPos1', 'RT130'),
expected_result)
def test_seismic_channel(self):
with self.subTest("RT130 Seismic"):
expected_result = {'channel': 'DS2',
'plotType': 'linesSRate',
'unit': '',
'linkedChan': None,
'convertFactor': 1,
'label': 'DS2',
'fixPoint': 0,
'valueColors': None}
self.assertDictEqual(get_chan_plot_info('DS2', 'RT130'),
expected_result)
with self.subTest("MSeed Seismic"):
expected_result = {'channel': 'LHE',
'plotType': 'linesSRate',
'unit': '',
'linkedChan': None,
'convertFactor': 1,
'label': 'LHE-EW',
'fixPoint': 0,
'valueColors': None}
self.assertDictEqual(get_chan_plot_info('LHE', 'Q330'),
expected_result)
def test_data_type_is_unknown(self):
Test basic functionality of get_chan_plot_info - 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',
self.assertDictEqual(get_chan_plot_info('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,
self.assertDictEqual(
get_chan_plot_info('LCE', 'Unknown'),
expected_result)
def test_bad_channel_or_data_type(self):
Test basic functionality of get_chan_plot_info - 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
'valueColors': None}
# Data type has None value. None value comes from
expected_result['label'] = 'DEFAULT-SOH/Data Def'
self.assertDictEqual(get_chan_plot_info('SOH/Data Def', None),
expected_result)
# Channel and data type are empty strings
expected_result['label'] = 'DEFAULT-'
self.assertDictEqual(get_chan_plot_info('', ''),
expected_result)
# Channel exists in database but data type does not
expected_result['label'] = 'DEFAULT-SOH/Data Def'
get_chan_plot_info('SOH/Data Def', 'Bad Data Type'),
# Data type exists in database but channel does not
expected_result['label'] = 'DEFAULT-Bad Channel ID'
self.assertDictEqual(get_chan_plot_info('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(get_chan_plot_info('SOH/Data Def', 'Q330'),
expected_result)
class TestGetSeismicChanLabel(unittest.TestCase):
def test_good_channel_id(self):
Test basic functionality of get_seismic_chan_label - 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(get_seismic_chan_label('CH1'), 'CH1-NS')
self.assertEqual(get_seismic_chan_label('CH2'), 'CH2-EW')
self.assertEqual(get_seismic_chan_label('CHG'), 'CHG')
self.assertEqual(get_seismic_chan_label('DS-TEST-CHANNEL'),
'DS-TEST-CHANNEL')
def test_bad_channel_id(self):
Test basic functionality of get_seismic_chan_label - channel ID does
not end in one of the keys in conf.dbSettings.dbConf['seisLabel']
or is the empty string.
self.assertRaises(IndexError, get_seismic_chan_label, '')
class TestGetSignatureChannels(unittest.TestCase):
def test_get_signature_channels(self):
"""Test basic functionality of get_signature_channels"""
self.assertIsInstance(get_signature_channels(), dict)
class TestGetColorDef(unittest.TestCase):
"""Test basic functionality of get_color_def"""
colors = get_color_def()
expected_colors = ['K', 'U', 'C', 'G', 'Y', 'R', 'M', 'E']
self.assertListEqual(colors, expected_colors)
class TestGetColorRanges(unittest.TestCase):
"""Test basic functionality of get_color_ranges"""
names, all_counts, all_display_strings = get_color_ranges()
expected_names = ['Antarctica', 'Low', 'Medium', '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)
class TestConvertActualChannelToDBChannelWQuestionMark(unittest.TestCase):
def test_question_channel(self):
ret = convert_actual_channel_to_db_channel_w_question_mark('VM1')
self.assertEqual(ret, 'VM?')
def test_non_question_channel(self):
ret = convert_actual_channel_to_db_channel_w_question_mark('VCO')
self.assertEqual(ret, 'VCO')
class TestGetConvertFactor(unittest.TestCase):
def test_question_channel(self):
ret = get_convert_factor('VM1', 'Centaur')
self.assertEqual(ret, 10**(-6))
def test_non_question_channel(self):
ret = get_convert_factor('VEP', 'Q330')
self.assertEqual(ret, 0.15)