Skip to content

Commit

Permalink
Fix issue creating SMuRF controller client list for single controller (
Browse files Browse the repository at this point in the history
…#155)

* Create test for create utils when a single smurf is online

* Create SMuRF client list for case when only one controller online
  • Loading branch information
BrianJKoopman authored May 24, 2024
1 parent b25c507 commit 617d4ce
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/sorunlib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,12 @@ def create_clients(config=None, sorunlib_config=None, test_mode=False):
hwp_client = _try_client(hwp_id)
clients['hwp'] = hwp_client

# Always create smurf client list, even if empty
smurf_clients = [_try_client(x) for x in smurf_ids]
if isinstance(smurf_ids, str):
# when only a single SMuRF controller online
smurf_clients = [smurf_ids]
else:
# create smurf client list, even if empty
smurf_clients = [_try_client(x) for x in smurf_ids]
clients['smurf'] = smurf_clients

clients['wiregrid'] = _create_wiregrid_clients(
Expand Down
33 changes: 32 additions & 1 deletion tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,33 @@ def mock_client(*args, **kwargs):
'stop_and_clear': 1},
'agent_class': 'ACUAgent',
'agent_address': 'observatory.acu-sat1'}}}

mock_registry_client = create_mock_ocsclient(reg_session)

reg_session_single_smurf = {'session_id': 0,
'op_name': 'main',
'op_code': 3,
'status': 'running',
'success': None,
'start_time': 1669919099.7585046,
'end_time': None,
'data': {
'observatory.smurf-file-emulator-5': {
'expired': False,
'time_expired': None,
'last_updated': 1669935108.8366735,
'op_codes': {
'uxm_setup': 1,
'uxm_relock': 1,
'take_iv': 1,
'take_bias_steps': 1,
'take_bgmap': 1,
'bias_dets': 1,
'take_noise': 1,
'stream': 1},
'agent_class': 'SmurfFileEmulator',
'agent_address': 'observatory.smurf-file-emulator-5'}}}
mock_registry_client_single_smurf = create_mock_ocsclient(reg_session_single_smurf)


class NoAgentClient:
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -187,6 +211,13 @@ def test_create_clients_test_mode():
assert 'wiregrid' in clients


@patch('sorunlib.util.OCSClient', mock_registry_client_single_smurf)
def test_create_clients_test_mode_single_smurf():
clients = util.create_clients(test_mode=True)
assert 'smurf' in clients
assert len(clients['smurf']) == 1


@patch('sorunlib.util.OCSClient', mock_registry_client)
def test__create_clients_minimal_config():
clients = util.create_clients(sorunlib_config='./data/minimal_config.yaml')
Expand Down

0 comments on commit 617d4ce

Please sign in to comment.