Repository: simonsobs/ocs

Issue:
Add boolean support to OCS feeds
Once Bool support is added to so3g (https://github.com/simonsobs/so3g/issues/116)  `Feed.verify_message_data_type` should be updated to support bools.

Discussion:

Patch:
diff --git a/Dockerfile b/Dockerfile
index 49d1f0d..6b7bc59 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -2,7 +2,7 @@
 # A container setup with an installation of ocs.
 
 # Use ubuntu base image
-FROM simonsobs/so3g:v0.1.0-117-g75c1d8d
+FROM simonsobs/so3g:v0.1.3-13-g5471f0d
 
 # Set locale
 ENV LANG C.UTF-8
diff --git a/ocs/ocs_feed.py b/ocs/ocs_feed.py
index 0e59b49..934e727 100644
--- a/ocs/ocs_feed.py
+++ b/ocs/ocs_feed.py
@@ -248,17 +248,15 @@ class Feed:
         supported types.
 
         Args:
-            value (list, float, int):
+            value (list, float, int, bool):
                 'data' dictionary value published (see Feed.publish_message for details).
 
         """
-        valid_types = (float, int, str)
+        valid_types = (float, int, str, bool)
 
-        # separate bool checks since bool is a subclass of int
         # multi-sample check
         if isinstance(value, list):
-            if (any(isinstance(x, bool) for x in value)
-                    or not all(isinstance(x, valid_types) for x in value)):
+            if not all(isinstance(x, valid_types) for x in value):
                 type_set = set([type(x) for x in value])
                 invalid_types = type_set.difference(valid_types)
                 raise TypeError("message 'data' block contains invalid data" +
@@ -266,7 +264,7 @@ class Feed:
 
         # single sample check
         else:
-            if isinstance(value, bool) or not isinstance(value, valid_types):
+            if not isinstance(value, valid_types):
                 invalid_type = type(value)
                 raise TypeError("message 'data' block contains invalid " +
                                 f"data type: {invalid_type}")


Test patch:
diff --git a/tests/test_ocs_feed.py b/tests/test_ocs_feed.py
index b6ec529..d5869ca 100644
--- a/tests/test_ocs_feed.py
+++ b/tests/test_ocs_feed.py
@@ -76,8 +76,7 @@ class TestPublishMessage:
             }
         }
 
-        with pytest.raises(TypeError):
-            test_feed.publish_message(test_message)
+        test_feed.publish_message(test_message)
 
     def test_bool_multi_sample_input(self):
         mock_agent = MagicMock()
@@ -91,6 +90,21 @@ class TestPublishMessage:
             }
         }
 
+        test_feed.publish_message(test_message)
+
+    def test_invalid_single_sample_input(self):
+        mock_agent = MagicMock()
+        test_feed = ocs_feed.Feed(mock_agent, 'test_feed', record=True)
+
+        test_message = {
+            'block_name': 'test',
+            'timestamps': time.time(),
+            'data': {
+                'key1': 1.,
+                'key2': None,
+            }
+        }
+
         with pytest.raises(TypeError):
             test_feed.publish_message(test_message)