From 42e5b0f9c410394c3de3fd57cbfdd5fe5ab082a8 Mon Sep 17 00:00:00 2001
From: Jorrit Schaap <schaap@astron.nl>
Date: Wed, 11 Sep 2019 16:24:05 +0200
Subject: [PATCH] SW-815: more checks for integer types.

---
 .../test/test_taskprescheduler.py             | 22 +++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/SAS/ResourceAssignment/TaskPrescheduler/test/test_taskprescheduler.py b/SAS/ResourceAssignment/TaskPrescheduler/test/test_taskprescheduler.py
index d3d7fdc5f44..caee9c0c927 100755
--- a/SAS/ResourceAssignment/TaskPrescheduler/test/test_taskprescheduler.py
+++ b/SAS/ResourceAssignment/TaskPrescheduler/test/test_taskprescheduler.py
@@ -208,7 +208,14 @@ class PreschedulerTest(unittest.TestCase):
 
     def test_CobaltOTDBsettings(self):
         otdb_info = cobaltOTDBsettings(self.test_cobalt_settings)
+
+        # beware! assertEqual succeeds for a comparison between 42.0 and 42
+        # but for lofar specs it is essential that some values are int
+        # so, check specifically for those!
         self.assertEqual(otdb_info, self.otdb_info)
+        self.assertEqual(int, type(otdb_info['LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.Correlator.nrBlocksPerIntegration']))
+        self.assertEqual(int, type(otdb_info['LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.Correlator.nrIntegrationsPerBlock']))
+        self.assertEqual(int, type(otdb_info['LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.blockSize']))
 
     @mock.patch('lofar.sas.resourceassignment.common.specification.logger')
     def test_onObservationApproved_log_mom_id_found(self, logger_mock):
@@ -301,6 +308,21 @@ class PreschedulerTest(unittest.TestCase):
         self.assertEqual(int, type(cobalt_settings['nrBlocks']))
         self.assertEqual(int, type(cobalt_settings['nrSubBlocks']))
 
+    def test_calculateCobaltSettingsAndConvertToOTDBsettings(self):
+        '''combination of test_CobaltOTDBsettings and test_calculateCobaltSettings
+        Make sure that the values are calculated and converted correctly'''
+        spec = Specification(self.otdbrpc_mock, self.momrpc_mock, self.radbrpc_mock)
+        spec.internal_dict = self.test_specification
+        otdb_info = cobaltOTDBsettings(calculateCobaltSettings(spec))
+
+        # beware! assertEqual succeeds for a comparison between 42.0 and 42
+        # but for lofar specs it is essential that some values are int
+        # so, check specifically for those!
+        self.assertEqual(otdb_info, self.otdb_info)
+        self.assertEqual(int, type(otdb_info['LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.Correlator.nrBlocksPerIntegration']))
+        self.assertEqual(int, type(otdb_info['LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.Correlator.nrIntegrationsPerBlock']))
+        self.assertEqual(int, type(otdb_info['LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.blockSize']))
+
     @mock.patch("lofar.common.util.waitForInterrupt")
     @mock.patch("lofar.messaging.messagebus.BusListener.start_listening")
     def test_main(self, mock_wait, mock_otdbbuslistener):
-- 
GitLab