diff --git a/tests/test_model/test_handling_data.py b/tests/test_model/test_handling_data.py index b16ef6c2aa0f0d574a86545b1c4a2df19fbb047f..db4da3274ca17e078d6323df8969edce7d5f1381 100644 --- a/tests/test_model/test_handling_data.py +++ b/tests/test_model/test_handling_data.py @@ -1,3 +1,10 @@ +""" Test suites for the functions defined in handling_data + +All random test data are named in the format sample_* and are generated using +the builtin random library with a seed of 22589824271860044. This seed is +obtained by converting the string PASSCAL to bytes and converting the resulting +bytes to an integer with big endian ordering.""" + from pathlib import Path import tempfile from math import isclose @@ -22,7 +29,8 @@ from sohstationviewer.model.handling_data import ( saveData2File, checkChan, checkWFChan, - checkSOHChan + checkSOHChan, + sortData ) from sohstationviewer.model.reftek.from_rt2ms.core import Reftek130 @@ -124,18 +132,6 @@ class TestHandlingData(TestCase): self.assertTrue(mock_save_data_2_file.called) - # @skip - # def test_check_sohchan(self): - # self.fail() - # - # @skip - # def test_check_wfchan(self): - # self.fail() - # - # @skip - # def test_sort_data(self): - # self.fail() - # # @skip # def test_squash_gaps(self): # self.fail() @@ -613,10 +609,6 @@ class TestCheckChan(TestCase): class TestCheckSohChan(TestCase): def setUp(self) -> None: self.req_soh_chans = ['LCE', 'LCQ', 'EX?'] - # Generated using the builtin random library with a seed of - # 22589824271860044. This seed is obtained by converting the string - # PASSCAL to bytes and converting the resulting bytes to an integer - # with big endian ordering. self.sample_channel_ids = ['ODV', 'QGA', 'NF4', 'OLY', 'UZM'] def test_all_channels_requested(self): @@ -686,4 +678,38 @@ class TestCheckWfChan(TestCase): self.assertTupleEqual( checkWFChan(channel_id, self.req_wf_chans), ('', False) - ) \ No newline at end of file + ) + + +class TestSortData(TestCase): + def setUp(self): + station_id = 'station' + channel_id = 'channel' + + self.data_dict = {} + self.data_dict[station_id] = {} + station_data = self.data_dict[station_id] + station_data['readData'] = {} + read_data = station_data['readData'] + read_data[channel_id] = {} + channel_data = read_data[channel_id] + channel_data['tracesInfo'] = [] + self.traces_list: list = channel_data['tracesInfo'] + + self.sample_timestamps = [593960929, 336078110, 159498833, 77413117, + 359137083, 445180140, 280423288, 13462065, + 546898731, 219269289, 224077281, 111636543] + + @expectedFailure + def test_unsorted_data_is_sorted(self): + for timestamp in self.sample_timestamps: + self.traces_list.append({'startTmEpoch': timestamp}) + self.assertDictEqual(sortData(self.data_dict), self.data_dict) + + @expectedFailure + def test_sorted_data_stays_the_same(self): + self.sample_timestamps.sort() + for timestamp in self.sample_timestamps: + self.traces_list.append({'startTmEpoch': timestamp}) + self.assertDictEqual(sortData(self.data_dict), self.data_dict) +