Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pre_commit_hooks/sort_simple_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def main(argv: Sequence[str] | None = None) -> int:
retval = 0

for filename in args.filenames:
with open(filename, 'r+') as f:
with open(filename, 'r+', encoding='utf-8', newline='') as f:
lines = [line.rstrip() for line in f.readlines()]
new_lines = sort(lines)

Expand Down
12 changes: 12 additions & 0 deletions tests/sort_simple_yaml_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ def test_integration_good_bad_lines(tmpdir, bad_lines, good_lines, retval):
assert [line.rstrip() for line in f.readlines()] == good_lines


def test_non_ascii_content_roundtrip(tmpdir):
file_path = os.path.join(str(tmpdir), 'foo.yaml')

with open(file_path, 'w', encoding='utf-8') as f:
f.write('b: caf\u00e9\n\na: \u2603\n')

assert main([file_path]) == RETVAL_BAD

with open(file_path, encoding='utf-8') as f:
assert f.read() == 'a: \u2603\n\nb: caf\u00e9\n'


def test_parse_header():
lines = ['# some header', '# is here', '', 'this is not a header']
assert parse_block(lines, header=True) == ['# some header', '# is here']
Expand Down
Loading