Skip to content
Open
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-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ repos:
# https://docs.openstack.org/bashate/latest/man/bashate.html#options
args: [-i, E006]
- repo: https://github.com/commitizen-tools/commitizen
rev: v4.13.0
rev: v4.12.1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pre-commit autoupdate PRs typically bump hook versions, but this change downgrades commitizen from v4.13.0 to v4.12.1. Can you confirm the downgrade is intentional (e.g., due to a regression/incompatibility in v4.13.0), since it may reintroduce previously fixed behavior?

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

hooks:
- id: commitizen
stages: [commit-msg]
12 changes: 4 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ def project_default(tmp_path):
from tests.helpers import ProjectMock, tomlstring # noqa: PLC0415

nitpick_style = Path(__file__).parent.parent / NITPICK_STYLE_TOML
return ProjectMock(tmp_path).pyproject_toml(
f"""
return ProjectMock(tmp_path).pyproject_toml(f"""
[tool.nitpick]
style = {tomlstring(nitpick_style)}
"""
)
""")


@pytest.fixture
Expand All @@ -52,16 +50,14 @@ def project_remote(request, tmp_path):
mocked_response.add(mocked_response.GET, remote_url, dedent(remote_style), status=200)

project = ProjectMock(tmp_path)
project.pyproject_toml(
f"""
project.pyproject_toml(f"""
[tool.nitpick]
style = {tomlstring(remote_url)}
{tool_nitpick}

[tool.black]
line-length = 100
"""
).remote(mocked_response, remote_url)
""").remote(mocked_response, remote_url)
yield project


Expand Down
18 changes: 6 additions & 12 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,21 @@ def test_simple_error(tmp_path: Path) -> None:
"""A simple error on the CLI."""
project = (
ProjectMock(tmp_path)
.style(
"""
.style("""
["pyproject.toml".tool.black]
line-length = 100
"""
)
.pyproject_toml(
"""
""")
.pyproject_toml("""
[tool.blabla]
something = 22
"""
)
""")
)

project.cli_run(
f"""
project.cli_run(f"""
{project.root_dir / "pyproject.toml"!s}:1: NIP318 has missing values:
[tool.black]
line-length = 100
"""
)
""")


def test_missing_style_and_suggest_option(tmp_path: Path) -> None:
Expand Down
88 changes: 28 additions & 60 deletions tests/test_ini.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@ def test_setup_cfg_has_no_configuration(tmp_path):

def test_comma_separated_keys_on_style_file(tmp_path):
"""Comma separated keys on the style file."""
ProjectMock(tmp_path).style(
f"""
ProjectMock(tmp_path).style(f"""
[nitpick.files."{PYTHON_SETUP_CFG}"]
comma_separated_values = ["food.eat", "food.drink"]

["{PYTHON_SETUP_CFG}".food]
eat = "salt,ham,eggs"
drink = "water,bier,wine"
"""
).setup_cfg(
""").setup_cfg(
"""
[food]
eat = spam,eggs,cheese
Expand Down Expand Up @@ -76,8 +74,7 @@ def test_suggest_initial_contents(tmp_path):
end_of_line = lf
insert_final_newline = True
"""
ProjectMock(tmp_path).style(
f"""
ProjectMock(tmp_path).style(f"""
["{PYTHON_SETUP_CFG}".mypy]
ignore_missing_imports = true

Expand All @@ -94,8 +91,7 @@ def test_suggest_initial_contents(tmp_path):
["{EDITOR_CONFIG}"."*"]
end_of_line = "lf"
insert_final_newline = true
"""
).api_check_then_fix(
""").api_check_then_fix(
Fuss(
True,
PYTHON_SETUP_CFG,
Expand Down Expand Up @@ -124,12 +120,10 @@ def test_suggest_initial_contents(tmp_path):

def test_missing_sections(tmp_path):
"""Test missing sections."""
ProjectMock(tmp_path).setup_cfg(
"""
ProjectMock(tmp_path).setup_cfg("""
[mypy]
ignore_missing_imports = true
"""
).style(
""").style(
f"""
["{PYTHON_SETUP_CFG}".mypy]
ignore_missing_imports = true
Expand Down Expand Up @@ -171,8 +165,7 @@ def test_missing_sections(tmp_path):

def test_missing_different_values(tmp_path):
"""Test different and missing keys/values."""
ProjectMock(tmp_path).setup_cfg(
"""
ProjectMock(tmp_path).setup_cfg("""
[mypy]
# Line comment with hash (inline comments are not supported)
ignore_missing_imports = true
Expand All @@ -183,8 +176,7 @@ def test_missing_different_values(tmp_path):
[flake8]
; Line comment with semicolon
xxx = "aaa"
"""
).style(
""").style(
f"""
["{PYTHON_SETUP_CFG}".mypy]
ignore_missing_imports = true
Expand Down Expand Up @@ -308,8 +300,7 @@ def test_missing_different_values_editorconfig_with_root(tmp_path, datadir):

def test_invalid_configuration_comma_separated_values(tmp_path):
"""Test an invalid configuration for comma_separated_values."""
ProjectMock(tmp_path).style(
f"""
ProjectMock(tmp_path).style(f"""
["{PYTHON_SETUP_CFG}".flake8]
max-line-length = 85
max-complexity = 12
Expand All @@ -318,8 +309,7 @@ def test_invalid_configuration_comma_separated_values(tmp_path):

[nitpick.files."{PYTHON_SETUP_CFG}"]
comma_separated_values = ["flake8.ignore", "flake8.exclude"]
"""
).api_check().assert_violations(
""").api_check().assert_violations(
Fuss(
False,
PYTHON_SETUP_CFG,
Expand All @@ -338,12 +328,10 @@ def test_invalid_configuration_comma_separated_values(tmp_path):

def test_invalid_section_dot_fields(tmp_path):
"""Test invalid section/field pairs."""
ProjectMock(tmp_path).style(
f"""
ProjectMock(tmp_path).style(f"""
[nitpick.files."{PYTHON_SETUP_CFG}"]
comma_separated_values = ["no_dot", "multiple.dots.here", ".filed_only", "section_only."]
"""
).setup_cfg("").api_check().assert_violations(
""").setup_cfg("").api_check().assert_violations(
Fuss(
False,
"nitpick-style.toml",
Expand All @@ -361,17 +349,15 @@ def test_invalid_section_dot_fields(tmp_path):

def test_invalid_sections_comma_separated_values(tmp_path):
"""Test invalid sections on comma_separated_values."""
ProjectMock(tmp_path).style(
f"""
ProjectMock(tmp_path).style(f"""
["{PYTHON_SETUP_CFG}".flake8]
ignore = "W503,E203,FI58,PT003,C408"
exclude = "venv*,**/migrations/"
per-file-ignores = "tests/**.py:FI18,setup.py:FI18"

[nitpick.files."{PYTHON_SETUP_CFG}"]
comma_separated_values = ["flake8.ignore", "flake8.exclude", "falek8.per-file-ignores", "aaa.invalid-section"]
"""
).setup_cfg(
""").setup_cfg(
"""
[flake8]
exclude = venv*,**/migrations/
Expand All @@ -385,12 +371,10 @@ def test_invalid_sections_comma_separated_values(tmp_path):

def test_multiline_comment(tmp_path, datadir):
"""Test file with multiline comments should not raise a configparser.ParsingError."""
ProjectMock(tmp_path).style(
f"""
ProjectMock(tmp_path).style(f"""
["{PYTHON_SETUP_CFG}".flake8]
new = "value"
"""
).setup_cfg(datadir / "3-actual-setup.cfg").api_fix().assert_violations(
""").setup_cfg(datadir / "3-actual-setup.cfg").api_fix().assert_violations(
Fuss(
True,
PYTHON_SETUP_CFG,
Expand All @@ -401,9 +385,7 @@ def test_multiline_comment(tmp_path, datadir):
new = value
""",
)
).assert_file_contents(
PYTHON_SETUP_CFG, datadir / "3-expected-setup.cfg"
)
).assert_file_contents(PYTHON_SETUP_CFG, datadir / "3-expected-setup.cfg")


def test_duplicated_option(tmp_path):
Expand All @@ -414,22 +396,18 @@ def test_duplicated_option(tmp_path):
easy = as sunday morning
"""
project = ProjectMock(tmp_path)
project.style(
f"""
project.style(f"""
["{PYTHON_SETUP_CFG}".abc]
hard = "as a rock"
"""
).setup_cfg(original_file).api_fix().assert_violations(
""").setup_cfg(original_file).api_fix().assert_violations(
Fuss(
False,
PYTHON_SETUP_CFG,
Violations.PARSING_ERROR.code,
f": parsing error (DuplicateOptionError): While reading from {project.path_for(PYTHON_SETUP_CFG)!r} "
f"[line 3]: option 'easy' in section 'abc' already exists",
)
).assert_file_contents(
PYTHON_SETUP_CFG, original_file
)
).assert_file_contents(PYTHON_SETUP_CFG, original_file)


@mock.patch.object(ConfigUpdater, "update_file")
Expand All @@ -441,12 +419,10 @@ def test_simulate_parsing_error_when_saving(update_file, tmp_path):
[flake8]
existing = value
"""
ProjectMock(tmp_path).style(
f"""
ProjectMock(tmp_path).style(f"""
["{PYTHON_SETUP_CFG}".flake8]
new = "value"
"""
).setup_cfg(original_file).api_fix().assert_violations(
""").setup_cfg(original_file).api_fix().assert_violations(
Fuss(
True,
PYTHON_SETUP_CFG,
Expand All @@ -463,9 +439,7 @@ def test_simulate_parsing_error_when_saving(update_file, tmp_path):
Violations.PARSING_ERROR.code,
": parsing error (ParsingError): Source contains parsing errors: 'simulating a captured error'",
),
).assert_file_contents(
PYTHON_SETUP_CFG, original_file
)
).assert_file_contents(PYTHON_SETUP_CFG, original_file)


def test_generic_ini_with_missing_header(tmp_path):
Expand All @@ -478,13 +452,11 @@ def test_generic_ini_with_missing_header(tmp_path):
your_string = value
"""
project = ProjectMock(tmp_path)
project.save_file("generic.ini", expected_generic_ini).style(
"""
project.save_file("generic.ini", expected_generic_ini).style("""
["generic.ini".your-section]
your_string = "value"
your_number = 100
"""
).api_check_then_fix(
""").api_check_then_fix(
Fuss(
False,
"generic.ini",
Expand All @@ -493,9 +465,7 @@ def test_generic_ini_with_missing_header(tmp_path):
f"file: {project.path_for('generic.ini')!r}, line: 1\n"
"'this_key_is_invalid = for a generic .ini (it should always have a section)\\n'",
)
).assert_file_contents(
"generic.ini", expected_generic_ini
)
).assert_file_contents("generic.ini", expected_generic_ini)


def test_add_options_with_multiple_trailing_spaces(tmp_path):
Expand All @@ -504,14 +474,12 @@ def test_add_options_with_multiple_trailing_spaces(tmp_path):
This is a regression test for the NotAttachedError bug that occurred when
trying to detach multiple consecutive Space blocks.
"""
ProjectMock(tmp_path).setup_cfg(
"""
ProjectMock(tmp_path).setup_cfg("""
[flake8]
max-line-length = 100


"""
).style(
""").style(
f"""
["{PYTHON_SETUP_CFG}".flake8]
max-line-length = 100
Expand Down
Loading
Loading