Skip to content

Commit

Permalink
Fixing the function signature of send_signal in _TestingPebbleClient (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
weiiwang01 committed Apr 24, 2023
1 parent a8717ea commit 734e12d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions ops/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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(
Expand Down
12 changes: 6 additions & 6 deletions test/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 734e12d

Please sign in to comment.