From b7e55b718494add61e0f5326dd4697a4d2d33e91 Mon Sep 17 00:00:00 2001
From: ldam <ldam@passcal.nmt.edu>
Date: Wed, 26 Feb 2025 11:20:27 -0700
Subject: [PATCH] add test to unittest for check_masspos()

---
 tests/view/util/test_functions.py | 96 +++++++++++++++++++++++++------
 1 file changed, 77 insertions(+), 19 deletions(-)

diff --git a/tests/view/util/test_functions.py b/tests/view/util/test_functions.py
index 1e2855cdb..12e6b95c3 100644
--- a/tests/view/util/test_functions.py
+++ b/tests/view/util/test_functions.py
@@ -383,38 +383,96 @@ class TestCheckChanWildcardsFormat(BaseTestCase):
 class TestCheckMassPos(BaseTestCase):
     @classmethod
     def setUpClass(cls) -> None:
-        cls.mp_data = {'MP1': {'chan_id': 'MP1', 'samplerate': 1},
-                       'MP3': {'chan_id': 'MP3', 'samplerate': 1},
-                       'MP4': {'chan_id': 'MP4', 'samplerate': 1}}
         cls.sel_key = '1378'
 
-    def test_include_mp123(self):
-        with self.assertRaises(Exception) as context:
-            check_masspos(self.mp_data, self.sel_key,
-                          include_mp123=True, include_mp456=False)
-        self.assertEqual(
-            str(context.exception),
-            f"Data set {self.sel_key} doesn't include mass position 2")
+    def test_include_mp123_not_include_mp456(self):
+        with self.subTest("Consist of MP1,MP3"):
+            mp_data = {'MP1': {'chan_id': 'MP1', 'samplerate': 1},
+                       'MP3': {'chan_id': 'MP3', 'samplerate': 1},
+                       'MP4': {'chan_id': 'MP4', 'samplerate': 1}}
+            with self.assertRaises(Exception) as context:
+                check_masspos(mp_data, self.sel_key,
+                              include_mp123=True, include_mp456=False)
+            self.assertEqual(
+                str(context.exception),
+                f"Data set {self.sel_key} doesn't include mass position 2")
+        with self.subTest("Consist of  MP1,MP3,MPE"):
+            mp_data = {'MP1': {'chan_id': 'MP1', 'samplerate': 1},
+                       'MP3': {'chan_id': 'MP3', 'samplerate': 1},
+                       'MPE': {'chan_id': 'MPE', 'samplerate': 1},
+                       'MP4': {'chan_id': 'MP4', 'samplerate': 1}}
+            with self.assertRaises(Exception) as context:
+                check_masspos(mp_data, self.sel_key,
+                              include_mp123=True, include_mp456=False)
+            self.assertEqual(
+                str(context.exception),
+                f"Data set {self.sel_key} doesn't include mass position "
+                f"2,Z,N")
+        with self.subTest("Consist of MPB"):
+            mp_data = {'MPB': {'chan_id': 'MPB', 'samplerate': 1},
+                       'MP4': {'chan_id': 'MP4', 'samplerate': 1}}
+            with self.assertRaises(Exception) as context:
+                check_masspos(mp_data, self.sel_key,
+                              include_mp123=True, include_mp456=False)
+            self.assertEqual(
+                str(context.exception),
+                f"Data set {self.sel_key} doesn't include mass position "
+                f"A,C")
+        with self.subTest("No MP 123/ZNE/ABC"):
+            mp_data = {'MP4': {'chan_id': 'MP4', 'samplerate': 1}}
+            with self.assertRaises(Exception) as context:
+                check_masspos(mp_data, self.sel_key,
+                              include_mp123=True, include_mp456=False)
+            self.assertEqual(
+                str(context.exception),
+                f"Data set {self.sel_key} doesn't include mass position "
+                f"1,2,3")
 
-    def test_include_mp456(self):
-        with self.assertRaises(Exception) as context:
-            check_masspos(self.mp_data, self.sel_key,
-                          include_mp123=False, include_mp456=True)
-        self.assertEqual(
-            str(context.exception),
-            f"Data set {self.sel_key} doesn't include mass position 5,6")
+    def test_include_mp456_not_include456(self):
+        with self.subTest("Consist of MP4"):
+            mp_data = {'MP1': {'chan_id': 'MP1', 'samplerate': 1},
+                       'MP4': {'chan_id': 'MP4', 'samplerate': 1}}
+            with self.assertRaises(Exception) as context:
+                check_masspos(mp_data, self.sel_key,
+                              include_mp123=False, include_mp456=True)
+            self.assertEqual(
+                str(context.exception),
+                f"Data set {self.sel_key} doesn't include mass position 5,6")
+        with self.subTest("Consist of MPW"):
+            mp_data = {'MP1': {'chan_id': 'MP1', 'samplerate': 1},
+                       'MPW': {'chan_id': 'MPW', 'samplerate': 1}}
+            with self.assertRaises(Exception) as context:
+                check_masspos(mp_data, self.sel_key,
+                              include_mp123=False, include_mp456=True)
+            self.assertEqual(
+                str(context.exception),
+                f"Data set {self.sel_key} doesn't include mass position U,V")
+        with self.subTest("No MP 456/UVW"):
+            mp_data = {'MP1': {'chan_id': 'MP1', 'samplerate': 1}}
+            with self.assertRaises(Exception) as context:
+                check_masspos(mp_data, self.sel_key,
+                              include_mp123=False, include_mp456=True)
+            self.assertEqual(
+                str(context.exception),
+                f"Data set {self.sel_key} doesn't include mass position "
+                f"4,5,6")
 
     def test_include_mp123456(self):
+        mp_data = {'MP1': {'chan_id': 'MP1', 'samplerate': 1},
+                   'MP3': {'chan_id': 'MP3', 'samplerate': 1},
+                   'MP4': {'chan_id': 'MP4', 'samplerate': 1}}
         with self.assertRaises(Exception) as context:
-            check_masspos(self.mp_data, self.sel_key,
+            check_masspos(mp_data, self.sel_key,
                           include_mp123=True, include_mp456=True)
         self.assertEqual(
             str(context.exception),
             f"Data set {self.sel_key} doesn't include mass position 2,5,6")
 
     def test_not_include_mp(self):
+        mp_data = {'MP1': {'chan_id': 'MP1', 'samplerate': 1},
+                   'MP4': {'chan_id': 'MP4', 'samplerate': 1}}
         try:
-            check_masspos(self.mp_data, self.sel_key,
+            check_masspos(mp_data, self.sel_key,
                           include_mp123=False, include_mp456=False)
         except Exception:
             self.fail("check_masspos() raise Exception unexpectedly")
-- 
GitLab