Skip to content

Commit

Permalink
bf: fix yaml output
Browse files Browse the repository at this point in the history
The issue is that PyYAML is dumping OrderedDict objects with their Python-specific tags.
To get plain YAML output, we convert them to regular dicts before dumping.
  • Loading branch information
asmacdo committed Feb 4, 2025
1 parent fdd036c commit 3c4dcaf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/con_duct/suite/ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ def ls(args: argparse.Namespace) -> int:
elif args.format == "json_pp":
print(json.dumps(output_rows, indent=2))
elif args.format == "yaml":
print(yaml.dump(output_rows, default_flow_style=False))
plain_rows = [dict(row) for row in output_rows]
print(yaml.dump(plain_rows, default_flow_style=False))
else:
raise RuntimeError(
f"Unexpected format encountered: {args.format}. This should have been caught by argparse.",
Expand Down
18 changes: 8 additions & 10 deletions test/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import unittest
from unittest.mock import MagicMock, mock_open, patch
import pytest

# import yaml
import yaml
from con_duct.suite import main, plot, pprint_json
from con_duct.suite.ls import MINIMUM_SCHEMA_VERSION, ls

Expand Down Expand Up @@ -228,11 +227,10 @@ def test_ls_json_pp_output(self) -> None:
for entry in parsed:
self.assertIn("prefix", entry)

# def test_ls_yaml_output(self) -> None:
# """Test YAML output format."""
# result = self._run_ls("file*", "yaml")
# import ipdb; ipdb.set_trace()
# parsed = yaml.safe_load(result)
# self.assertEqual(len(parsed), 2)
# for entry in parsed:
# self.assertIn("prefix", entry)
def test_ls_yaml_output(self) -> None:
"""Test YAML output format."""
result = self._run_ls("file*", "yaml")
parsed = yaml.safe_load(result)
self.assertEqual(len(parsed), 2)
for entry in parsed:
self.assertIn("prefix", entry)

0 comments on commit 3c4dcaf

Please sign in to comment.