Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the function signature of send_signal in _TestingPebbleClient #926

Merged
merged 2 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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