From 57b5c7994e4c996a19d4c3f55bbc5da40212087f Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 2 Jan 2024 12:24:04 +0100 Subject: [PATCH] test: fix all pylint issues --- test/mod/test_loop.py | 6 +++--- test/mod/test_meta.py | 1 - test/mod/test_monitor.py | 2 +- test/mod/test_mounts.py | 2 -- test/mod/test_objectstore.py | 1 - test/mod/test_testutil_fake_tree.py | 6 ++---- test/mod/test_testutil_imports.py | 4 ---- test/mod/test_util_fscache.py | 10 +++++----- test/mod/test_util_linux.py | 6 +++--- test/mod/test_util_mnt.py | 4 +--- test/run/test_devices.py | 1 - test/run/test_mount.py | 5 ++--- test/run/test_noop.py | 1 - test/run/test_sources.py | 3 +-- test/run/test_stages.py | 1 - 15 files changed, 18 insertions(+), 35 deletions(-) diff --git a/test/mod/test_loop.py b/test/mod/test_loop.py index 2bd3e6ce..fb052122 100644 --- a/test/mod/test_loop.py +++ b/test/mod/test_loop.py @@ -258,16 +258,16 @@ def test_on_close(tempdir): @patch("os.open", side_effect=FileNotFoundError) -def test_loop_handles_error_in_init(mocked_open): +def test_loop_handles_error_in_init(mocked_open): # pylint: disable=unused-argument with pytest.raises(FileNotFoundError): - lopo = loop.Loop(999) + loop.Loop(999) @pytest.mark.skipif(os.getuid() != 0, reason="root only") def test_loop_create_mknod(): # tmpdir must be /var/tmp because /tmp is usually mounted with "nodev" with TemporaryDirectory(dir="/var/tmp") as tmpdir: - with patch.object(loop, "DEV_PATH", new=tmpdir) as mocked_dev_path: + with patch.object(loop, "DEV_PATH", new=tmpdir): lopo = loop.Loop(1337) assert lopo.devname == "loop1337" assert pathlib.Path(f"{tmpdir}/loop1337").is_block_device() diff --git a/test/mod/test_meta.py b/test/mod/test_meta.py index 3f9bf98d..b7ced843 100644 --- a/test/mod/test_meta.py +++ b/test/mod/test_meta.py @@ -1,5 +1,4 @@ import os -from tempfile import TemporaryDirectory import pytest diff --git a/test/mod/test_monitor.py b/test/mod/test_monitor.py index 4aa44a87..53c978ee 100644 --- a/test/mod/test_monitor.py +++ b/test/mod/test_monitor.py @@ -33,7 +33,7 @@ class TapeMonitor(osbuild.monitor.BaseMonitor): def begin(self, pipeline: osbuild.Pipeline): self.counter["begin"] += 1 - def finish(self, result): + def finish(self, results): self.counter["finish"] += 1 self.output = self.logger.getvalue() diff --git a/test/mod/test_mounts.py b/test/mod/test_mounts.py index 416706a4..156b7663 100644 --- a/test/mod/test_mounts.py +++ b/test/mod/test_mounts.py @@ -1,7 +1,5 @@ from unittest.mock import Mock -import pytest - from osbuild.mounts import Mount from osbuild.meta import ModuleInfo diff --git a/test/mod/test_objectstore.py b/test/mod/test_objectstore.py index 94711601..510198d3 100644 --- a/test/mod/test_objectstore.py +++ b/test/mod/test_objectstore.py @@ -348,4 +348,3 @@ def test_object_export_preserves_override(tmp_path, object_store): assert expected_exported_path.exists() assert expected_exported_path.stat().st_uid == 0 assert expected_exported_path.stat().st_gid == 0 - diff --git a/test/mod/test_testutil_fake_tree.py b/test/mod/test_testutil_fake_tree.py index e929949c..7db609ab 100644 --- a/test/mod/test_testutil_fake_tree.py +++ b/test/mod/test_testutil_fake_tree.py @@ -3,8 +3,6 @@ # import os.path -import pytest - from osbuild.testutil import make_fake_input_tree @@ -15,6 +13,6 @@ def test_make_fake_tree(tmp_path): # pylint: disable=unused-argument }) assert os.path.isdir(fake_input_tree) assert os.path.exists(os.path.join(fake_input_tree, "fake-file-one")) - assert open(os.path.join(fake_input_tree, "fake-file-one")).read() == "Some content" + assert open(os.path.join(fake_input_tree, "fake-file-one"), encoding="utf8").read() == "Some content" assert os.path.exists(os.path.join(fake_input_tree, "second/fake-file-two")) - assert open(os.path.join(fake_input_tree, "second/fake-file-two")).read() == "Second content" + assert open(os.path.join(fake_input_tree, "second/fake-file-two"), encoding="utf").read() == "Second content" diff --git a/test/mod/test_testutil_imports.py b/test/mod/test_testutil_imports.py index 8b8e9a06..c4f75852 100644 --- a/test/mod/test_testutil_imports.py +++ b/test/mod/test_testutil_imports.py @@ -1,10 +1,6 @@ # # Tests for the 'osbuild.util.testutil' module. # -import os.path -import tempfile - -import pytest from osbuild.testutil.imports import import_module_from_path diff --git a/test/mod/test_util_fscache.py b/test/mod/test_util_fscache.py index d7428493..3045f0d9 100644 --- a/test/mod/test_util_fscache.py +++ b/test/mod/test_util_fscache.py @@ -66,9 +66,9 @@ def test_calculate_space(tmpdir): os.makedirs(os.path.join(test_dir, "dir")) assert fscache.FsCache._calculate_space(test_dir) == du(test_dir) - with open(os.path.join(test_dir, "sparse-file"), "w") as f: + with open(os.path.join(test_dir, "sparse-file"), "wb") as f: f.truncate(10*1024*1024) - f.write("I'm not an empty file") + f.write(b"I'm not an empty file") assert fscache.FsCache._calculate_space(test_dir) == du(test_dir) @@ -429,9 +429,9 @@ def test_cache_load_updates_last_used(tmpdir): cache = fscache.FsCache("osbuild-test-appid", tmpdir) with cache: cache.info = cache.info._replace(maximum_size=1024*1024) - with cache.store("foo") as rpath: + with cache.store("foo"): pass - with cache.load("foo") as rpath: + with cache.load("foo"): pass load_time1 = cache._last_used("foo") # would be nice to have a helper for this in cache @@ -440,7 +440,7 @@ def test_cache_load_updates_last_used(tmpdir): mtime1 = os.stat(cache._path(obj_lock_path)).st_mtime assert load_time1 > 0 sleep_for_fs() - with cache.load("foo") as rpath: + with cache.load("foo"): pass # load time is updated load_time2 = cache._last_used("foo") diff --git a/test/mod/test_util_linux.py b/test/mod/test_util_linux.py index b098bf66..65d1427c 100644 --- a/test/mod/test_util_linux.py +++ b/test/mod/test_util_linux.py @@ -252,10 +252,10 @@ def test_libc_futimens_errcheck(): def test_libc_futimes_works(tmpdir): libc = linux.Libc.default() stamp_file = os.path.join(tmpdir, "foo") - with open(stamp_file, "w") as fp: - fp.write("meep") + with open(stamp_file, "wb") as fp: + fp.write(b"meep") mtime1 = os.stat(stamp_file).st_mtime - with open(stamp_file, "w") as fp: + with open(stamp_file, "wb") as fp: libc.futimens(fp.fileno(), ctypes.byref(linux.c_timespec_times2( atime=linux.c_timespec(tv_sec=3, tv_nsec=300*1000*1000), mtime=linux.c_timespec(tv_sec=0, tv_nsec=libc.UTIME_OMIT), diff --git a/test/mod/test_util_mnt.py b/test/mod/test_util_mnt.py index becbdc66..435eccc4 100644 --- a/test/mod/test_util_mnt.py +++ b/test/mod/test_util_mnt.py @@ -1,5 +1,4 @@ import os -import subprocess import pytest @@ -25,7 +24,7 @@ def test_mount_guard_failure_msg(tmp_path): # This needs a proper refactor so that FileSystemMountService just uses # a common mount helper. class FakeFileSystemMountService(FileSystemMountService): - def __init__(self, args=None): + def __init__(self, args=None): # pylint: disable=super-init-not-called # override __init__ to make it testable pass def translate_options(self, options): @@ -45,4 +44,3 @@ def test_osbuild_mount_failure_msg(tmp_path): } mnt_service.mount(args) assert "special device /dev/invalid-src does not exist" in str(e.value) - diff --git a/test/run/test_devices.py b/test/run/test_devices.py index d0b10b3a..a3538700 100755 --- a/test/run/test_devices.py +++ b/test/run/test_devices.py @@ -5,7 +5,6 @@ # import os -import tempfile import pytest diff --git a/test/run/test_mount.py b/test/run/test_mount.py index 3c30dec4..cebf52a7 100755 --- a/test/run/test_mount.py +++ b/test/run/test_mount.py @@ -212,10 +212,10 @@ def test_mount_with_partition(tmp_path): opts = {} # mount both partitions for i in range(1,3): - mount = mounts.Mount( + mount_opts = mounts.Mount( name=f"name-{i}", info=ext4_mod_info, device=dev, partition=i, target=f"/mnt-{i}", options=opts) - mntmgr.mount(mount) + mntmgr.mount(mount_opts) # check that the both mounts actually happend output = subprocess.check_output( @@ -227,4 +227,3 @@ def test_mount_with_partition(tmp_path): chld = lsblk_info["blockdevices"][0]["children"] assert chld[0]["mountpoints"] == [f"{mnt_base}/mnt-1"] assert chld[1]["mountpoints"] == [f"{mnt_base}/mnt-2"] - diff --git a/test/run/test_noop.py b/test/run/test_noop.py index da66498e..fb92a123 100644 --- a/test/run/test_noop.py +++ b/test/run/test_noop.py @@ -3,7 +3,6 @@ # import json -import tempfile import pytest diff --git a/test/run/test_sources.py b/test/run/test_sources.py index a539da76..0f95a7b0 100644 --- a/test/run/test_sources.py +++ b/test/run/test_sources.py @@ -9,7 +9,6 @@ import json import os import socketserver import subprocess -import tempfile import threading import pytest @@ -66,7 +65,7 @@ def can_setup_netns() -> bool: try: with netns(): return True - except BaseException: # pylint: disable=bare-except + except BaseException: # pylint: disable=broad-exception-caught return False diff --git a/test/run/test_stages.py b/test/run/test_stages.py index 26859c36..1e944392 100644 --- a/test/run/test_stages.py +++ b/test/run/test_stages.py @@ -4,7 +4,6 @@ import contextlib import difflib -import functools import glob import json import os