Address some pylint issues (#1155)

* Address cyclic-import.

* Address redefined-builtin.

* Address redefined-argument-from-local.

* Address many redefined-outer-name.

* Address pointless-string-statement.

* No longer needed due to separate bugfix.

* Address useless-return.

* Address possibly-used-before-assignment.

* Add TODOs.

* Address super-init-not-called.

* Address function-redefined.

* Address unspecified-encoding.

* Clean up more imports.
This commit is contained in:
Felix Fontein
2025-10-09 20:11:36 +02:00
committed by GitHub
parent db09affaea
commit a3efa26e2e
42 changed files with 348 additions and 323 deletions
@@ -619,29 +619,29 @@ class DisableSocketTest(unittest.TestCase):
def test_disable_socket_timeout(self):
"""Test that the timeout is disabled on a generic socket object."""
socket = self.DummySocket()
the_socket = self.DummySocket()
self.client._disable_socket_timeout(socket)
self.client._disable_socket_timeout(the_socket)
assert socket.timeout is None
assert the_socket.timeout is None
def test_disable_socket_timeout2(self):
"""Test that the timeouts are disabled on a generic socket object
and it's _sock object if present."""
socket = self.DummySocket()
socket._sock = self.DummySocket()
the_socket = self.DummySocket()
the_socket._sock = self.DummySocket()
self.client._disable_socket_timeout(socket)
self.client._disable_socket_timeout(the_socket)
assert socket.timeout is None
assert socket._sock.timeout is None
assert the_socket.timeout is None
assert the_socket._sock.timeout is None
def test_disable_socket_timout_non_blocking(self):
"""Test that a non-blocking socket does not get set to blocking."""
socket = self.DummySocket()
socket._sock = self.DummySocket(0.0)
the_socket = self.DummySocket()
the_socket._sock = self.DummySocket(0.0)
self.client._disable_socket_timeout(socket)
self.client._disable_socket_timeout(the_socket)
assert socket.timeout is None
assert socket._sock.timeout == 0.0
assert the_socket.timeout is None
assert the_socket._sock.timeout == 0.0
@@ -300,7 +300,7 @@ class LoadConfigTest(unittest.TestCase):
self.addCleanup(shutil.rmtree, folder)
cfg_path = os.path.join(folder, ".dockercfg")
auth_ = base64.b64encode(b"sakuya:izayoi").decode("ascii")
with open(cfg_path, "w") as f:
with open(cfg_path, "wt", encoding="utf-8") as f:
f.write(f"auth = {auth_}\n")
f.write("email = sakuya@scarlet.net")
@@ -319,7 +319,7 @@ class LoadConfigTest(unittest.TestCase):
cfg_path = os.path.join(folder, ".dockercfg")
auth_ = base64.b64encode(b"sakuya:izayoi").decode("ascii")
email = "sakuya@scarlet.net"
with open(cfg_path, "w") as f:
with open(cfg_path, "wt", encoding="utf-8") as f:
json.dump({auth.INDEX_URL: {"auth": auth_, "email": email}}, f)
cfg = auth.load_config(cfg_path)
assert auth.resolve_authconfig(cfg) is not None
@@ -336,7 +336,7 @@ class LoadConfigTest(unittest.TestCase):
cfg_path = os.path.join(folder, "config.json")
auth_ = base64.b64encode(b"sakuya:izayoi").decode("ascii")
email = "sakuya@scarlet.net"
with open(cfg_path, "w") as f:
with open(cfg_path, "wt", encoding="utf-8") as f:
json.dump({"auths": {auth.INDEX_URL: {"auth": auth_, "email": email}}}, f)
cfg = auth.load_config(cfg_path)
assert auth.resolve_authconfig(cfg) is not None
@@ -355,7 +355,7 @@ class LoadConfigTest(unittest.TestCase):
auth_ = base64.b64encode(b"sakuya:izayoi").decode("ascii")
config = {registry: {"auth": f"{auth_}", "email": "sakuya@scarlet.net"}}
with open(dockercfg_path, "w") as f:
with open(dockercfg_path, "wt", encoding="utf-8") as f:
json.dump(config, f)
cfg = auth.load_config(dockercfg_path).auths
@@ -376,7 +376,7 @@ class LoadConfigTest(unittest.TestCase):
auth_ = base64.b64encode(b"sakuya:izayoi").decode("ascii")
config = {registry: {"auth": f"{auth_}", "email": "sakuya@scarlet.net"}}
with open(dockercfg_path, "w") as f:
with open(dockercfg_path, "wt", encoding="utf-8") as f:
json.dump(config, f)
with mock.patch.dict(os.environ, {"DOCKER_CONFIG": folder}):
@@ -400,7 +400,7 @@ class LoadConfigTest(unittest.TestCase):
"auths": {registry: {"auth": f"{auth_}", "email": "sakuya@scarlet.net"}}
}
with open(dockercfg_path, "w") as f:
with open(dockercfg_path, "wt", encoding="utf-8") as f:
json.dump(config, f)
with mock.patch.dict(os.environ, {"DOCKER_CONFIG": folder}):
@@ -423,7 +423,7 @@ class LoadConfigTest(unittest.TestCase):
"auths": {registry: {"auth": f"{auth_}", "email": "sakuya@scarlet.net"}}
}
with open(dockercfg_path, "w") as f:
with open(dockercfg_path, "wt", encoding="utf-8") as f:
json.dump(config, f)
with mock.patch.dict(os.environ, {"DOCKER_CONFIG": folder}):
@@ -440,7 +440,7 @@ class LoadConfigTest(unittest.TestCase):
self.addCleanup(shutil.rmtree, folder)
dockercfg_path = os.path.join(folder, "config.json")
config = {"detachKeys": "ctrl-q, ctrl-u, ctrl-i"}
with open(dockercfg_path, "w") as f:
with open(dockercfg_path, "wt", encoding="utf-8") as f:
json.dump(config, f)
cfg = auth.load_config(dockercfg_path)
@@ -451,7 +451,7 @@ class LoadConfigTest(unittest.TestCase):
self.addCleanup(shutil.rmtree, folder)
dockercfg_path = os.path.join(folder, "config.json")
config = {"auths": {"scarlet.net": {"sakuya": "izayoi"}}}
with open(dockercfg_path, "w") as f:
with open(dockercfg_path, "wt", encoding="utf-8") as f:
json.dump(config, f)
cfg = auth.load_config(dockercfg_path)
@@ -465,7 +465,7 @@ class LoadConfigTest(unittest.TestCase):
dockercfg_path = os.path.join(folder, "config.json")
auth_entry = encode_auth({"username": "sakuya"}).decode("ascii")
config = {"auths": {registry: {"auth": auth_entry, "identitytoken": token}}}
with open(dockercfg_path, "w") as f:
with open(dockercfg_path, "wt", encoding="utf-8") as f:
json.dump(config, f)
cfg = auth.load_config(dockercfg_path)
@@ -803,7 +803,7 @@ class CredstoreTest(unittest.TestCase):
class InMemoryStore(Store):
def __init__(self, *args, **kwargs):
def __init__(self, *args, **kwargs): # pylint: disable=super-init-not-called
self.__store = {}
def get(self, server):
@@ -123,8 +123,8 @@ class APIErrorTest(unittest.TestCase):
except requests.exceptions.HTTPError as e:
try:
create_api_error_from_http_exception(e)
except APIError as e:
err = e
except APIError as e2:
err = e2
assert err.is_server_error() is True
@@ -37,7 +37,7 @@ def make_tree(dirs, files):
os.makedirs(os.path.join(base, path))
for path in files:
with open(os.path.join(base, path), "w") as f:
with open(os.path.join(base, path), "wt", encoding="utf-8") as f:
f.write("content")
return base
@@ -440,7 +440,7 @@ class TarTest(unittest.TestCase):
base = tempfile.mkdtemp()
full_path = os.path.join(base, "foo")
self.addCleanup(shutil.rmtree, base)
with open(full_path, "w") as f:
with open(full_path, "wt", encoding="utf-8") as f:
f.write("content")
os.chmod(full_path, 0o222)
with pytest.raises(IOError) as ei:
@@ -452,7 +452,7 @@ class TarTest(unittest.TestCase):
def test_tar_with_file_symlinks(self):
base = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, base)
with open(os.path.join(base, "foo"), "w") as f:
with open(os.path.join(base, "foo"), "wt", encoding="utf-8") as f:
f.write("content")
os.makedirs(os.path.join(base, "bar"))
os.symlink("../foo", os.path.join(base, "bar/foo"))
@@ -500,7 +500,7 @@ class TarTest(unittest.TestCase):
base = tempfile.mkdtemp()
filename = os.path.join(base, "th.txt")
self.addCleanup(shutil.rmtree, base)
with open(filename, "w") as f:
with open(filename, "wt", encoding="utf-8") as f:
f.write("Invisible Full Moon")
os.utime(filename, (12345, -3600.0))
with tar(base) as archive:
@@ -96,7 +96,7 @@ class LoadConfigTest(unittest.TestCase):
"HttpHeaders": {"Name": "Spike", "Surname": "Spiegel"},
}
with open(dockercfg_path, "w") as f:
with open(dockercfg_path, "wt", encoding="utf-8") as f:
json.dump(config_data, f)
cfg = config.load_general_config(dockercfg_path)
@@ -108,7 +108,7 @@ class LoadConfigTest(unittest.TestCase):
self.addCleanup(shutil.rmtree, folder)
dockercfg_path = os.path.join(folder, "config.json")
config_data = {"detachKeys": "ctrl-q, ctrl-u, ctrl-i"}
with open(dockercfg_path, "w") as f:
with open(dockercfg_path, "wt", encoding="utf-8") as f:
json.dump(config_data, f)
cfg = config.load_general_config(dockercfg_path)
@@ -119,7 +119,7 @@ class LoadConfigTest(unittest.TestCase):
self.addCleanup(shutil.rmtree, folder)
dockercfg_path = os.path.join(folder, "config.json")
config_data = {"detachKeys": "ctrl-q, ctrl-u, ctrl-i"}
with open(dockercfg_path, "w") as f:
with open(dockercfg_path, "wt", encoding="utf-8") as f:
json.dump(config_data, f)
with mock.patch.dict(os.environ, {"DOCKER_CONFIG": folder}):
@@ -15,7 +15,7 @@ from ansible_collections.community.docker.plugins.modules.docker_container_copy_
@pytest.mark.parametrize(
"input, expected",
"value, expected",
[
("0777", 0o777),
("777", 0o777),
@@ -32,13 +32,13 @@ from ansible_collections.community.docker.plugins.modules.docker_container_copy_
("-1", -1),
],
)
def test_parse_string(input, expected):
assert parse_modern(input) == expected
assert parse_octal_string_only(input) == expected
def test_parse_string(value, expected):
assert parse_modern(value) == expected
assert parse_octal_string_only(value) == expected
@pytest.mark.parametrize(
"input",
"value",
[
0o777,
0o755,
@@ -47,14 +47,14 @@ def test_parse_string(input, expected):
123456789012345678901234567890123456789012345678901234567890,
],
)
def test_parse_int(input):
assert parse_modern(input) == input
with pytest.raises(TypeError, match=f"^must be an octal string, got {input}L?$"):
parse_octal_string_only(input)
def test_parse_int(value):
assert parse_modern(value) == value
with pytest.raises(TypeError, match=f"^must be an octal string, got {value}L?$"):
parse_octal_string_only(value)
@pytest.mark.parametrize(
"input",
"value",
[
1.0,
755.5,
@@ -62,23 +62,23 @@ def test_parse_int(input):
{},
],
)
def test_parse_bad_type(input):
def test_parse_bad_type(value):
with pytest.raises(TypeError, match="^must be an octal string or an integer, got "):
parse_modern(input)
parse_modern(value)
with pytest.raises(TypeError, match="^must be an octal string, got "):
parse_octal_string_only(input)
parse_octal_string_only(value)
@pytest.mark.parametrize(
"input",
"value",
[
"foo",
"8",
"9",
],
)
def test_parse_bad_value(input):
def test_parse_bad_value(value):
with pytest.raises(ValueError):
parse_modern(input)
parse_modern(value)
with pytest.raises(ValueError):
parse_octal_string_only(input)
parse_octal_string_only(value)
@@ -14,7 +14,7 @@ from ansible_collections.community.docker.plugins.modules.docker_image_build imp
@pytest.mark.parametrize(
"input, expected",
"value, expected",
[
("", ""),
(" ", '" "'),
@@ -23,5 +23,5 @@ from ansible_collections.community.docker.plugins.modules.docker_image_build imp
('\rhello, "hi" !\n', '"\rhello, ""hi"" !\n"'),
],
)
def test__quote_csv(input, expected):
assert _quote_csv(input) == expected
def test__quote_csv(value, expected):
assert _quote_csv(value) == expected