1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-19 18:31:33 +00:00

Reformat everything.

This commit is contained in:
Felix Fontein 2025-11-01 12:08:41 +01:00
parent 3f2213791a
commit 340ff8586d
1008 changed files with 61301 additions and 58309 deletions

View file

@ -8,7 +8,10 @@ import pytest
from unittest.mock import Mock, patch
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import ModuleTestCase, set_module_args
from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import (
ModuleTestCase,
set_module_args,
)
from ansible_collections.community.general.plugins.modules.archive import get_archive, common_path
@ -16,29 +19,23 @@ class TestArchive(ModuleTestCase):
def setUp(self):
super().setUp()
self.mock_os_path_isdir = patch('os.path.isdir')
self.mock_os_path_isdir = patch("os.path.isdir")
self.os_path_isdir = self.mock_os_path_isdir.start()
def tearDown(self):
self.os_path_isdir = self.mock_os_path_isdir.stop()
def test_archive_removal_safety(self):
with set_module_args(
dict(
path=['/foo', '/bar', '/baz'],
dest='/foo/destination.tgz',
remove=True
)
):
with set_module_args(dict(path=["/foo", "/bar", "/baz"], dest="/foo/destination.tgz", remove=True)):
module = AnsibleModule(
argument_spec=dict(
path=dict(type='list', elements='path', required=True),
format=dict(type='str', default='gz', choices=['bz2', 'gz', 'tar', 'xz', 'zip']),
dest=dict(type='path'),
exclude_path=dict(type='list', elements='path', default=[]),
exclusion_patterns=dict(type='list', elements='path'),
force_archive=dict(type='bool', default=False),
remove=dict(type='bool', default=False),
path=dict(type="list", elements="path", required=True),
format=dict(type="str", default="gz", choices=["bz2", "gz", "tar", "xz", "zip"]),
dest=dict(type="path"),
exclude_path=dict(type="list", elements="path", default=[]),
exclusion_patterns=dict(type="list", elements="path"),
force_archive=dict(type="bool", default=False),
remove=dict(type="bool", default=False),
),
add_file_common_args=True,
supports_check_mode=True,
@ -51,19 +48,19 @@ class TestArchive(ModuleTestCase):
archive = get_archive(module)
module.fail_json.assert_called_once_with(
path=b', '.join(archive.paths),
msg='Error, created archive can not be contained in source paths when remove=true'
path=b", ".join(archive.paths),
msg="Error, created archive can not be contained in source paths when remove=true",
)
PATHS: tuple[tuple[list[str | bytes], str | bytes], ...] = (
([], ''),
(['/'], '/'),
([b'/'], b'/'),
(['/foo', '/bar', '/baz', '/foobar', '/barbaz', '/foo/bar'], '/'),
([b'/foo', b'/bar', b'/baz', b'/foobar', b'/barbaz', b'/foo/bar'], b'/'),
(['/foo/bar/baz', '/foo/bar'], '/foo/'),
(['/foo/bar/baz', '/foo/bar/'], '/foo/bar/'),
([], ""),
(["/"], "/"),
([b"/"], b"/"),
(["/foo", "/bar", "/baz", "/foobar", "/barbaz", "/foo/bar"], "/"),
([b"/foo", b"/bar", b"/baz", b"/foobar", b"/barbaz", b"/foo/bar"], b"/"),
(["/foo/bar/baz", "/foo/bar"], "/foo/"),
(["/foo/bar/baz", "/foo/bar/"], "/foo/bar/"),
)