Remove explicit utf-8 from decode() as it's default (#2237)

This commit is contained in:
Ayaz Salikhov
2025-02-22 14:15:53 +00:00
committed by GitHub
parent 8fc97cb36b
commit 4ee4f2b906
8 changed files with 16 additions and 16 deletions

View File

@@ -48,7 +48,7 @@ class DockerRunner:
) -> str: ) -> str:
LOGGER.info(f"Running cmd: '{cmd}' on container: {container}") LOGGER.info(f"Running cmd: '{cmd}' on container: {container}")
out = container.exec_run(cmd) out = container.exec_run(cmd)
result = out.output.decode("utf-8").rstrip() result = out.output.decode().rstrip()
assert isinstance(result, str) assert isinstance(result, str)
if print_result: if print_result:
LOGGER.info(f"Command result: {result}") LOGGER.info(f"Command result: {result}")

View File

@@ -21,7 +21,7 @@ def test_cli_args(container: TrackedContainer, http_client: requests.Session) ->
) )
resp = http_client.get(f"http://localhost:{host_port}") resp = http_client.get(f"http://localhost:{host_port}")
resp.raise_for_status() resp.raise_for_status()
logs = running_container.logs().decode("utf-8") logs = running_container.logs().decode()
LOGGER.debug(logs) LOGGER.debug(logs)
assert "ERROR" not in logs assert "ERROR" not in logs
warnings = TrackedContainer.get_warnings(logs) warnings = TrackedContainer.get_warnings(logs)
@@ -48,7 +48,7 @@ def test_nb_user_change(container: TrackedContainer) -> None:
command = f'stat -c "%F %U %G" /home/{nb_user}/.jupyter' command = f'stat -c "%F %U %G" /home/{nb_user}/.jupyter'
expected_output = f"directory {nb_user} users" expected_output = f"directory {nb_user} users"
cmd = running_container.exec_run(command, workdir=f"/home/{nb_user}") cmd = running_container.exec_run(command, workdir=f"/home/{nb_user}")
output = cmd.output.decode("utf-8").strip("\n") output = cmd.output.decode().strip("\n")
assert ( assert (
output == expected_output output == expected_output
), f"Hidden folder .jupyter was not copied properly to {nb_user} home folder. stat: {output}, expected {expected_output}" ), f"Hidden folder .jupyter was not copied properly to {nb_user} home folder. stat: {output}, expected {expected_output}"
@@ -74,7 +74,7 @@ def test_unsigned_ssl(
resp = http_client.get(f"https://localhost:{host_port}", verify=False) resp = http_client.get(f"https://localhost:{host_port}", verify=False)
resp.raise_for_status() resp.raise_for_status()
assert "login_submit" in resp.text assert "login_submit" in resp.text
logs = running_container.logs().decode("utf-8") logs = running_container.logs().decode()
assert "ERROR" not in logs assert "ERROR" not in logs
warnings = TrackedContainer.get_warnings(logs) warnings = TrackedContainer.get_warnings(logs)
assert not warnings assert not warnings
@@ -109,7 +109,7 @@ def test_custom_internal_port(
) )
resp = http_client.get(f"http://localhost:{host_port}") resp = http_client.get(f"http://localhost:{host_port}")
resp.raise_for_status() resp.raise_for_status()
logs = running_container.logs().decode("utf-8") logs = running_container.logs().decode()
LOGGER.debug(logs) LOGGER.debug(logs)
assert "ERROR" not in logs assert "ERROR" not in logs
warnings = TrackedContainer.get_warnings(logs) warnings = TrackedContainer.get_warnings(logs)

View File

@@ -49,7 +49,7 @@ def test_start_notebook(
) )
# sleeping some time to let the server start # sleeping some time to let the server start
time.sleep(2) time.sleep(2)
logs = running_container.logs().decode("utf-8") logs = running_container.logs().decode()
LOGGER.debug(logs) LOGGER.debug(logs)
# checking that the expected command is launched # checking that the expected command is launched
assert ( assert (
@@ -79,7 +79,7 @@ def test_tini_entrypoint(
running_container = container.run_detached(tty=True) running_container = container.run_detached(tty=True)
# Select the PID 1 and get the corresponding command # Select the PID 1 and get the corresponding command
cmd = running_container.exec_run(f"ps -p {pid} -o comm=") cmd = running_container.exec_run(f"ps -p {pid} -o comm=")
output = cmd.output.decode("utf-8").strip("\n") output = cmd.output.decode().strip("\n")
assert "ERROR" not in output assert "ERROR" not in output
assert "WARNING" not in output assert "WARNING" not in output
assert output == command, f"{command} shall be launched as pid {pid}, got {output}" assert output == command, f"{command} shall be launched as pid {pid}, got {output}"

View File

@@ -115,7 +115,7 @@ def _check_import_package(
"""Generic function executing a command""" """Generic function executing a command"""
LOGGER.debug(f"Trying to import a package with [{command}] ...") LOGGER.debug(f"Trying to import a package with [{command}] ...")
exec_result = package_helper.running_container.exec_run(command) exec_result = package_helper.running_container.exec_run(command)
assert exec_result.exit_code == 0, exec_result.output.decode("utf-8") assert exec_result.exit_code == 0, exec_result.output.decode()
def check_import_python_package( def check_import_python_package(

View File

@@ -50,7 +50,7 @@ def test_nb_user_change(container: TrackedContainer) -> None:
# Use sleep, not wait, because the container sleeps forever. # Use sleep, not wait, because the container sleeps forever.
time.sleep(1) time.sleep(1)
LOGGER.info(f"Checking if the user is changed to {nb_user} by the start script ...") LOGGER.info(f"Checking if the user is changed to {nb_user} by the start script ...")
output = running_container.logs().decode("utf-8") output = running_container.logs().decode()
assert "ERROR" not in output assert "ERROR" not in output
assert "WARNING" not in output assert "WARNING" not in output
assert ( assert (
@@ -61,14 +61,14 @@ def test_nb_user_change(container: TrackedContainer) -> None:
command = "id" command = "id"
expected_output = f"uid=1000({nb_user}) gid=100(users) groups=100(users)" expected_output = f"uid=1000({nb_user}) gid=100(users) groups=100(users)"
cmd = running_container.exec_run(command, user=nb_user, workdir=f"/home/{nb_user}") cmd = running_container.exec_run(command, user=nb_user, workdir=f"/home/{nb_user}")
output = cmd.output.decode("utf-8").strip("\n") output = cmd.output.decode().strip("\n")
assert output == expected_output, f"Bad user {output}, expected {expected_output}" assert output == expected_output, f"Bad user {output}, expected {expected_output}"
LOGGER.info(f"Checking if {nb_user} owns his home folder ...") LOGGER.info(f"Checking if {nb_user} owns his home folder ...")
command = f'stat -c "%U %G" /home/{nb_user}/' command = f'stat -c "%U %G" /home/{nb_user}/'
expected_output = f"{nb_user} users" expected_output = f"{nb_user} users"
cmd = running_container.exec_run(command, workdir=f"/home/{nb_user}") cmd = running_container.exec_run(command, workdir=f"/home/{nb_user}")
output = cmd.output.decode("utf-8").strip("\n") output = cmd.output.decode().strip("\n")
assert ( assert (
output == expected_output output == expected_output
), f"Bad owner for the {nb_user} home folder {output}, expected {expected_output}" ), f"Bad owner for the {nb_user} home folder {output}, expected {expected_output}"
@@ -79,7 +79,7 @@ def test_nb_user_change(container: TrackedContainer) -> None:
command = f'stat -c "%F %U %G" /home/{nb_user}/work' command = f'stat -c "%F %U %G" /home/{nb_user}/work'
expected_output = f"directory {nb_user} users" expected_output = f"directory {nb_user} users"
cmd = running_container.exec_run(command, workdir=f"/home/{nb_user}") cmd = running_container.exec_run(command, workdir=f"/home/{nb_user}")
output = cmd.output.decode("utf-8").strip("\n") output = cmd.output.decode().strip("\n")
assert ( assert (
output == expected_output output == expected_output
), f"Folder work was not copied properly to {nb_user} home folder. stat: {output}, expected {expected_output}" ), f"Folder work was not copied properly to {nb_user} home folder. stat: {output}, expected {expected_output}"

View File

@@ -45,11 +45,11 @@ def test_matplotlib(
) )
command = f"python {cont_data_dir}/{test_file}" command = f"python {cont_data_dir}/{test_file}"
cmd = running_container.exec_run(command) cmd = running_container.exec_run(command)
LOGGER.debug(cmd.output.decode("utf-8")) LOGGER.debug(cmd.output.decode())
assert cmd.exit_code == 0, f"Command {command} failed" assert cmd.exit_code == 0, f"Command {command} failed"
# Checking if the file is generated # Checking if the file is generated
# https://stackoverflow.com/a/15895594/4413446 # https://stackoverflow.com/a/15895594/4413446
command = f"test -s {output_dir}/{expected_file}" command = f"test -s {output_dir}/{expected_file}"
cmd = running_container.exec_run(command) cmd = running_container.exec_run(command)
LOGGER.debug(cmd.output.decode("utf-8")) LOGGER.debug(cmd.output.decode())
assert cmd.exit_code == 0, f"Command {command} failed" assert cmd.exit_code == 0, f"Command {command} failed"

View File

@@ -91,7 +91,7 @@ class CondaPackageHelper:
def _execute_command(self, command: list[str]) -> str: def _execute_command(self, command: list[str]) -> str:
"""Execute a command on a running container""" """Execute a command on a running container"""
rc = self.running_container.exec_run(command, stderr=False) rc = self.running_container.exec_run(command, stderr=False)
return rc.output.decode("utf-8") # type: ignore return rc.output.decode() # type: ignore
@staticmethod @staticmethod
def _parse_package_versions(env_export: str) -> dict[str, set[str]]: def _parse_package_versions(env_export: str) -> dict[str, set[str]]:

View File

@@ -70,7 +70,7 @@ class TrackedContainer:
) -> str: ) -> str:
running_container = self.run_detached(**kwargs) running_container = self.run_detached(**kwargs)
rv = running_container.wait(timeout=timeout) rv = running_container.wait(timeout=timeout)
logs = running_container.logs().decode("utf-8") logs = running_container.logs().decode()
assert isinstance(logs, str) assert isinstance(logs, str)
LOGGER.debug(logs) LOGGER.debug(logs)
assert no_warnings == (not self.get_warnings(logs)) assert no_warnings == (not self.get_warnings(logs))