-
Notifications
You must be signed in to change notification settings - Fork 664
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tool to generate formatting fixtures (#1936)
Co-authored-by: Sorin Sbarnea <ssbarnea@redhat.com>
- Loading branch information
1 parent
8e62160
commit 5584461
Showing
10 changed files
with
189 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Fixtures used in tests.""" |
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# preamble/header comment | ||
--- | ||
# initial comment | ||
- foo: bar | ||
|
||
- baz: # over indented | ||
- qwerty | ||
- foobar | ||
animals: # under indented | ||
- crow | ||
- pig | ||
- giraffe | ||
|
||
- nothing: null # null | ||
|
||
- octal: | ||
- 0o123 # YAML 1.2 octal | ||
- 0123 # YAML 1.1 octal | ||
|
This file contains 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# preamble/header comment | ||
--- | ||
# initial comment | ||
- foo: bar | ||
|
||
- baz: # over indented | ||
- qwerty | ||
- foobar | ||
animals: # under indented | ||
- crow | ||
- pig | ||
- giraffe | ||
|
||
- nothing: null # null | ||
|
||
- octal: | ||
- 0o123 # YAML 1.2 octal | ||
- 0123 # YAML 1.1 octal | ||
|
This file contains 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
# ^ too many newlines before | ||
foo: bar # This is a comment has extra spaces preceding it | ||
|
||
fruits: # unindented sequence: | ||
- apple | ||
- orange | ||
vegetables: # indented sequence: | ||
- onion | ||
- carrot | ||
|
||
quoting: | ||
- "that should have double quotes" | ||
- "that should remain in single quotes" | ||
- 'a string with " inside' | ||
# next line has some undesired trailing spaces: | ||
- "a string with ' inside" | ||
- can't be sure! | ||
# next line should be converted to use double quotes: | ||
- ["foo", "bar"] | ||
|
||
inline-dictionary: | ||
- { foo: bar } # should add some spacing between curly braces and content | ||
|
||
# YAML 1.1 Boolean-hell: https://yaml.org/type/bool.html | ||
booleans-true: | ||
preferred: true # YAML 1.2 compatible! | ||
answer-1.1: YES | ||
canonical-1.1: y | ||
canonical-upper-1.1: Y | ||
logical-1.1: True | ||
option-1.1: on | ||
booleans-false: | ||
preferred: false # YAML 1.2 compatible! | ||
answer-1.1: NO | ||
canonical-1.1: n | ||
canonical-upper-1.1: N | ||
logical-1.1: False | ||
option-1.1: off | ||
|
||
# ^ double newline should be removed | ||
overly-indented-vault-value: !vault | | ||
$ANSIBLE_VAULT;1.1;AES256 | ||
123466303630313 | ||
# this file also has 3 newlines at end-of-file instead of one | ||
|
This file contains 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# preamble/header comment | ||
--- | ||
# initial comment | ||
- foo: bar | ||
|
||
- baz: # over indented | ||
- qwerty | ||
- foobar | ||
animals: # under indented | ||
- crow | ||
- pig | ||
- giraffe | ||
|
||
- nothing: null # null | ||
|
||
- octal: | ||
- 0o123 # YAML 1.2 octal | ||
- 0123 # YAML 1.1 octal | ||
|
This file contains 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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"""Test that re-generates formatting fixtures.""" | ||
import shutil | ||
import subprocess | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
|
||
@pytest.mark.formatting_fixtures() | ||
def test_regenerate_formatting_fixtures() -> None: | ||
"""Re-generate formatting fixtures with prettier and internal formatter. | ||
Pass ``--regenerate-formatting-fixtures`` to run this and skip all other tests. | ||
This is a "test" because once fixtures are regenerated, | ||
we run prettier again to make sure it does not change files formatted | ||
with our internal formatting code. | ||
""" | ||
print("Looking for prettier on PATH...") | ||
subprocess.check_call(["which", "prettier"]) | ||
|
||
fixtures_dir = Path("test/fixtures/") | ||
fixtures_dir_before = fixtures_dir / "formatting-before" | ||
fixtures_dir_prettier = fixtures_dir / "formatting-prettier" | ||
fixtures_dir_after = fixtures_dir / "formatting-after" | ||
|
||
fixtures_dir_prettier.mkdir(exist_ok=True) | ||
fixtures_dir_after.mkdir(exist_ok=True) | ||
|
||
print("\nCopying before fixtures...") | ||
for fixture in fixtures_dir_before.glob("fmt-[0-9].yml"): | ||
shutil.copy(str(fixture), str(fixtures_dir_prettier / fixture.name)) | ||
shutil.copy(str(fixture), str(fixtures_dir_after / fixture.name)) | ||
|
||
print("\nWriting fixtures with prettier...") | ||
subprocess.check_call(["prettier", "-w", str(fixtures_dir_prettier)]) | ||
# NB: pre-commit end-of-file-fixer can also modify files. | ||
|
||
# prepare ruamel.yaml fixtures (diff in next PR will show how it compares). | ||
subprocess.check_call(["prettier", "-w", str(fixtures_dir_after)]) |