diff --git a/src/sorunlib/util.py b/src/sorunlib/util.py index 3564b57..b30033f 100644 --- a/src/sorunlib/util.py +++ b/src/sorunlib/util.py @@ -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( diff --git a/tests/test_util.py b/tests/test_util.py index b012d5c..67c6211 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -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): @@ -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')