FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

sort-simple-yaml: read and write YAML files as UTF-8 by 0xacee · Pull Request #1276 · pre-commit/pre-commit-hooks · GitHub

Repository navigation

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

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion pre_commit_hooks/sort_simple_yaml.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL