Skip to content

Commit

Permalink
refactor: add json and yaml parse error handling
Browse files Browse the repository at this point in the history
Signed-off-by: paullongtan <paullongtan@gmail.com>
  • Loading branch information
paullongtan committed Jan 7, 2025
1 parent 42510ba commit 8a82a78
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions tests/flytekit/unit/cli/pyflyte/test_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,12 @@ def test_register_registrated_summary_json(mock_client, mock_remote):
["register", "--summary-format", "json", "core5"]
)
assert result.exit_code == 0
summary_data = json.loads(result.output)
try:
summary_data = json.loads(result.output)
except json.JSONDecodeError as e:
pytest.fail(f"Failed to parse registration summary JSON: {e}")
except Exception as e:
pytest.fail(f"Unexpected error while parsing registration summary: {e}")
assert isinstance(summary_data, list)
assert len(summary_data) > 0
for entry in summary_data:
Expand Down Expand Up @@ -225,7 +230,10 @@ def test_register_registrated_summary_yaml(mock_client, mock_remote):
["register", "--summary-format", "yaml", "core6"]
)
assert result.exit_code == 0
summary_data = yaml.safe_load(result.output)
try:
summary_data = yaml.safe_load(result.output)
except yaml.YAMLError as e:
pytest.fail(f"Failed to parse YAML output: {e}")
assert isinstance(summary_data, list)
assert len(summary_data) > 0
for entry in summary_data:
Expand Down

0 comments on commit 8a82a78

Please sign in to comment.