Skip to content

Commit

Permalink
Merge pull request #269 from simonsobs/koopman/bool-support
Browse files Browse the repository at this point in the history
Add boolean support to feeds
  • Loading branch information
BrianJKoopman committed May 26, 2022
2 parents bc67d61 + 8098f8f commit f2433e5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions ocs/ocs_feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,25 +248,23 @@ def verify_message_data_type(value):
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" +
f"types: {invalid_types}")

# 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}")
Expand Down
18 changes: 16 additions & 2 deletions tests/test_ocs_feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ def test_bool_single_sample_input(self):
}
}

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()
Expand All @@ -91,6 +90,21 @@ def test_bool_multi_sample_input(self):
}
}

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)

Expand Down

0 comments on commit f2433e5

Please sign in to comment.