-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Check root keys on pre-commit file (e.g.: fail_fast)
- Loading branch information
1 parent
8448fa4
commit 9470aed
Showing
7 changed files
with
161 additions
and
57 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
This file was deleted.
Oops, something went wrong.
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,91 @@ | ||
"""Pre-commit tests.""" | ||
from tests.helpers import ProjectMock | ||
|
||
|
||
def test_missing_pre_commit_config_yaml(request): | ||
"""Suggest initial contents for missing .pre-commit-config.yaml.""" | ||
project = ( | ||
ProjectMock(request) | ||
.style( | ||
''' | ||
[["pre-commit-config.yaml".repos]] | ||
repo = "local" | ||
hooks = """ | ||
- id: whatever | ||
any: valid | ||
yaml: here | ||
- id: blargh | ||
note: only the id is verified | ||
""" | ||
''' | ||
) | ||
.lint() | ||
) | ||
project.assert_errors_contain( | ||
"""NIP331 File: .pre-commit-config.yaml: Missing file. Suggested initial content: | ||
repos: | ||
- hooks: | ||
- any: valid | ||
id: whatever | ||
yaml: here | ||
- id: blargh | ||
note: only the id is verified | ||
repo: local | ||
""" | ||
) | ||
|
||
|
||
def test_root_values_on_missing_file(request): | ||
"""Test values on the root of the config file when it's missing.""" | ||
project = ( | ||
ProjectMock(request) | ||
.style( | ||
""" | ||
["pre-commit-config.yaml"] | ||
fail_fast = true | ||
whatever = "1" | ||
""" | ||
) | ||
.lint() | ||
) | ||
project.assert_errors_contain( | ||
"""NIP331 File: .pre-commit-config.yaml: Missing file. Suggested initial content: | ||
fail_fast: true | ||
whatever: '1' | ||
""" | ||
) | ||
|
||
|
||
def test_root_values_on_existing_file(request): | ||
"""Test values on the root of the config file when there is a file.""" | ||
project = ( | ||
ProjectMock(request) | ||
.style( | ||
""" | ||
["pre-commit-config.yaml"] | ||
fail_fast = true | ||
blabla = "what" | ||
something = true | ||
""" | ||
) | ||
.pre_commit( | ||
""" | ||
repos: | ||
- hooks: | ||
- id: whatever | ||
something: false | ||
""" | ||
) | ||
.lint() | ||
) | ||
project.assert_errors_contain( | ||
"""NIP338 File: .pre-commit-config.yaml: Missing keys: | ||
blabla: what | ||
fail_fast: true | ||
""" | ||
) | ||
project.assert_errors_contain( | ||
"""NIP339 File: .pre-commit-config.yaml: Expected value True in key, got False | ||
something: true | ||
""" | ||
) |
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,10 @@ | ||
"""pyproject.toml tests.""" | ||
from flake8_nitpick import PyProjectTomlChecker | ||
from tests.helpers import ProjectMock | ||
|
||
|
||
def test_missing_pyproject_toml(request): | ||
"""Suggest poetry init when pyproject.toml does not exist.""" | ||
assert ProjectMock(request, pyproject_toml=False).lint().errors == { | ||
f"NIP201 {PyProjectTomlChecker.file_name} does not exist. Run 'poetry init' to create one." | ||
} |