Skip to content

Commit

Permalink
style(lint): fix ruff 0.6.0 linting errors (#624)
Browse files Browse the repository at this point in the history
Also bumps the pre-commit config to use rolling ruff versions
  • Loading branch information
lengau authored Aug 21, 2024
1 parent afa0fad commit 823622d
Show file tree
Hide file tree
Showing 32 changed files with 103 additions and 105 deletions.
4 changes: 1 addition & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ repos:
- id: check-toml
- id: fix-byte-order-marker
- id: mixed-line-ending
- repo: https://github.com/charliermarsh/ruff-pre-commit
# renovate: datasource=pypi;depName=ruff
rev: "v0.1.7"
- repo: https://github.com/astral-sh/ruff-pre-commit
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def is_installed_dangerously(snap_name: str) -> bool:
return get_host_snap_info(snap_name)["revision"].startswith("x")


@pytest.fixture()
@pytest.fixture
def home_tmp_path():
"""Provide a temporary directory located in user's home directory.
Expand All @@ -74,7 +74,7 @@ def home_tmp_path():
yield pathlib.Path(temp_dir)


@pytest.fixture()
@pytest.fixture
def instance_name():
"""Provide a random name for an instance to launch."""
return generate_instance_name()
Expand Down Expand Up @@ -105,7 +105,7 @@ def installed_lxd():
pytest.skip("lxd not installed, skipped")


@pytest.fixture()
@pytest.fixture
def uninstalled_lxd():
"""Uninstall Lxd prior to test, if environment allows it.
Expand Down Expand Up @@ -150,7 +150,7 @@ def installed_multipass():
pytest.skip("multipass not installed, skipped")


@pytest.fixture()
@pytest.fixture
def uninstalled_multipass():
"""Uninstall Multipass prior to test, if environment allows it.
Expand Down Expand Up @@ -180,7 +180,7 @@ def uninstalled_multipass():
multipass.install()


@pytest.fixture()
@pytest.fixture
def core22_lxd_instance(installed_lxd, instance_name):
"""Fully configured buildd-based core22 LXD instance."""
base_configuration = ubuntu.BuilddBase(alias=ubuntu.BuilddBaseAlias.JAMMY)
Expand Down Expand Up @@ -237,7 +237,7 @@ def _installed_snap(snap_name, *, try_path: Optional[pathlib.Path] = None):
return _installed_snap


@pytest.fixture()
@pytest.fixture
def dangerously_installed_snap(tmpdir):
"""Fixture to provide contextmanager for a dangerously installed snap.
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/lxd/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def installed_lxd_required(installed_lxd):
"""All LXD integration tests required LXD to be installed."""


@pytest.fixture()
@pytest.mark.with_sudo()
@pytest.fixture
@pytest.mark.with_sudo
def installed_lxd_without_init(uninstalled_lxd):
"""Ensure lxd is installed, but not initialized.
Expand Down Expand Up @@ -134,18 +134,18 @@ def tmp_instance(
assert instance_name not in lxc.list_names(project=project, remote=remote)


@pytest.fixture()
@pytest.fixture
def lxc():
return LXC()


@pytest.fixture()
@pytest.fixture
def project_name():
"""Create temporary LXD project and assert expected properties."""
return "ptest-" + "".join(random.choices(string.ascii_uppercase, k=4))


@pytest.fixture()
@pytest.fixture
def project(lxc, project_name):
"""Create temporary LXD project and assert expected properties."""
lxc_project.create_with_default_profile(lxc=lxc, project=project_name)
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/lxd/test_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _base_instance(
return _base_instance


@pytest.fixture()
@pytest.fixture
def base_configuration(tmp_path):
"""Returns a simple base configuration."""
return ubuntu.BuilddBase(
Expand All @@ -64,7 +64,7 @@ def base_configuration(tmp_path):
)


@pytest.fixture()
@pytest.fixture
def core22_instance(instance_name):
"""Yields a minimally setup core22 instance.
Expand Down Expand Up @@ -97,7 +97,7 @@ def core22_instance(instance_name):
instance.delete()


@pytest.fixture()
@pytest.fixture
def get_instance_and_base_instance(
base_configuration, get_base_instance, instance_name
):
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/lxd/test_lxc.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from . import conftest


@pytest.fixture()
@pytest.fixture
def instance(instance_name, session_project):
with conftest.tmp_instance(
name=instance_name, project=session_project
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/lxd/test_lxd.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from craft_providers.lxd import LXD


@pytest.fixture()
@pytest.fixture
def lxd():
return LXD()

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/lxd/test_lxd_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
]


@pytest.fixture()
@pytest.fixture
def instance(instance_name, project):
with conftest.tmp_instance(
name=instance_name,
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/multipass/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
from craft_providers.bases import ubuntu


@pytest.fixture()
@pytest.fixture
def simple_file(home_tmp_path):
"""Create a file in the home directory (accessible by Multipass)."""
file = home_tmp_path / "src.txt"
file.write_text("this is a test")
return file


@pytest.mark.smoketest()
@pytest.mark.smoketest
def test_smoketest(instance_name, home_tmp_path):
"""Launch an instance and run some basic tasks."""

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/multipass/test_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
pytestmark = [pytest.mark.xdist_group("multipass_launch_tests")]


@pytest.fixture()
@pytest.fixture
def core22_instance(instance_name):
"""Yields a minimally setup core22 instance.
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/multipass/test_multipass.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
from . import conftest


@pytest.fixture()
@pytest.fixture
def instance(instance_name):
with conftest.tmp_instance(
instance_name=instance_name,
) as tmp_instance:
yield tmp_instance


@pytest.fixture()
@pytest.fixture
def multipass():
return Multipass()

Expand Down Expand Up @@ -181,7 +181,7 @@ def test_transfer_destination_io(instance, multipass, home_tmp_path):
assert out_path.read_text() == "this is a test"


@pytest.mark.slow()
@pytest.mark.slow
def test_transfer_destination_io_large(instance, multipass, home_tmp_path):
test_file = home_tmp_path / "test.txt"

Expand Down Expand Up @@ -224,7 +224,7 @@ def test_transfer_source_io(instance, multipass):
assert proc.stdout == b"this is a test"


@pytest.mark.slow()
@pytest.mark.slow
def test_transfer_source_io_large(instance, multipass, home_tmp_path):
test_file = home_tmp_path / "test.txt"

Expand Down
4 changes: 2 additions & 2 deletions tests/integration/multipass/test_multipass_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
pytestmark = pytest.mark.flaky(reruns=3, reruns_delay=2)


@pytest.fixture()
@pytest.fixture
def instance(instance_name):
with conftest.tmp_instance(
instance_name=instance_name,
Expand All @@ -46,7 +46,7 @@ def reusable_instance(reusable_instance_name):
yield MultipassInstance(name=tmp_instance)


@pytest.fixture()
@pytest.fixture
def simple_file(home_tmp_path):
"""Create a file in the home directory (accessible by Multipass)."""
file = home_tmp_path / "src.txt"
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/multipass/test_multipass_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_create_environment(installed_multipass, instance_name):
ALIASES.remove(BuilddBaseAlias.XENIAL)


@pytest.mark.slow()
@pytest.mark.slow
@pytest.mark.parametrize("alias", ALIASES)
def test_launched_environment(alias, installed_multipass, instance_name, tmp_path):
"""Verify `launched_environment()` creates and starts an instance then stops
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/actions/test_snap_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from logassert import Exact # type: ignore


@pytest.fixture()
@pytest.fixture
def mock_requests():
"""Mock requests_unixsocket."""
with mock.patch(
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/bases/test_almalinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,30 @@
from tests.unit.conftest import DEFAULT_FAKE_CMD


@pytest.fixture()
@pytest.fixture
def mock_load(mocker):
return mocker.patch(
"craft_providers.instance_config.InstanceConfiguration.load",
return_value=InstanceConfiguration(compatibility_tag="almalinux-base-v7"),
)


@pytest.fixture()
@pytest.fixture
def fake_filesystem(fs):
return fs


@pytest.fixture()
@pytest.fixture
def mock_install_from_store(mocker):
return mocker.patch("craft_providers.actions.snap_installer.install_from_store")


@pytest.fixture()
@pytest.fixture
def mock_inject_from_host(mocker):
return mocker.patch("craft_providers.actions.snap_installer.inject_from_host")


@pytest.fixture()
@pytest.fixture
def mock_get_os_release(mocker):
return mocker.patch.object(
almalinux.AlmaLinuxBase,
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/bases/test_centos_7.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,30 @@
from tests.unit.conftest import DEFAULT_FAKE_CMD


@pytest.fixture()
@pytest.fixture
def mock_load(mocker):
return mocker.patch(
"craft_providers.instance_config.InstanceConfiguration.load",
return_value=InstanceConfiguration(compatibility_tag="centos-base-v7"),
)


@pytest.fixture()
@pytest.fixture
def fake_filesystem(fs):
return fs


@pytest.fixture()
@pytest.fixture
def mock_install_from_store(mocker):
return mocker.patch("craft_providers.actions.snap_installer.install_from_store")


@pytest.fixture()
@pytest.fixture
def mock_inject_from_host(mocker):
return mocker.patch("craft_providers.actions.snap_installer.inject_from_host")


@pytest.fixture()
@pytest.fixture
def mock_get_os_release(mocker):
return mocker.patch.object(
centos.CentOSBase,
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/bases/test_instance_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from pydantic import ValidationError


@pytest.fixture()
@pytest.fixture
def default_config_data():
return {
"compatibility_tag": "tag-foo-v2",
Expand All @@ -38,13 +38,13 @@ def default_config_data():
}


@pytest.fixture()
@pytest.fixture
def mock_executor():
executor_mock = mock.Mock(spec=Executor)
return executor_mock


@pytest.fixture()
@pytest.fixture
def config_fixture(fake_home_temporary_file):
"""Creates an instance config file containing data passed to the fixture."""

Expand Down
10 changes: 5 additions & 5 deletions tests/unit/bases/test_ubuntu_buildd.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,30 @@
from tests.unit.conftest import DEFAULT_FAKE_CMD


@pytest.fixture()
@pytest.fixture
def mock_load(mocker):
return mocker.patch(
"craft_providers.instance_config.InstanceConfiguration.load",
return_value=InstanceConfiguration(compatibility_tag="buildd-base-v7"),
)


@pytest.fixture()
@pytest.fixture
def fake_filesystem(fs):
return fs


@pytest.fixture()
@pytest.fixture
def mock_install_from_store(mocker):
return mocker.patch("craft_providers.actions.snap_installer.install_from_store")


@pytest.fixture()
@pytest.fixture
def mock_inject_from_host(mocker):
return mocker.patch("craft_providers.actions.snap_installer.inject_from_host")


@pytest.fixture()
@pytest.fixture
def mock_get_os_release(mocker):
return mocker.patch.object(
ubuntu.BuilddBase,
Expand Down
Loading

0 comments on commit 823622d

Please sign in to comment.