Skip to content

Commit

Permalink
Switch to Ruff 2025 style (0.9.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkmueller committed Jan 10, 2025
1 parent 8ce99e4 commit a04a9b8
Show file tree
Hide file tree
Showing 14 changed files with 127 additions and 122 deletions.
14 changes: 8 additions & 6 deletions bci_tester/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@
# List the released versions of SLE, used for supportabilty and EULA tests
RELEASED_SLE_VERSIONS = ("15.3", "15.4", "15.5", "15.6", "15.6-ai")

assert (
sorted(ALLOWED_BASE_OS_VERSIONS) == list(ALLOWED_BASE_OS_VERSIONS)
), f"list ALLOWED_BASE_OS_VERSIONS must be sorted, but got {ALLOWED_BASE_OS_VERSIONS}"
assert sorted(ALLOWED_BASE_OS_VERSIONS) == list(ALLOWED_BASE_OS_VERSIONS), (
f"list ALLOWED_BASE_OS_VERSIONS must be sorted, but got {ALLOWED_BASE_OS_VERSIONS}"
)

assert (
sorted(ALLOWED_NONBASE_OS_VERSIONS) == list(ALLOWED_NONBASE_OS_VERSIONS)
), f"list ALLOWED_NONOS_VERSIONS must be sorted, but got {ALLOWED_NONBASE_OS_VERSIONS}"
assert sorted(ALLOWED_NONBASE_OS_VERSIONS) == list(
ALLOWED_NONBASE_OS_VERSIONS
), (
f"list ALLOWED_NONOS_VERSIONS must be sorted, but got {ALLOWED_NONBASE_OS_VERSIONS}"
)

if not (
OS_VERSION in ALLOWED_BASE_OS_VERSIONS
Expand Down
6 changes: 3 additions & 3 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ def container_git_clone(

assert isinstance(container_fixture, ContainerData)

assert (
container_fixture is not None
), "No container fixture was passed to the test function, cannot execute `container_git_clone`"
assert container_fixture is not None, (
"No container fixture was passed to the test function, cannot execute `container_git_clone`"
)

check_output(shlex.split(git_repo_build.clone_command), cwd=tmp_path)

Expand Down
43 changes: 22 additions & 21 deletions tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ def test_lifecycle(auto_container):
support_end = datetime.datetime.strptime(
entry_date, "%Y-%m-%d"
)
assert (
datetime.datetime.now() < support_end
), f"{entry_name} = {installed_binaries[entry_name]} installed but out of support since {entry_date}"
assert datetime.datetime.now() < support_end, (
f"{entry_name} = {installed_binaries[entry_name]} installed but out of support since {entry_date}"
)


@pytest.mark.skipif(
Expand Down Expand Up @@ -446,9 +446,9 @@ def test_systemd_not_installed_in_all_containers_except_init(container):

# we cannot check for an existing package if rpm is not installed
if container.connection.exists("rpm"):
assert not container.connection.package(
"systemd"
).is_installed, "systemd is installed in this container!"
assert not container.connection.package("systemd").is_installed, (
"systemd is installed in this container!"
)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -478,9 +478,9 @@ def test_bci_eula_is_correctly_available(container: ContainerData) -> None:
OS_VERSION in ALLOWED_BCI_REPO_OS_VERSIONS
and OS_VERSION in RELEASED_SLE_VERSIONS
):
assert container.connection.file(
bci_license
).exists, "BCI EULA is missing"
assert container.connection.file(bci_license).exists, (
"BCI EULA is missing"
)
assert (
"SUSE Linux Enterprise Base Container Image License"
in container.connection.check_output(f"head -n 1 {bci_license}")
Expand All @@ -500,9 +500,9 @@ def test_bci_eula_is_correctly_available(container: ContainerData) -> None:
):
pytest.skip("Unmaintained bci-* base os containers are not tested")

assert not container.connection.file(
bci_license
).exists, "BCI EULA shall not be in LTSS container"
assert not container.connection.file(bci_license).exists, (
"BCI EULA shall not be in LTSS container"
)


@pytest.mark.skipif(
Expand Down Expand Up @@ -633,9 +633,9 @@ def test_container_build_and_repo(container_per_test, host):

repos = get_repos_from_connection(container_per_test.connection)

assert (
len(repos) > 1
), "On a registered host, we must have more than one repository on the host"
assert len(repos) > 1, (
"On a registered host, we must have more than one repository on the host"
)
else:
assert len(repos) <= len(expected_repos)
assert not repo_names - expected_repos
Expand Down Expand Up @@ -670,12 +670,13 @@ def test_container_build_and_repo(container_per_test, host):
)

assert (
("SLE_BCI_debug" in repo_names and "SLE_BCI_source" in repo_names)
or (
"SLE_BCI_debug" not in repo_names
and "SLE_BCI_source" not in repo_names
)
), "repos SLE_BCI_source and SLE_BCI_debug must either both be present or both missing"
"SLE_BCI_debug" in repo_names and "SLE_BCI_source" in repo_names
) or (
"SLE_BCI_debug" not in repo_names
and "SLE_BCI_source" not in repo_names
), (
"repos SLE_BCI_source and SLE_BCI_debug must either both be present or both missing"
)

# check that all enabled repos are valid and can be refreshed
container_per_test.connection.run_expect([0], "zypper -n ref")
2 changes: 1 addition & 1 deletion tests/test_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def _fetch_catalog():
host.run_expect(
[0],
textwrap.dedent(
f"""cd {tmp_path} && {' '.join(container_runtime.build_command)} \
f"""cd {tmp_path} && {" ".join(container_runtime.build_command)} \
-t {container_path} -f Containerfile .""",
),
)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_dotnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ def get_pkg_list(extra_search_flags: str = "") -> List[str]:
return valid_names

repos = get_repos_from_connection(container_per_test.connection)
assert (
len(repos) >= 2
), "The .Net containers must contain the SLE_BCI and MS .Net repository"
assert len(repos) >= 2, (
"The .Net containers must contain the SLE_BCI and MS .Net repository"
)

ms_repos = [repo for repo in repos if repo.name == MS_REPO_NAME]
assert len(ms_repos) == 1
Expand Down
12 changes: 6 additions & 6 deletions tests/test_fips.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ def openssl_fips_hashes_test_fnct(container_per_test: ContainerData) -> None:
dev_null_digest = container_per_test.connection.check_output(
f"openssl {digest} /dev/null"
)
assert (
f"= {NULL_DIGESTS[digest]}" in dev_null_digest
), f"unexpected digest of hash {digest}: {dev_null_digest}"
assert f"= {NULL_DIGESTS[digest]}" in dev_null_digest, (
f"unexpected digest of hash {digest}: {dev_null_digest}"
)


@pytest.mark.skipif(
Expand Down Expand Up @@ -218,9 +218,9 @@ def test_gnutls_binary(container_per_test: ContainerData) -> None:
for digest in NONFIPS_GNUTLS_DIGESTS:
err_msg = c.run_expect([1], f"/bin/fips-test-gnutls {digest}").stderr

assert (
"Hash calculation failed" in err_msg
), f"Hash calculation unexpectedly succeeded for {digest}"
assert "Hash calculation failed" in err_msg, (
f"Hash calculation unexpectedly succeeded for {digest}"
)


@pytest.mark.parametrize(
Expand Down
6 changes: 3 additions & 3 deletions tests/test_go.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ def test_rancher_build(host, host_git_clone, dapper, container: ContainerData):
)
from_line = from_line_regex.match(contents)

assert from_line and from_line.group(
"go_ver"
), f"No valid FROM line found in Dockerfile.dapper: {contents}"
assert from_line and from_line.group("go_ver"), (
f"No valid FROM line found in Dockerfile.dapper: {contents}"
)
go_version = container.connection.check_output("echo $GOLANG_VERSION")
if not go_version.startswith(from_line.group("go_ver")):
pytest.skip(
Expand Down
54 changes: 27 additions & 27 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ def extract_time(stdout, prefix):
startup = extract_time(time.stdout, "Startup finished in ")
assert startup <= startup_limit, "Startup threshold exceeded"
target = extract_time(time.stdout, ".target reached after ")
assert (
target <= target_limit
), "Reaching systemd target threshold exceeded"
assert target <= target_limit, (
"Reaching systemd target threshold exceeded"
)

def test_systemd_nofailed_units(self, auto_container):
"""
Expand All @@ -99,19 +99,19 @@ def test_systemd_nofailed_units(self, auto_container):
output = auto_container.connection.run_expect(
[0], "systemctl list-units --state=failed"
)
assert (
"0 loaded units listed" in output.stdout
), "failed systemd units detected"
assert "0 loaded units listed" in output.stdout, (
"failed systemd units detected"
)

def test_systemd_detect_virt(self, auto_container, container_runtime):
"""
Ensure :command:`systemd-detect-virt` detects the container runtime
"""
output = auto_container.connection.check_output("systemd-detect-virt")
runtime = container_runtime.runner_binary
assert (
runtime in output
), f"systemd-detect-virt failed to detect {runtime}"
assert runtime in output, (
f"systemd-detect-virt failed to detect {runtime}"
)

def test_journald(self, auto_container):
"""
Expand All @@ -122,9 +122,9 @@ def test_journald(self, auto_container):
journal = auto_container.connection.run_expect(
[0], "journalctl --boot"
)
assert (
"Reached target Multi-User System" in journal.stdout
), "Multi-User target was not reached"
assert "Reached target Multi-User System" in journal.stdout, (
"Multi-User target was not reached"
)

def test_hostnamectl(self, auto_container, container_runtime):
"""
Expand All @@ -143,9 +143,9 @@ def test_hostnamectl(self, auto_container, container_runtime):
if OS_VERSION == "tumbleweed"
else "SUSE Linux Enterprise Server"
)
assert (
expected_os in values["OperatingSystemPrettyName"]
), "Missing SUSE tag in Operating system"
assert expected_os in values["OperatingSystemPrettyName"], (
"Missing SUSE tag in Operating system"
)

virt_detected = auto_container.connection.run_expect(
[0], "systemd-detect-virt -c"
Expand All @@ -159,26 +159,26 @@ def test_timedatectl(self, auto_container):
Ensure :command:`timedatectl` works as expected and the container timezone is UTC
"""
output = auto_container.connection.check_output("timedatectl")
assert re.search(
r"Time zone:.*(Etc/UTC|UTC)", output
), "Time zone not set to UTC"
assert re.search(r"Time zone:.*(Etc/UTC|UTC)", output), (
"Time zone not set to UTC"
)

# Check that the reported timestamp for UTC and local time match the system time
def check_timestamp(pattern, timestamp, delta):
"""Checks the timedatectl output for the given pattern against the given timestamp
e.g. use the "Universal time" as pattern and datetime.utcnow() to check for the UTC time
"""
grep = [line for line in output.split("\n") if pattern in line]
assert (
len(grep) == 1
), f"{pattern} not present in timedatectl output"
assert len(grep) == 1, (
f"{pattern} not present in timedatectl output"
)
tsp = (
grep[0].strip()[len(pattern) + 2 :].strip()
) # Extract actual timestamp
tsp = datetime.datetime.strptime(tsp, "%a %Y-%m-%d %H:%M:%S UTC")
assert (
abs(tsp - timestamp) < delta
), f"timedatectl diff exceeded for {pattern}"
assert abs(tsp - timestamp) < delta, (
f"timedatectl diff exceeded for {pattern}"
)

check_timestamp(
"Universal time",
Expand All @@ -197,6 +197,6 @@ def test_no_loginctl_sessions(self, auto_container):
Ensure :command:`loginctl` contains no logins
"""
loginctl = auto_container.connection.run_expect([0], "loginctl")
assert (
"No sessions" in loginctl.stdout
), "Assert no sessions are present failed"
assert "No sessions" in loginctl.stdout, (
"Assert no sessions are present failed"
)
42 changes: 21 additions & 21 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ def _get_container_label_prefix(
]


assert len(ALL_CONTAINERS) == len(
IMAGES_AND_NAMES
), "IMAGES_AND_NAMES must have all containers from ALL_CONTAINERS"
assert len(ALL_CONTAINERS) == len(IMAGES_AND_NAMES), (
"IMAGES_AND_NAMES must have all containers from ALL_CONTAINERS"
)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -375,9 +375,9 @@ def test_general_labels(
"https://www.suse.com/products/long-term-service-pack-support/",
)

assert (
labels[f"{prefix}.url"] in expected_url
), f"expected LABEL {prefix}.url = {expected_url} but is {labels[f'{prefix}.url']}"
assert labels[f"{prefix}.url"] in expected_url, (
f"expected LABEL {prefix}.url = {expected_url} but is {labels[f'{prefix}.url']}"
)
assert labels[f"{prefix}.vendor"] == VENDOR

if OS_VERSION == "tumbleweed":
Expand Down Expand Up @@ -507,9 +507,9 @@ def test_disturl_can_be_checked_out(
pytest.skip(reason=f"Cannot connect to SUSE internal host: {e}")
raise
req.raise_for_status()
assert (
"kiwi" in req.text or "Dockerfile" in req.text
), "Cannot find a valid build description"
assert "kiwi" in req.text or "Dockerfile" in req.text, (
"Cannot find a valid build description"
)


@SKIP_IF_TW_MARK
Expand Down Expand Up @@ -559,9 +559,9 @@ def test_acc_label(container: ContainerData):
``com.suse.supportlevel`` set to ``acc``.
Reference: https://confluence.suse.com/display/ENGCTNRSTORY/SLE+BCI+Image+Overview
"""
assert (
container.inspect.config.labels["com.suse.supportlevel"] == "acc"
), "acc images must be marked as acc"
assert container.inspect.config.labels["com.suse.supportlevel"] == "acc", (
"acc images must be marked as acc"
)


@SKIP_IF_TW_MARK
Expand All @@ -571,9 +571,9 @@ def test_l3_label(container: ContainerData):
``com.suse.supportlevel`` set to ``l3``.
Reference: https://confluence.suse.com/display/ENGCTNRSTORY/SLE+BCI+Image+Overview
"""
assert (
container.inspect.config.labels["com.suse.supportlevel"] == "l3"
), "image supportlevel must be marked as L3"
assert container.inspect.config.labels["com.suse.supportlevel"] == "l3", (
"image supportlevel must be marked as L3"
)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -680,15 +680,15 @@ def test_oci_base_refs(
base_digest: str = labels["org.opencontainers.image.base.digest"]
base_name: str = labels["org.opencontainers.image.base.name"]

assert (
":" in base_name
), f"`org.opencontainers.image.base.name` is not the expected format: {base_name}"
assert ":" in base_name, (
f"`org.opencontainers.image.base.name` is not the expected format: {base_name}"
)
base_repository = base_name.partition(":")[0]

assert base_name.startswith("registry.suse.com/")
assert (
f":{OS_VERSION_ID}" in base_name
), "Base image reference is not the expected version"
assert f":{OS_VERSION_ID}" in base_name, (
"Base image reference is not the expected version"
)
assert base_digest.startswith("sha256:")

if PODMAN_SELECTED and container_runtime.version.major < 3:
Expand Down
Loading

0 comments on commit a04a9b8

Please sign in to comment.