mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-06 22:24:23 -07:00
FATAL: Command "pytest "
This commit is contained in:
parent
fc5073e341
commit
9c2dbfc5c1
1 changed files with 11 additions and 7 deletions
|
@ -1,15 +1,19 @@
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from unittest.mock import mock_open, patch, MagicMock
|
from unittest.mock import mock_open, patch, MagicMock
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from mock import mock_open, patch, MagicMock
|
from mock import mock_open, patch, MagicMock
|
||||||
|
|
||||||
from plugins.modules.nfs_exports_info import get_exports
|
import pytest
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
# Add plugins/modules to path for direct import
|
||||||
|
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../../plugins/modules')))
|
||||||
|
|
||||||
|
from nfs_exports_info import get_exports
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -25,7 +29,7 @@ def test_get_exports_ips_per_share(fake_exports_content):
|
||||||
mock_module = MagicMock()
|
mock_module = MagicMock()
|
||||||
mock_module.digest_from_file.return_value = "fake_sha1_digest"
|
mock_module.digest_from_file.return_value = "fake_sha1_digest"
|
||||||
|
|
||||||
with patch("builtins.open", mock_open(read_data=fake_exports_content)):
|
with patch("builtins.open", mock_open(read_data=fake_exports_content)) if sys.version_info[0] == 3 else patch("__builtin__.open", mock_open(read_data=fake_exports_content)):
|
||||||
result = get_exports(mock_module, "ips_per_share")
|
result = get_exports(mock_module, "ips_per_share")
|
||||||
|
|
||||||
expected = {
|
expected = {
|
||||||
|
@ -46,7 +50,7 @@ def test_get_exports_shares_per_ip(fake_exports_content):
|
||||||
mock_module = MagicMock()
|
mock_module = MagicMock()
|
||||||
mock_module.digest_from_file.return_value = "fake_sha1_digest"
|
mock_module.digest_from_file.return_value = "fake_sha1_digest"
|
||||||
|
|
||||||
with patch("builtins.open", mock_open(read_data=fake_exports_content)):
|
with patch("builtins.open", mock_open(read_data=fake_exports_content)) if sys.version_info[0] == 3 else patch("__builtin__.open", mock_open(read_data=fake_exports_content)):
|
||||||
result = get_exports(mock_module, "shares_per_ip")
|
result = get_exports(mock_module, "shares_per_ip")
|
||||||
|
|
||||||
expected = {
|
expected = {
|
||||||
|
@ -62,4 +66,4 @@ def test_get_exports_shares_per_ip(fake_exports_content):
|
||||||
}
|
}
|
||||||
|
|
||||||
assert result['exports_info'] == expected
|
assert result['exports_info'] == expected
|
||||||
assert result['file_digest'] == "fake_sha1_digest"
|
assert result['file_digest'] == "fake_sha1_digest"
|
Loading…
Add table
Add a link
Reference in a new issue