Skip to content

Commit

Permalink
rollback raise changes
Browse files Browse the repository at this point in the history
  • Loading branch information
stan-dot committed Jun 3, 2024
1 parent 9408dc8 commit 94a7b05
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
18 changes: 8 additions & 10 deletions src/blueapi/cli/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json
import logging
import sys
from collections import deque
from functools import wraps
from pathlib import Path
Expand Down Expand Up @@ -46,8 +45,7 @@ def main(ctx: click.Context, config: Path | None | tuple[Path, ...]) -> None:
if path.exists():
config_loader.use_values_from_yaml(path)
else:
print(f"Cannot find file: {path}")
sys.exit(1)
raise FileNotFoundError(f"Cannot find file: {path}")

ctx.ensure_object(dict)
loaded_config: ApplicationConfig = config_loader.load()
Expand Down Expand Up @@ -110,7 +108,6 @@ def wrapper(*args, **kwargs):
func(*args, **kwargs)
except ConnectionError:
print("Failed to establish connection to FastAPI server.")
return

return wrapper

Expand Down Expand Up @@ -144,8 +141,7 @@ def listen_to_events(obj: dict) -> None:
StompMessagingTemplate.autoconfigured(config.stomp)
)
else:
print("Message bus needs to be configured")
sys.exit(1)
raise RuntimeError("Message bus needs to be configured")

def on_event(
context: MessageContext,
Expand Down Expand Up @@ -186,8 +182,9 @@ def run_plan(
if config.stomp is not None:
_message_template = StompMessagingTemplate.autoconfigured(config.stomp)
else:
pprint("ERROR: Cannot run plans without Stomp configuration to track progress")
return
raise RuntimeError(
"Cannot run plans without Stomp configuration to track progress"
)
event_bus_client = EventBusClient(_message_template)
finished_event: deque[WorkerEvent] = deque()

Expand Down Expand Up @@ -280,7 +277,7 @@ def stop(obj: dict) -> None:
"""

client: BlueapiRestClient = obj["rest_client"]
print(client.cancel_current_task(state=WorkerState.STOPPING))
pprint(client.cancel_current_task(state=WorkerState.STOPPING))


@controller.command(name="env")
Expand Down Expand Up @@ -311,7 +308,8 @@ def env(obj: dict, reload: bool | None) -> None:
print(deserialized)

except BlueskyRemoteError:
sys.stderr.write("Failed to reload the environment")
pprint("Failed to reload the environment")
quit("Exiting the environment inspection")

# Initialize a variable to keep track of the environment status
environment_initialized = False
Expand Down
11 changes: 6 additions & 5 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ def test_get_plans_and_devices(
def test_invalid_config_path_handling(runner: CliRunner):
# test what happens if you pass an invalid config file...
result = runner.invoke(main, ["-c", "non_existent.yaml"])
assert result.output == "Cannot find file: non_existent.yaml\n"
assert result.exit_code == 1


Expand Down Expand Up @@ -168,16 +167,18 @@ def test_config_passed_down_to_command_children(

def test_invalid_stomp_config_for_listener(runner: CliRunner):
result = runner.invoke(main, ["controller", "listen"])
assert result.exit_code == 1
assert result.output == "Message bus needs to be configured\n"
assert (
isinstance(result.exception, RuntimeError)
and str(result.exception) == "Message bus needs to be configured"
)


def test_cannot_run_plans_without_stomp_config(runner: CliRunner):
result = runner.invoke(main, ["controller", "run", "sleep", '{"time": 5}'])
assert result.exit_code == 1
assert (
"Cannot run plans without Stomp configuration to track progress"
in result.output
isinstance(result.exception, RuntimeError)
and str(result.exception) == "Message bus needs to be configured"
)


Expand Down

0 comments on commit 94a7b05

Please sign in to comment.