Skip to content

Commit

Permalink
Merge 7a8c795 into 1752835
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Feb 16, 2020
2 parents 1752835 + 7a8c795 commit e525da0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,7 @@
- Added a `YAML_LIBRARY` setting to control the underlying YAML library.
- Fixed ORM methods to handle relative file patterns.
- Updated the `@datafile` decorator to be able to be called without parentheses to act as `@dataclass`.
- Updated YAML serialization to preserve quotation marks in files.

# 0.6 (2020-01-25)

Expand Down
2 changes: 1 addition & 1 deletion datafiles/formats.py
Expand Up @@ -87,7 +87,7 @@ def deserialize(cls, file_object):
from ruamel import yaml

try:
return yaml.YAML(typ='rt').load(file_object) or {}
return yaml.round_trip_load(file_object, preserve_quotes=True) or {}
except NotImplementedError as e:
log.error(str(e))
return {}
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
@@ -1,7 +1,7 @@
[tool.poetry]

name = "datafiles"
version = "0.7b4"
version = "0.7b5"
description = "File-based ORM for dataclasses."

license = "MIT"
Expand Down
22 changes: 22 additions & 0 deletions tests/test_saving.py
Expand Up @@ -386,3 +386,25 @@ def with_comments_on_nested_lines(expect):
score: 4.0 # Nested line
"""
)

def with_quotations(expect):
sample = Sample(None, None, None, "42")

write(
'tmp/sample.yml',
"""
str_: "42"
""",
)

sample.datafile.load()
sample.datafile.save()

expect(read('tmp/sample.yml')) == dedent(
"""
str_: "42"
bool_: false
int_: 0
float_: 0.0
"""
)

0 comments on commit e525da0

Please sign in to comment.