migrate test_pecl to pytest

This commit is contained in:
Frode Gundersen 2022-12-08 15:59:10 +00:00
parent 2bb2604f74
commit 6d765017ae
No known key found for this signature in database
GPG key ID: DAB4C1C375D2EF45
2 changed files with 53 additions and 47 deletions

View file

@ -0,0 +1,53 @@
"""
:codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
Test cases for salt.modules.pecl
"""
import pytest
import salt.modules.pecl as pecl
from tests.support.mock import patch
@pytest.fixture
def configure_loader_modules():
return {pecl: {}}
def test_install():
"""
Test to installs one or several pecl extensions.
"""
with patch.object(pecl, "_pecl", return_value="A"):
assert pecl.install("fuse", force=True) == "A"
assert not pecl.install("fuse")
with patch.object(pecl, "list_", return_value={"A": ["A", "B"]}):
assert pecl.install(["A", "B"])
def test_uninstall():
"""
Test to uninstall one or several pecl extensions.
"""
with patch.object(pecl, "_pecl", return_value="A"):
assert pecl.uninstall("fuse") == "A"
def test_update():
"""
Test to update one or several pecl extensions.
"""
with patch.object(pecl, "_pecl", return_value="A"):
assert pecl.update("fuse") == "A"
def test_list_():
"""
Test to list installed pecl extensions.
"""
with patch.object(pecl, "_pecl", return_value="A\nB"):
assert pecl.list_("channel") == {}

View file

@ -1,47 +0,0 @@
"""
:codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
"""
import salt.modules.pecl as pecl
from tests.support.mock import patch
from tests.support.unit import TestCase
class PeclTestCase(TestCase):
"""
Test cases for salt.modules.pecl
"""
def test_install(self):
"""
Test to installs one or several pecl extensions.
"""
with patch.object(pecl, "_pecl", return_value="A"):
self.assertEqual(pecl.install("fuse", force=True), "A")
self.assertFalse(pecl.install("fuse"))
with patch.object(pecl, "list_", return_value={"A": ["A", "B"]}):
self.assertTrue(pecl.install(["A", "B"]))
def test_uninstall(self):
"""
Test to uninstall one or several pecl extensions.
"""
with patch.object(pecl, "_pecl", return_value="A"):
self.assertEqual(pecl.uninstall("fuse"), "A")
def test_update(self):
"""
Test to update one or several pecl extensions.
"""
with patch.object(pecl, "_pecl", return_value="A"):
self.assertEqual(pecl.update("fuse"), "A")
def test_list_(self):
"""
Test to list installed pecl extensions.
"""
with patch.object(pecl, "_pecl", return_value="A\nB"):
self.assertDictEqual(pecl.list_("channel"), {})