test_apt: migrate from unittest to pytest (#82666)

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
pull/78765/merge
Abhijeet Kasurde 2 years ago committed by GitHub
parent 2806758793
commit 6439627ce4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,45 +1,45 @@
# Copyright: Contributors to the Ansible project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations from __future__ import annotations
import collections import collections
from unittest.mock import Mock from ansible.modules.apt import expand_pkgspec_from_fnmatches
import unittest import pytest
from ansible.modules.apt import (
expand_pkgspec_from_fnmatches,
)
class AptExpandPkgspecTestCase(unittest.TestCase):
def setUp(self):
FakePackage = collections.namedtuple("Package", ("name",)) FakePackage = collections.namedtuple("Package", ("name",))
self.fake_cache = [ fake_cache = [
FakePackage("apt"), FakePackage("apt"),
FakePackage("apt-utils"), FakePackage("apt-utils"),
FakePackage("not-selected"), FakePackage("not-selected"),
] ]
def test_trivial(self):
pkg = ["apt"]
self.assertEqual(
expand_pkgspec_from_fnmatches(None, pkg, self.fake_cache), pkg)
def test_version_wildcard(self): @pytest.mark.parametrize(
pkg = ["apt=1.0*"] ("test_input", "expected"),
self.assertEqual( [
expand_pkgspec_from_fnmatches(None, pkg, self.fake_cache), pkg) pytest.param(
["apt"],
def test_pkgname_wildcard_version_wildcard(self): ["apt"],
pkg = ["apt*=1.0*"] id="trivial",
m_mock = Mock() ),
self.assertEqual( pytest.param(
expand_pkgspec_from_fnmatches(m_mock, pkg, self.fake_cache), ["apt=1.0*"],
['apt', 'apt-utils']) ["apt=1.0*"],
id="version-wildcard",
def test_pkgname_expands(self): ),
pkg = ["apt*"] pytest.param(
m_mock = Mock() ["apt*=1.0*"],
self.assertEqual( ["apt", "apt-utils"],
expand_pkgspec_from_fnmatches(m_mock, pkg, self.fake_cache), id="pkgname-wildcard-version",
["apt", "apt-utils"]) ),
pytest.param(
["apt*"],
["apt", "apt-utils"],
id="pkgname-expands",
),
],
)
def test_expand_pkgspec_from_fnmatches(test_input, expected):
"""Test positive cases of ``expand_pkgspec_from_fnmatches``."""
assert expand_pkgspec_from_fnmatches(None, test_input, fake_cache) == expected

Loading…
Cancel
Save