mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-05 21:54:22 -07:00
Errors1
This commit is contained in:
parent
d088911ed8
commit
07c0ac9390
1 changed files with 4 additions and 11 deletions
|
@ -14,7 +14,7 @@ except ImportError:
|
||||||
import pytest
|
import pytest
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
|
|
||||||
sys.path.insert(0, os.path.abspath(
|
sys.path.insert(0, os.path.abspath(
|
||||||
|
@ -36,14 +36,14 @@ def fake_exports_content():
|
||||||
def calculate_expected_digests(content_string):
|
def calculate_expected_digests(content_string):
|
||||||
content_bytes = content_string.encode('utf-8')
|
content_bytes = content_string.encode('utf-8')
|
||||||
digests = {}
|
digests = {}
|
||||||
hash_algorithms = ['sha256', 'sha1', 'md5']
|
hash_algorithms = ['sha256', 'sha1', 'md5']
|
||||||
for algo in hash_algorithms:
|
for algo in hash_algorithms:
|
||||||
try:
|
try:
|
||||||
hasher = hashlib.new(algo)
|
hasher = hashlib.new(algo)
|
||||||
hasher.update(content_bytes)
|
hasher.update(content_bytes)
|
||||||
digests[algo] = hasher.hexdigest()
|
digests[algo] = hasher.hexdigest()
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
return digests
|
return digests
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,9 +51,7 @@ def test_get_exports_ips_per_share(fake_exports_content):
|
||||||
mock_module = MagicMock()
|
mock_module = MagicMock()
|
||||||
mock_module.file_exists.return_value = True
|
mock_module.file_exists.return_value = True
|
||||||
mock_module.warn.return_value = None
|
mock_module.warn.return_value = None
|
||||||
mock_module.fail_json.side_effect = Exception("fail_json called")
|
mock_module.fail_json.side_effect = Exception("fail_json called")
|
||||||
|
|
||||||
|
|
||||||
patch_target = "builtins.open" if sys.version_info[0] == 3 else "__builtin__.open"
|
patch_target = "builtins.open" if sys.version_info[0] == 3 else "__builtin__.open"
|
||||||
|
|
||||||
with patch(patch_target, mock_open(read_data=fake_exports_content.encode('utf-8'))):
|
with patch(patch_target, mock_open(read_data=fake_exports_content.encode('utf-8'))):
|
||||||
|
@ -77,14 +75,9 @@ def test_get_exports_ips_per_share(fake_exports_content):
|
||||||
|
|
||||||
def test_get_exports_shares_per_ip(fake_exports_content):
|
def test_get_exports_shares_per_ip(fake_exports_content):
|
||||||
mock_module = MagicMock()
|
mock_module = MagicMock()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
mock_module.file_exists.return_value = True
|
mock_module.file_exists.return_value = True
|
||||||
mock_module.warn.return_value = None
|
mock_module.warn.return_value = None
|
||||||
mock_module.fail_json.side_effect = Exception("fail_json called")
|
mock_module.fail_json.side_effect = Exception("fail_json called")
|
||||||
|
|
||||||
|
|
||||||
patch_target = "builtins.open" if sys.version_info[0] == 3 else "__builtin__.open"
|
patch_target = "builtins.open" if sys.version_info[0] == 3 else "__builtin__.open"
|
||||||
|
|
||||||
with patch(patch_target, mock_open(read_data=fake_exports_content.encode('utf-8'))):
|
with patch(patch_target, mock_open(read_data=fake_exports_content.encode('utf-8'))):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue