From 57b4d7367abfbb5c663b9e90fc756edf450ed33f Mon Sep 17 00:00:00 2001
From: kienle <kienle@passcal.nmt.edu>
Date: Wed, 28 Sep 2022 10:44:49 -0600
Subject: [PATCH] Add tests for sortData

---
 tests/test_model/test_handling_data.py | 62 ++++++++++++++++++--------
 1 file changed, 44 insertions(+), 18 deletions(-)

diff --git a/tests/test_model/test_handling_data.py b/tests/test_model/test_handling_data.py
index b16ef6c2a..db4da3274 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)
+
-- 
GitLab