<commit_before>"""
    :codeauthor: <NAME> <<EMAIL>>
"""


import pytest

import salt.modules.cmdmod
import salt.modules.rpm_lowpkg as rpm
import salt.utils.path
from tests.support.mock import MagicMock, patch

# pylint: disable=unused-import
try:
    import rpm as rpm_lib

    HAS_RPM = True
except ImportError:
    HAS_RPM = False

try:
    import rpm_vercmp

    HAS_PY_RPM = True
except ImportError:
    HAS_PY_RPM = False
# pylint: enable=unused-import


def _called_with_root(mock):
    cmd = " ".join(mock.call_args[0][0])
    return cmd.startswith("rpm --root /")


@pytest.fixture
def configure_loader_modules():
    return {rpm: {"rpm": MagicMock(return_value=MagicMock)}}


# 'list_pkgs' function tests: 2


def test_list_pkgs():
    """
    Test if it list the packages currently installed in a dict
    """
    mock = MagicMock(return_value="")
    with patch.dict(rpm.__salt__, {"cmd.run": mock}):
        assert rpm.list_pkgs() == {}
        assert not _called_with_root(mock)


def test_list_pkgs_root():
    """
    Test if it list the packages currently installed in a dict,
    called with root parameter
    """
    mock = MagicMock(return_value="")<commit_msg>Add tests for __virtual__ function<commit_after>"""
    :codeauthor: <NAME> <<EMAIL>>
"""


import pytest

import salt.modules.cmdmod
import salt.modules.rpm_lowpkg as rpm
import salt.utils.path
from tests.support.mock import MagicMock, patch

# pylint: disable=unused-import
try:
    import rpm as rpm_lib

    HAS_RPM = True
except ImportError:
    HAS_RPM = False

try:
    import rpm_vercmp

    HAS_PY_RPM = True
except ImportError:
    HAS_PY_RPM = False
# pylint: enable=unused-import


def _called_with_root(mock):
    cmd = " ".join(mock.call_args[0][0])
    return cmd.startswith("rpm --root /")


@pytest.fixture
def configure_loader_modules():
    return {rpm: {"rpm": MagicMock(return_value=MagicMock)}}

def test___virtual___openeuler():
    patch_which = patch("salt.utils.path.which", return_value=True)
    with patch.dict(rpm.__grains__, {"os": "openEuler", "os_family": "openEuler"}), patch_which:
        assert rpm.__virtual__() == "lowpkg"

def test___virtual___issabel_pbx():
    patch_which = patch("salt.utils.path.which", return_value=True)
    with patch.dict(rpm.__grains__, {"os": "Issabel Pbx", "os_family": "IssabeL PBX"}), patch_which:
        assert rpm.__virtual__() == "lowpkg"

def test___virtual___virtuozzo():
    patch_which = patch("salt.utils.path.which", return_value=True)
    with patch.dict(rpm.__grains__, {"os": "virtuozzo", "os_family": "VirtuoZZO"}), patch_which:
        assert rpm.__virtual__() == "lowpkg"

def test___virtual___with_no_rpm():
    patch_which = patch("salt.utils.path.which", return_value=False)
    ret = rpm.__virtual__()
    assert isinstance(ret, tuple)
    assert ret[0] == False

# 'list_pkgs' function tests: 2


def test_list_pkgs():
    """
    Test if it list the packages currently installed in a dict
    """
    mock = MagicMock(return_value="")
    with patch.dict(rpm.__salt__, {"cmd.run": mock}):
        assert rpm.list_pkgs() == {}
        assert not _called_with_root(mock)


def test_list_pkgs_root():
    """
    Test if it list the packages currently installed in a dict,
    called with root parameter
    """
    mock = MagicMock(return_value="")
{'fraction_non_alphanumeric': 0.12530120481927712, 'fraction_numerical': 0.002108433734939759, 'mean_word_length': 3.92, 'pattern_counts': {'":': 10, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3622557', 'n_tokens_mistral': 1158, 'n_tokens_neox': 1092, 'n_words': 271}