Skip to content
Snippets Groups Projects
Commit e4f451d8 authored by Lan Dam's avatar Lan Dam
Browse files

add unittest for get_chan_plot_info() for masspos and seismic channels

parent ca7aa90d
No related branches found
No related tags found
1 merge request!131combine get wf plot info to get chan plot info
Pipeline #2578 failed with stage
in 3 minutes and 6 seconds
This commit is part of merge request !131. Comments created here will be created in the context of that merge request.
...@@ -2,8 +2,7 @@ import unittest ...@@ -2,8 +2,7 @@ import unittest
from sohstationviewer.database.extract_data import ( from sohstationviewer.database.extract_data import (
get_chan_plot_info, get_chan_plot_info,
get_wf_plot_info, get_seismic_chan_label,
get_chan_label,
get_signature_channels, get_signature_channels,
get_color_def, get_color_def,
get_color_ranges, get_color_ranges,
...@@ -11,7 +10,7 @@ from sohstationviewer.database.extract_data import ( ...@@ -11,7 +10,7 @@ from sohstationviewer.database.extract_data import (
class TestExtractData(unittest.TestCase): class TestExtractData(unittest.TestCase):
def test_get_chan_plot_info_good_channel_and_data_type(self): def test_get_chan_plot_info_good_soh_channel_and_data_type(self):
""" """
Test basic functionality of get_chan_plot_info - channel and data type Test basic functionality of get_chan_plot_info - channel and data type
combination exists in database table `Channels` combination exists in database table `Channels`
...@@ -25,9 +24,62 @@ class TestExtractData(unittest.TestCase): ...@@ -25,9 +24,62 @@ class TestExtractData(unittest.TestCase):
'label': 'SOH/Data Def', 'label': 'SOH/Data Def',
'fixPoint': 0, 'fixPoint': 0,
'valueColors': '0:W|1:C'} 'valueColors': '0:W|1:C'}
self.assertDictEqual( self.assertDictEqual(get_chan_plot_info('SOH/Data Def', 'RT130'),
get_chan_plot_info('SOH/Data Def', {'samplerate': 10}, 'RT130'), expected_result)
expected_result)
def test_get_chan_plot_info_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_get_chan_plot_info_seismic_channel(self):
with self.subTest("RT130 Seismic"):
expected_result = {'channel': 'DS2',
'plotType': 'linesSRate',
'height': 4,
'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',
'height': 4,
'unit': '',
'linkedChan': None,
'convertFactor': 1,
'label': 'LHE-EW',
'fixPoint': 0,
'valueColors': None}
self.assertDictEqual(get_chan_plot_info('LHE', 'Q330'),
expected_result)
def test_get_chan_plot_info_data_type_is_unknown(self): def test_get_chan_plot_info_data_type_is_unknown(self):
""" """
...@@ -44,10 +96,8 @@ class TestExtractData(unittest.TestCase): ...@@ -44,10 +96,8 @@ class TestExtractData(unittest.TestCase):
'label': 'DEFAULT-Bad Channel ID', 'label': 'DEFAULT-Bad Channel ID',
'fixPoint': 0, 'fixPoint': 0,
'valueColors': None} 'valueColors': None}
self.assertDictEqual( self.assertDictEqual(get_chan_plot_info('Bad Channel ID', 'Unknown'),
get_chan_plot_info('Bad Channel ID', expected_result)
{'samplerate': 10}, 'Unknown'),
expected_result)
# Channel exist in database # Channel exist in database
expected_result = {'channel': 'LCE', expected_result = {'channel': 'LCE',
...@@ -59,12 +109,8 @@ class TestExtractData(unittest.TestCase): ...@@ -59,12 +109,8 @@ class TestExtractData(unittest.TestCase):
'label': 'LCE-PhaseError', 'label': 'LCE-PhaseError',
'fixPoint': 0, 'fixPoint': 0,
'valueColors': 'L:W|D:Y'} 'valueColors': 'L:W|D:Y'}
self.assertDictEqual( self.assertDictEqual(get_chan_plot_info('LCE', 'Unknown'),
get_chan_plot_info('LCE', {'samplerate': 10}, 'Unknown'), expected_result)
expected_result)
self.assertDictEqual(
get_chan_plot_info('LCE', {'samplerate': 10}, 'Unknown'),
expected_result)
def test_get_chan_plot_info_bad_channel_or_data_type(self): def test_get_chan_plot_info_bad_channel_or_data_type(self):
""" """
...@@ -86,69 +132,54 @@ class TestExtractData(unittest.TestCase): ...@@ -86,69 +132,54 @@ class TestExtractData(unittest.TestCase):
# Data type has None value. None value comes from # Data type has None value. None value comes from
# controller.processing.detect_data_type. # controller.processing.detect_data_type.
expected_result['label'] = 'DEFAULT-SOH/Data Def' expected_result['label'] = 'DEFAULT-SOH/Data Def'
self.assertDictEqual( self.assertDictEqual(get_chan_plot_info('SOH/Data Def', None),
get_chan_plot_info('SOH/Data Def', {'samplerate': 10}, None), expected_result)
expected_result)
# Channel and data type are empty strings # Channel and data type are empty strings
expected_result['label'] = 'DEFAULT-' expected_result['label'] = 'DEFAULT-'
self.assertDictEqual( self.assertDictEqual(get_chan_plot_info('', ''),
get_chan_plot_info('', {'samplerate': 10}, ''), expected_result)
expected_result)
# Channel exists in database but data type does not # Channel exists in database but data type does not
expected_result['label'] = 'DEFAULT-SOH/Data Def' expected_result['label'] = 'DEFAULT-SOH/Data Def'
self.assertDictEqual( self.assertDictEqual(
get_chan_plot_info('SOH/Data Def', get_chan_plot_info('SOH/Data Def', 'Bad Data Type'),
{'samplerate': 10}, 'Bad Data Type'),
expected_result expected_result
) )
# Data type exists in database but channel does not # Data type exists in database but channel does not
expected_result['label'] = 'DEFAULT-Bad Channel ID' expected_result['label'] = 'DEFAULT-Bad Channel ID'
self.assertDictEqual( self.assertDictEqual(get_chan_plot_info('Bad Channel ID', 'RT130'),
get_chan_plot_info('Bad Channel ID', expected_result)
{'samplerate': 10}, 'RT130'),
expected_result)
# Both channel and data type exists in database but not their # Both channel and data type exists in database but not their
# combination # combination
expected_result['label'] = 'DEFAULT-SOH/Data Def' expected_result['label'] = 'DEFAULT-SOH/Data Def'
self.assertDictEqual( self.assertDictEqual(get_chan_plot_info('SOH/Data Def', 'Q330'),
get_chan_plot_info('SOH/Data Def', {'samplerate': 10}, 'Q330'), expected_result)
expected_result)
def test_get_wf_plot_info(self):
"""
Test basic functionality of get_wf_plot_info - ensures returned
dictionary contains all the needed key. Bad channel IDs cases are
handled in tests for get_chan_label.
"""
result = get_wf_plot_info('CH1')
expected_keys = {'param', 'plotType', 'valueColors', 'height',
'label', 'unit', 'channel', 'convertFactor'}
self.assertSetEqual(set(result.keys()), expected_keys)
def test_get_chan_label_good_channel_id(self): def test_get_seismic_chan_label_good_channel_id(self):
""" """
Test basic functionality of get_chan_label - channel ID ends in one Test basic functionality of get_seismic_chan_label - channel ID ends
of the keys in conf.dbSettings.dbConf['seisLabel'] or starts with 'DS' in one of the keys in conf.dbSettings.dbConf['seisLabel'] or
starts with 'DS'
""" """
# Channel ID does not start with 'DS' # Channel ID does not start with 'DS'
self.assertEqual(get_chan_label('CH1'), 'CH1-NS') self.assertEqual(get_seismic_chan_label('CH1'), 'CH1-NS')
self.assertEqual(get_chan_label('CH2'), 'CH2-EW') self.assertEqual(get_seismic_chan_label('CH2'), 'CH2-EW')
self.assertEqual(get_chan_label('CHG'), 'CHG') self.assertEqual(get_seismic_chan_label('CHG'), 'CHG')
# Channel ID starts with 'DS' # Channel ID starts with 'DS'
self.assertEqual(get_chan_label('DS-TEST-CHANNEL'), 'DS-TEST-CHANNEL') self.assertEqual(get_seismic_chan_label('DS-TEST-CHANNEL'),
'DS-TEST-CHANNEL')
def test_get_chan_label_bad_channel_id(self): def test_get_chan_label_bad_channel_id(self):
""" """
Test basic functionality of get_chan_label - channel ID does not end in Test basic functionality of get_seismic_chan_label - channel ID does
one of the keys in conf.dbSettings.dbConf['seisLabel'] or is the empty not end in one of the keys in conf.dbSettings.dbConf['seisLabel']
string. or is the empty string.
""" """
self.assertRaises(IndexError, get_chan_label, '') self.assertRaises(IndexError, get_seismic_chan_label, '')
def test_get_signature_channels(self): def test_get_signature_channels(self):
"""Test basic functionality of get_signature_channels""" """Test basic functionality of get_signature_channels"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment