diff --git a/ops/testing.py b/ops/testing.py index d7672d837..cdde47020 100755 --- a/ops/testing.py +++ b/ops/testing.py @@ -2537,7 +2537,7 @@ def remove_path(self, path: str, *, recursive: bool = False): def exec(self, command, **kwargs): # type:ignore raise NotImplementedError(self.exec) # type:ignore - def send_signal(self, sig: Union[int, str], *service_names: str): + def send_signal(self, sig: Union[int, str], service_names: Iterable[str]): if not service_names: raise TypeError('send_signal expected at least 1 service name, got 0') self._check_connection() @@ -2564,7 +2564,8 @@ def send_signal(self, sig: Union[int, str], *service_names: str): signal.Signals[sig] except KeyError: # conform with the real pebble api - message = f'cannot send signal to "{service_names[0]}": invalid signal name "{sig}"' + first_service = next(iter(service_names)) + message = f'cannot send signal to "{first_service}": invalid signal name "{sig}"' body = {'type': 'error', 'status-code': 500, 'status': 'Internal Server Error', 'result': {'message': message}} raise pebble.APIError( diff --git a/test/test_testing.py b/test/test_testing.py index 17d97e1ae..7cd12194f 100644 --- a/test/test_testing.py +++ b/test/test_testing.py @@ -3833,27 +3833,27 @@ def test_send_signal(self): # Foo is now started, but Bar is not # Send a valid signal to a running service - client.send_signal("SIGINT", "foo") + client.send_signal("SIGINT", ("foo",)) # Send a valid signal but omit service name with self.assertRaises(TypeError): - client.send_signal("SIGINT") + client.send_signal("SIGINT", tuple()) # Send an invalid signal to a running service with self.assertRaises(pebble.APIError): - client.send_signal("sigint", "foo") + client.send_signal("sigint", ("foo",)) # Send a valid signal to a stopped service with self.assertRaises(pebble.APIError): - client.send_signal("SIGINT", "bar") + client.send_signal("SIGINT", ("bar",)) # Send a valid signal to a non-existing service with self.assertRaises(pebble.APIError): - client.send_signal("SIGINT", "baz") + client.send_signal("SIGINT", ("baz",)) # Send a valid signal to a multiple services, one of which is not running with self.assertRaises(pebble.APIError): - client.send_signal("SIGINT", "foo", "bar") + client.send_signal("SIGINT", ("foo", "bar",)) # For testing file-ops of the pebble client. This is refactored into a