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
13 changes: 13 additions & 0 deletions tests/usethis/_core/test_core_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,7 @@ def test_small_contracts_dropped(
"""
)

@pytest.mark.usefixtures("_vary_network_conn")
def test_cyclic_excluded(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
# Arrange
(tmp_path / ".importlinter").touch()
Expand Down Expand Up @@ -1053,6 +1054,7 @@ def test_cyclic_excluded(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
"""
)

@pytest.mark.usefixtures("_vary_network_conn")
def test_existing_ini_match(self, tmp_path: Path):
# Arrange
(tmp_path / ".importlinter").write_text(
Expand Down Expand Up @@ -1081,6 +1083,7 @@ def test_existing_ini_match(self, tmp_path: Path):
"""
)

@pytest.mark.usefixtures("_vary_network_conn")
def test_existing_ini_differs(self, tmp_path: Path):
# Arrange
(tmp_path / ".importlinter").write_text(
Expand Down Expand Up @@ -1109,6 +1112,7 @@ def test_existing_ini_differs(self, tmp_path: Path):
"""
)

@pytest.mark.usefixtures("_vary_network_conn")
def test_numbers_in_layer_names(self, tmp_path: Path):
# Arrange
(tmp_path / ".importlinter").touch()
Expand Down Expand Up @@ -1140,6 +1144,7 @@ def test_numbers_in_layer_names(self, tmp_path: Path):
"""
)

@pytest.mark.usefixtures("_vary_network_conn")
def test_nesting(self, tmp_path: Path):
# Arrange
(tmp_path / ".importlinter").touch()
Expand Down Expand Up @@ -1183,6 +1188,7 @@ def test_nesting(self, tmp_path: Path):
"""
)

@pytest.mark.usefixtures("_vary_network_conn")
def test_multiple_packages_with_nesting(self, tmp_path: Path):
# The logic here is that we want to have the minimum number of nesting
# levels required to reach the minimum number of modules which is 3.
Expand Down Expand Up @@ -1539,6 +1545,7 @@ def test_config(
)

class TestBitbucketIntegration:
@pytest.mark.usefixtures("_vary_network_conn")
def test_config_file(self, tmp_path: Path):
# Arrange
(tmp_path / "bitbucket-pipelines.yml").write_text("""\
Expand Down Expand Up @@ -1582,6 +1589,7 @@ def test_config_contents(self, tmp_path: Path):
"""
)

@pytest.mark.usefixtures("_vary_network_conn")
def test_successful_build(self, tmp_path: Path):
# Act
with change_cwd(tmp_path), files_manager():
Expand Down Expand Up @@ -2055,6 +2063,7 @@ def test_add_unsubsumed_tools(self, uv_init_repo_dir: Path):
assert "ruff" in contents

class TestMultipleIntegrations:
@pytest.mark.usefixtures("_vary_network_conn")
def test_hooks_run_all_tools_empty_repo(self, uv_env_dir: Path):
# Arrange
with change_cwd(uv_env_dir), files_manager():
Expand Down Expand Up @@ -2486,6 +2495,7 @@ def test_pyproject_without_ini_priority(self, uv_init_repo_dir: Path):
# Assert
assert (uv_init_repo_dir / "setup.cfg").read_text()

@pytest.mark.usefixtures("_vary_network_conn")
def test_pythonpath_needed(self, tmp_path: Path):
# https://github.com/usethis-python/usethis-python/issues/347

Expand Down Expand Up @@ -2917,6 +2927,7 @@ def test_pre_commit_first(self, uv_init_repo_dir: Path):
assert "ruff-format" in hook_names
assert "ruff" in hook_names

@pytest.mark.usefixtures("_vary_network_conn")
def test_creates_pyproject_toml(
self, tmp_path: Path, capfd: pytest.CaptureFixture[str]
):
Expand Down Expand Up @@ -3484,6 +3495,7 @@ def test_remove_only_linter_yaml_only(
)

class TestBitbucketIntegration:
@pytest.mark.usefixtures("_vary_network_conn")
def test_add_linter_only(self, tmp_path: Path):
# Arrange
(tmp_path / "bitbucket-pipelines.yml").write_text("""\
Expand All @@ -3500,6 +3512,7 @@ def test_add_linter_only(self, tmp_path: Path):
assert "ruff check" in contents
assert "ruff format" not in contents

@pytest.mark.usefixtures("_vary_network_conn")
def test_add_formatter_only(self, tmp_path: Path):
# Arrange
(tmp_path / "bitbucket-pipelines.yml").write_text("""\
Expand Down
2 changes: 2 additions & 0 deletions tests/usethis/_core/test_docstyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def test_pep257(self, tmp_path: Path):
"""
)

@pytest.mark.usefixtures("_vary_network_conn")
def test_pyproject_toml_numpy(self, tmp_path: Path):
# Also tests the case that ruff isn't used yet.

Expand Down Expand Up @@ -170,6 +171,7 @@ def test_leave_ok_config_alone(self, tmp_path: Path):
# Assert
assert contents == (tmp_path / "ruff.toml").read_text()

@pytest.mark.usefixtures("_vary_network_conn")
def test_adding_ruff_afterwards_allows_default_rules(self, tmp_path: Path):
# Arrange
(tmp_path / "ruff.toml").touch()
Expand Down
8 changes: 7 additions & 1 deletion tests/usethis/_interface/test_doc.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
from pathlib import Path

import pytest
from typer.testing import CliRunner

from usethis._app import app
from usethis._config import usethis_config
from usethis._config_file import files_manager
from usethis._integrations.uv.deps import Dependency, get_deps_from_group
from usethis._test import change_cwd


class TestDoc:
@pytest.mark.usefixtures("_vary_network_conn")
def test_dependencies_added(self, tmp_path: Path):
# Act
runner = CliRunner()
with change_cwd(tmp_path):
result = runner.invoke(app, ["doc"])
if not usethis_config.offline:
result = runner.invoke(app, ["doc"])
else:
result = runner.invoke(app, ["doc", "--offline"])

# Assert
assert result.exit_code == 0, result.output
Expand Down
14 changes: 12 additions & 2 deletions tests/usethis/_interface/test_docstyle.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from pathlib import Path

import pytest
from typer.testing import CliRunner

from usethis._app import app
from usethis._config import usethis_config
from usethis._core.enums.docstyle import DocStyleEnum
from usethis._interface.docstyle import docstyle
from usethis._test import change_cwd
Expand All @@ -27,6 +29,7 @@ def test_invalid_pyproject_toml(self, tmp_path: Path):
# Assert
assert result.exit_code == 1, result.output

@pytest.mark.usefixtures("_vary_network_conn")
def test_pyproject_toml_success(self, tmp_path: Path):
# https://github.com/usethis-python/usethis-python/issues/507

Expand All @@ -37,7 +40,10 @@ def test_pyproject_toml_success(self, tmp_path: Path):
# Act
with change_cwd(tmp_path):
runner = CliRunner()
result = runner.invoke(app, ["docstyle", "numpy"])
if not usethis_config.offline:
result = runner.invoke(app, ["docstyle", "numpy"])
else:
result = runner.invoke(app, ["docstyle", "numpy", "--offline"])

# Assert
assert result.exit_code == 0, result.output
Expand Down Expand Up @@ -81,6 +87,7 @@ def test_adding_to_existing_file(self, tmp_path: Path):
content = existing_pyproject_toml.read_text()
assert "[lint.pydocstyle]" not in content # Wrong section name

@pytest.mark.usefixtures("_vary_network_conn")
def test_default(self, tmp_path: Path):
# Arrange
default_pyproject_toml = tmp_path / "pyproject.toml"
Expand All @@ -89,7 +96,10 @@ def test_default(self, tmp_path: Path):
# Act
with change_cwd(tmp_path):
runner = CliRunner()
result = runner.invoke(app, ["docstyle"])
if not usethis_config.offline:
result = runner.invoke(app, ["docstyle"])
else:
result = runner.invoke(app, ["docstyle", "--offline"])

# Assert
assert result.exit_code == 0, result.output
Expand Down
8 changes: 7 additions & 1 deletion tests/usethis/_interface/test_format_.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
from pathlib import Path

import pytest
from typer.testing import CliRunner

from usethis._app import app
from usethis._config import usethis_config
from usethis._config_file import files_manager
from usethis._integrations.uv.deps import Dependency, get_deps_from_group
from usethis._test import change_cwd


class TestFormat:
@pytest.mark.usefixtures("_vary_network_conn")
def test_dependencies_added(self, tmp_path: Path):
# Act
runner = CliRunner()
with change_cwd(tmp_path):
result = runner.invoke(app, ["format"])
if not usethis_config.offline:
result = runner.invoke(app, ["format"])
else:
result = runner.invoke(app, ["format", "--offline"])

# Assert
assert result.exit_code == 0, result.output
Expand Down
14 changes: 11 additions & 3 deletions tests/usethis/_interface/test_init.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
from pathlib import Path

import pytest
from typer.testing import CliRunner

from usethis._app import app
from usethis._config import usethis_config
from usethis._integrations.pre_commit.hooks import get_hook_ids
from usethis._test import change_cwd


class TestInit:
@pytest.mark.usefixtures("_vary_network_conn")
def test_pre_commit_included(self, tmp_path: Path):
# Act
runner = CliRunner()
with change_cwd(tmp_path):
result = runner.invoke(
app, ["init", "--pre-commit"], catch_exceptions=False
)
if not usethis_config.offline:
result = runner.invoke(
app, ["init", "--pre-commit"], catch_exceptions=False
)
else:
result = runner.invoke(
app, ["init", "--pre-commit", "--offline"], catch_exceptions=False
)

# Assert
assert result.exit_code == 0, result.output
Expand Down
5 changes: 4 additions & 1 deletion tests/usethis/_interface/test_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ def test_runs(self, tmp_path: Path):
# Act
runner = CliRunner()
with change_cwd(tmp_path):
result = runner.invoke(app, ["deptry"])
if not usethis_config.offline:
result = runner.invoke(app, ["deptry"])
else:
result = runner.invoke(app, ["deptry", "--offline"])

# Assert
assert result.exit_code == 0, result.output
Expand Down
4 changes: 3 additions & 1 deletion tests/usethis/_tool/impl/test_codespell.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import pytest

from usethis._config import usethis_config
from usethis._config_file import files_manager
from usethis._integrations.ci.github.errors import GitHubTagError
from usethis._integrations.ci.github.tags import get_github_latest_tag
Expand Down Expand Up @@ -98,6 +99,7 @@ def test_both_devdep_and_pre_commit_used(
assert not err
assert out == ("☐ Run 'codespell' to run the Codespell spellchecker.\n")

@pytest.mark.usefixtures("_vary_network_conn")
def test_latest_version(self):
(config,) = CodespellTool().get_pre_commit_config().repo_configs
repo = config.repo
Expand All @@ -107,7 +109,7 @@ def test_latest_version(self):
owner="codespell-project", repo="codespell"
)
except GitHubTagError as err:
if os.getenv("CI"):
if os.getenv("CI") or usethis_config.offline:
pytest.skip(
"Failed to fetch GitHub tags (connection issues); skipping test"
)
Expand Down
4 changes: 3 additions & 1 deletion tests/usethis/_tool/impl/test_pyproject_fmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import pytest

from usethis._config import usethis_config
from usethis._config_file import files_manager
from usethis._integrations.ci.github.errors import GitHubTagError
from usethis._integrations.ci.github.tags import get_github_latest_tag
Expand All @@ -28,6 +29,7 @@ def test_uv_only(self, tmp_path: Path, capfd: pytest.CaptureFixture[str]):
"☐ Run 'uv run pyproject-fmt pyproject.toml' to run pyproject-fmt.\n"
)

@pytest.mark.usefixtures("_vary_network_conn")
def test_latest_version(self):
(config,) = PyprojectFmtTool().get_pre_commit_config().repo_configs
repo = config.repo
Expand All @@ -37,7 +39,7 @@ def test_latest_version(self):
owner="tox-dev", repo="pyproject-fmt"
)
except GitHubTagError as err:
if os.getenv("CI"):
if os.getenv("CI") or usethis_config.offline:
pytest.skip(
"Failed to fetch GitHub tags (connection issues); skipping test"
)
Expand Down
Loading