Skip to content

Commit

Permalink
Add more tests for update.py
Browse files Browse the repository at this point in the history
  • Loading branch information
larsevj committed Sep 26, 2024
1 parent 95f951e commit 184692c
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 7 deletions.
5 changes: 2 additions & 3 deletions komodoenv/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
def distro_id() -> str:
return "rhel"

if "el7" in platform.release():
if ".el7" in platform.release():

def distro_versions() -> Tuple[str, str, str]:
return ("7", "0", "0")

elif "el8" in platform.release():
elif ".el8" in platform.release():

def distro_versions() -> Tuple[str, str, str]:
return ("8", "0", "0")
Expand Down Expand Up @@ -297,7 +297,6 @@ def can_update(config: Dict[str, str]) -> bool:
"""Compares the version of komodoenv that built the release with the one in the
one we want to update to. If the major versions are the same, we know the
layout is identical, and can be safely updated with this script.
"""
track_path = (Path(config["komodo-root"]) / config["tracked-release"]).resolve()
if not (track_path / "root").is_dir():
Expand Down
12 changes: 8 additions & 4 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import sys
from subprocess import PIPE, CalledProcessError, Popen, check_output
from subprocess import PIPE, STDOUT, Popen, check_output

import pytest
from komodoenv.__main__ import main as _main


Expand Down Expand Up @@ -89,8 +88,13 @@ def revert():
request.addfinalizer(revert)

# There's now an update
with pytest.raises(CalledProcessError):
check_output([str(tmp_path / "kenv/root/bin/komodoenv-update"), "--check"])
output = check_output(
[str(tmp_path / "kenv/root/bin/komodoenv-update"), "--check"], stderr=STDOUT
).decode("utf-8")
assert (
"Warning: Your komodoenv is out of date. You will need to recreate komodo"
in output
)

# Update
script = """\
Expand Down
52 changes: 52 additions & 0 deletions tests/test_update.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import importlib
import shutil
import sys
import time
from importlib.metadata import distribution
from pathlib import Path
from textwrap import dedent
from unittest.mock import mock_open, patch

from komodoenv import update

CONFIG_CONTENT = """
key1=value1
key2 = value2
# This is a comment
key3=value3
malformed_line
"""


def test_rewrite_executable_python():
pip = dedent(
Expand Down Expand Up @@ -165,3 +175,45 @@ def test_get_pkg_version_none():
)

assert ver is None


def test_read_config_with_valid_file():
with patch(
"komodoenv.update.open", new_callable=mock_open, read_data=CONFIG_CONTENT
):
config = update.read_config()
assert config["key1"] == "value1"
assert config["key2"] == "value2"
assert config["key3"] == "value3"
assert "malformed_line" not in config
assert config["komodo-root"] == "/prog/res/komodo"


def test_rhel_version_suffix_with_distro_not_installed():
with patch.dict("sys.modules", {"distro": None}), patch(
"platform.release", return_value="3.10.0-1062.el7.x86_64"
):
from komodoenv import update

importlib.reload(update)
assert update.rhel_version_suffix() == "-rhel7"
with patch.dict("sys.modules", {"distro": None}), patch(
"platform.release", return_value="4.18.0-147.el8.x86_64"
):
from komodoenv import update

importlib.reload(update)
assert update.rhel_version_suffix() == "-rhel8"


def test_rhel_version_suffix_with_distro_not_installed_incompatible(capsys):
with patch.dict("sys.modules", {"distro": None}), patch(
"platform.release", return_value="5.6.14-300.fc32.x86_64"
):
from komodoenv import update

importlib.reload(update)
assert (
"Warning: komodoenv is only compatible with RHEL7 or RHEL8"
in capsys.readouterr().err
)

0 comments on commit 184692c

Please sign in to comment.