Skip to content

Commit

Permalink
fix(yaml): always use pure-Python ruamel.yaml
Browse files Browse the repository at this point in the history
Resolves #55.
  • Loading branch information
dbohdan committed Jan 10, 2025
1 parent d67f157 commit 396141a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/remarshal/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ def _decode_toml(input_data: bytes) -> Document:

def _decode_yaml(input_data: bytes) -> Document:
try:
yaml = ruamel.yaml.YAML(typ="safe")
yaml = ruamel.yaml.YAML(pure=True, typ="safe")
doc = yaml.load(input_data)

return cast(Document, doc)
Expand Down Expand Up @@ -742,7 +742,7 @@ def _encode_yaml(
style: YAMLStyle,
width: int,
) -> str:
yaml = ruamel.yaml.YAML()
yaml = ruamel.yaml.YAML(pure=True)
yaml.default_flow_style = False

yaml.default_style = style # type: ignore
Expand Down
1 change: 1 addition & 0 deletions tests/colon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"data":[{"src":{"url":"http://example.com"}}]}
2 changes: 2 additions & 0 deletions tests/colon.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
data:
- src: {url: http://example.com}
9 changes: 9 additions & 0 deletions tests/test_remarshal.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,15 @@ def test_yaml2toml_timestamp_key(self, convert_and_read) -> None:
reference = read_file("timestamp-key.toml")
assert output == reference

def test_yaml_colon(self, convert_and_read) -> None:
output = convert_and_read(
"colon.yaml",
"yaml",
"json",
)
reference = read_file("colon.json")
assert output == reference

def test_yaml_width_default(self, convert_and_read) -> None:
output = convert_and_read(
"long-line.json",
Expand Down

0 comments on commit 396141a

Please sign in to comment.