Skip to content

Commit

Permalink
Fix error message exception
Browse files Browse the repository at this point in the history
  • Loading branch information
hnformentin committed Mar 8, 2023
1 parent a71f4dc commit 63b3fd3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
8 changes: 4 additions & 4 deletions komodo/release_transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _pick_package_versions_for_release(
try:
_check_version_exists_for_coordinates(versions, rhel_ver, py_ver)
except KeyError as err:
error_msg = str(err).replace("'", "") + f" {pkg_name}."
error_msg = f"{str(err)}. Failed for {pkg_name}."
raise KeyError(error_msg)

if rhel_ver in versions:
Expand Down Expand Up @@ -119,19 +119,19 @@ def _check_version_exists_for_coordinates(
if "rhel" in first_level_versions[0]:
# Both rhel and python versions can have different versions
if rhel_coordinate not in first_level_versions:
raise KeyError(f"Rhel version {rhel_coordinate} not found for package")
raise KeyError(f"Rhel version {rhel_coordinate} not found.")
second_level_versions = []
for version_py in pkg_versions[rhel_coordinate]:
second_level_versions.append(version_py)
if py_coordinate not in second_level_versions:
raise KeyError(
f"Python version {py_coordinate} not found for "
f"rhel version {rhel_coordinate} for package"
f"rhel version {rhel_coordinate}."
)
elif "py" in first_level_versions[0]:
# Only python has different versions
if py_coordinate not in first_level_versions:
raise KeyError(f"Python version {py_coordinate} not found in package")
raise KeyError(f"Python version {py_coordinate} not found.")


def transpile_releases(matrix_file: str, output_folder: str, matrix: dict) -> None:
Expand Down
11 changes: 5 additions & 6 deletions tests/test_release_transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,26 @@ def test_transpile_add_argument(tmpdir, matrix):


@pytest.mark.parametrize(
"matrix,reason_for_failure",
"matrix,error_message_content",
[
({"py": ["3.8"], "rhel": ["7"]}, "Test passes, no error reported"),
(
{"py": ["3.7"], "rhel": ["7"]},
"Python version py37 not found for rhel version rhel7 for package lib1.",
["py37", "rhel7", "lib1"],
),
(
{"py": ["3.6"], "rhel": ["5"]},
"Rhel version rhel5 not found for package lib1.",
["rhel5", "lib1"],
),
],
ids=["Pass for all packages", "Fail", "Fail"],
)
def test_check_version_exists_for_coordinates(matrix, reason_for_failure):
def test_check_version_exists_for_coordinates(matrix, error_message_content):
release_file = os.path.join(_get_test_root(), "data", "test_release_matrix.yml")
try:
transpile_releases(release_file, os.getcwd(), matrix)
except KeyError as exception_info:
assert reason_for_failure in str(exception_info)

assert all(word in str(exception_info) for word in error_message_content)

def test_get_py_coords():
release_folder = os.path.join(_get_test_root(), "data", "test_releases")
Expand Down

0 comments on commit 63b3fd3

Please sign in to comment.