Skip to content

Commit

Permalink
chore: fixing unit test case sensitivity
Browse files Browse the repository at this point in the history
Handling filesystem specific case sensitivity, by creating temporary files and checking if they point towards same file using their inodes. This fixes #992

Signed-off-by: Achraf Maghous <achraf.maghous@oracle.com>
  • Loading branch information
achrafmag committed Feb 16, 2025
1 parent a6460d1 commit c68feee
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions tests/artifact/test_local_artifact.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Copyright (c) 2024 - 2024, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2024 - 2025, Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/.

"""Test the local artifact utilities."""

import os
import tempfile
from pathlib import Path

import pytest
Expand All @@ -18,6 +19,18 @@
from macaron.errors import LocalArtifactFinderError


def is_case_sensitive_filesystem() -> bool:
"""Check if current filesystem is case-sensitive."""
with tempfile.NamedTemporaryFile(prefix="Tmp") as tmp:
base = tmp.name
lower = base.lower()
upper = base.upper()

return not (os.path.exists(lower) or os.path.exists(upper)) or (
os.path.exists(lower) and os.path.exists(upper) and os.stat(lower).st_ino != os.stat(upper).st_ino
)


@pytest.mark.parametrize(
("purl_str", "expectation"),
[
Expand Down Expand Up @@ -205,13 +218,21 @@ def test_get_local_artifact_paths_succeeded_pypi(tmp_path: Path) -> None:
python_venv_path = f"{tmp_path_str}/.venv/lib/python3.11/site-packages"

# We are also testing if the patterns match case-insensitively.
pypi_artifact_paths = [
f"{python_venv_path}/macaron",
f"{python_venv_path}/macaron-0.13.0.dist-info",
f"{python_venv_path}/Macaron-0.13.0.dist-info",
f"{python_venv_path}/macaron-0.13.0.data",
f"{python_venv_path}/Macaron-0.13.0.data",
]

if not is_case_sensitive_filesystem():
pypi_artifact_paths = [
f"{python_venv_path}/macaron",
f"{python_venv_path}/macaron-0.13.0.dist-info",
f"{python_venv_path}/macaron-0.13.0.data",
]
else:
pypi_artifact_paths = [
f"{python_venv_path}/macaron",
f"{python_venv_path}/macaron-0.13.0.dist-info",
f"{python_venv_path}/Macaron-0.13.0.dist-info",
f"{python_venv_path}/macaron-0.13.0.data",
f"{python_venv_path}/Macaron-0.13.0.data",
]

os.makedirs(python_venv_path)

Expand Down

0 comments on commit c68feee

Please sign in to comment.