mirror of
https://github.com/ansible-collections/community.docker.git
synced 2026-07-29 11:55:04 +00:00
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:
@@ -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}):
|
||||
|
||||
Reference in New Issue
Block a user