Skip to content
Merged
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
3 changes: 1 addition & 2 deletions src/usethis/_core/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,7 @@ def use_ruff(
tool.add_configs()

if linter:
tool.select_rules(rule_config.get_all_selected())
tool.ignore_rules(rule_config.get_all_ignored())
tool.apply_rule_config(rule_config)
if PreCommitTool().is_used():
tool.add_pre_commit_config()
else:
Expand Down
4 changes: 1 addition & 3 deletions src/usethis/_tool/impl/ruff.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,7 @@ def apply_rule_config(self, rule_config: RuleConfig) -> None:
"""
self.select_rules(rule_config.get_all_selected())
self.ignore_rules(rule_config.get_all_ignored())
self.ignore_rules_in_glob(
rule_config.tests_unmanaged_ignored, glob="*/tests/**"
)
self.ignore_rules_in_glob(rule_config.tests_unmanaged_ignored, glob="tests/**")

def remove_rule_config(self, rule_config: RuleConfig) -> None:
"""Remove the Ruff rules associated with a rule config from the project.
Expand Down
31 changes: 30 additions & 1 deletion tests/usethis/_core/test_core_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -1369,10 +1369,24 @@ def test_inp_rules_not_selected_for_tests_dir(self, tmp_path: Path):
select = ["INP"]

[lint.per-file-ignores]
"*/tests/**" = ["INP"]
"tests/**" = ["INP"]
"""
)

@pytest.mark.usefixtures("_vary_network_conn")
def test_ruff_passes(self, tmp_path: Path):
with change_cwd(tmp_path), files_manager():
# Arrange
use_ruff()
use_pytest()

# Act
use_import_linter()

# Assert
with change_cwd(tmp_path), files_manager():
call_uv_subprocess(["run", "ruff", "check", "."], change_toml=False)

class TestRemove:
def test_config_file(self, uv_init_repo_dir: Path):
# Arrange
Expand Down Expand Up @@ -2419,6 +2433,21 @@ def test_foo():
# Assert (that this doesn't raise an error)
call_uv_subprocess(["run", "pytest"], change_toml=False)

@pytest.mark.usefixtures("_vary_network_conn")
def test_import_linter_inp_rules(self, tmp_path: Path):
with change_cwd(tmp_path), files_manager():
# Arrange
use_import_linter()

# Act
(tmp_path / "ruff.toml").touch()
use_ruff()

# Assert
with change_cwd(tmp_path), files_manager():
contents = (tmp_path / "ruff.toml").read_text()
assert """"tests/**" = ["INP"]""" in contents

class TestRemove:
class TestRuffIntegration:
def test_deselected(self, uv_init_dir: Path):
Expand Down
14 changes: 14 additions & 0 deletions tests/usethis/_interface/test_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,20 @@ def test_how(self, tmp_path: Path):
"""
)

@pytest.mark.usefixtures("_vary_network_conn")
def test_passes_using_all_tools(self, uv_init_dir: Path):
"""Test that pytest runs with all tools installed."""
with change_cwd(uv_init_dir):
# Arrange, Act
for cmd in ALL_TOOL_COMMANDS:
if not usethis_config.offline:
call_subprocess(["usethis", "tool", cmd])
else:
call_subprocess(["usethis", "tool", cmd, "--offline"])

# Act, Assert
call_uv_subprocess(["run", "ruff", "check", "."], change_toml=False)


class TestPytest:
@pytest.mark.usefixtures("_vary_network_conn")
Expand Down
Loading