collection 교체

This commit is contained in:
정훈 변
2024-02-23 16:37:40 +09:00
parent b494779b5b
commit 3fd554eee9
38862 changed files with 220204 additions and 6600073 deletions

File diff suppressed because one or more lines are too long

View File

@@ -6,12 +6,15 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import unittest
from ansible_collections.ansible.utils.plugins.module_utils.common.argspec_validate import (
AnsibleArgSpecValidator,
)
from .fixtures.docstring import DOCUMENTATION
@@ -98,16 +101,12 @@ class TestSortList(unittest.TestCase):
data=data,
schema=DOCUMENTATION,
schema_format="doc",
schema_conditionals={
"required_together": [["param_str", "param_bool"]]
},
schema_conditionals={"required_together": [["param_str", "param_bool"]]},
name="test_action",
)
valid, errors, _updated_data = aav.validate()
self.assertFalse(valid)
self.assertIn(
"parameters are required together: param_str, param_bool", errors
)
self.assertIn("parameters are required together: param_str, param_bool", errors)
def test_unsupported_param(self):
data = {"param_str": "string", "not_valid": "string"}
@@ -122,9 +121,7 @@ class TestSortList(unittest.TestCase):
self.assertFalse(valid)
if isinstance(errors, list):
# for ansibleargspecvalidator 2.11 its returning errors as list
self.assertIn(
"not_valid. Supported parameters include:", errors[0]
)
self.assertIn("not_valid. Supported parameters include:", errors[0])
else:
self.assertIn(
"Unsupported parameters for 'test_action' module: not_valid",

View File

@@ -6,12 +6,12 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import unittest
from ansible_collections.ansible.utils.plugins.module_utils.common.utils import (
dict_merge,
)
from ansible_collections.ansible.utils.plugins.module_utils.common.utils import dict_merge
class TestDict_merge(unittest.TestCase):

View File

@@ -6,16 +6,15 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import unittest
from ansible_collections.ansible.utils.plugins.module_utils.common.get_path import (
get_path,
)
from ansible.template import Templar
from ansible_collections.ansible.utils.plugins.module_utils.common.get_path import get_path
class TestGetPath(unittest.TestCase):
def setUp(self):
@@ -24,18 +23,14 @@ class TestGetPath(unittest.TestCase):
def test_get_path_pass(self):
var = {"a": {"b": {"c": {"d": [0, 1]}}}}
path = "a.b.c.d[0]"
result = get_path(
var, path, environment=self._environment, wantlist=False
)
result = get_path(var, path, environment=self._environment, wantlist=False)
expected = "0"
self.assertEqual(result, expected)
def test_get_path_pass_wantlist(self):
var = {"a": {"b": {"c": {"d": [0, 1]}}}}
path = "a.b.c.d[0]"
result = get_path(
var, path, environment=self._environment, wantlist=True
)
result = get_path(var, path, environment=self._environment, wantlist=True)
expected = ["0"]
self.assertEqual(result, expected)

View File

@@ -1,120 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2020 Red Hat
# GNU General Public License v3.0+
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import unittest
from ansible_collections.ansible.utils.plugins.module_utils.common.index_of import (
index_of,
)
from ansible.template import Templar
class TestIndexOfFilter(unittest.TestCase):
def setUp(self):
self._tests = Templar(loader=None).environment.tests
def test_fail_no_qualfier(self):
obj, test, value = [1, 2], "@@", 1
with self.assertRaises(Exception) as exc:
index_of(obj, test, value, tests=self._tests)
self.assertIn("the test '@@' was not found", str(exc.exception))
obj, test, value, key = [{"a": 1}], "@@", 1, "a"
with self.assertRaises(Exception) as exc:
index_of(obj, test, value, key, tests=self._tests)
self.assertIn("the test '@@' was not found", str(exc.exception))
def test_fail_mixed_list(self):
obj, test, value, key = [{"a": "b"}, True, 1, "a"], "==", "b", "a"
with self.assertRaises(Exception) as exc:
index_of(obj, test, value, key, tests=self._tests)
self.assertIn("required to be dictionaries", str(exc.exception))
def test_fail_key_not_valid(self):
obj, test, value, key = [{"a": "b"}], "==", "b", [1, 2]
with self.assertRaises(Exception) as exc:
index_of(obj, test, value, key, tests=self._tests)
self.assertIn("Unknown key type", str(exc.exception))
def test_fail_on_missing(self):
obj, test, value, key = [{"a": True}, {"c": False}], "==", True, "a"
with self.assertRaises(Exception) as exc:
index_of(
obj, test, value, key, fail_on_missing=True, tests=self._tests
)
self.assertIn("'a' was not found", str(exc.exception))
def test_just_test(self):
"""Limit to jinja < 2.11 tests"""
objs = [
# ([True], "true", 0),
# ([False], "not false", []),
# ([False, 5], "boolean", 0),
# ([0, False], "false", 1),
([3, 4], "not even", 0),
([3, 4], "even", 1),
([3, 3], "even", []),
([3, 3, 3, 4], "odd", [0, 1, 2]),
# ([3.3, 3.4], "float", [0, 1]),
]
for entry in objs:
obj, test, answer = entry
result = index_of(obj, test, tests=self._tests)
expected = answer
self.assertEqual(result, expected)
def test_simple_lists(self):
objs = [
([1, 2, 3], "==", 2, 1),
(["a", "b", "c"], "eq", "c", 2),
([True, False, 0, 1], "equalto", False, [1, 2]),
([True, False, "0", "1"], "==", False, 1),
([True, False, "", "1"], "==", False, 1),
([True, False, "", "1"], "in", False, 1),
([True, False, "", "1", "a"], "in", [False, "1"], [1, 3]),
([1, 2, 3, "a", "b", "c"], "!=", "c", [0, 1, 2, 3, 4]),
([1, 2, 3], "!<", 3, 2),
]
for entry in objs:
obj, test, value, answer = entry
result = index_of(obj, test, value, tests=self._tests)
expected = answer
self.assertEqual(result, expected)
def test_simple_dict(self):
objs = [
([{"a": 1}], "==", 1, "a", 0),
([{"a": 1}], "==", 1, "b", []),
([{"a": 1}], "==", 2, "a", []),
(
[{"a": 1}, {"a": 1}, {"a": 1}, {"a": 2}],
"==",
1,
"a",
[0, 1, 2],
),
(
[{"a": "abc"}, {"a": "def"}, {"a": "ghi"}, {"a": "jkl"}],
"ansible.builtin.match",
"^a",
"a",
0,
),
(
[{"a": "abc"}, {"a": "def"}, {"a": "ghi"}, {"a": "jkl"}],
"ansible.builtin.search",
"e",
"a",
1,
),
]
for entry in objs:
obj, test, value, key, answer = entry
result = index_of(obj, test, value, key, tests=self._tests)
self.assertEqual(result, answer)

View File

@@ -6,12 +6,12 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import unittest
from ansible_collections.ansible.utils.plugins.module_utils.common.utils import (
sort_list,
)
from ansible_collections.ansible.utils.plugins.module_utils.common.utils import sort_list
class TestSortList(unittest.TestCase):

View File

@@ -6,21 +6,19 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import json
import heapq
import json
import os
import unittest
from ansible_collections.ansible.utils.plugins.module_utils.common.get_path import (
get_path,
)
from ansible_collections.ansible.utils.plugins.module_utils.common.to_paths import (
to_paths,
)
from ansible.template import Templar
from ansible_collections.ansible.utils.plugins.module_utils.common.get_path import get_path
from ansible_collections.ansible.utils.plugins.module_utils.common.to_paths import to_paths
class TestToPaths(unittest.TestCase):
def setUp(self):
@@ -52,18 +50,14 @@ class TestToPaths(unittest.TestCase):
def test_roundtrip_large(self):
"""Test the 1000 longest keys, otherwise this takes a _really_ long time"""
big_json_path = os.path.join(
os.path.dirname(__file__), "fixtures", "large.json"
)
big_json_path = os.path.join(os.path.dirname(__file__), "fixtures", "large.json")
with open(big_json_path) as fhand:
big_json = fhand.read()
var = json.loads(big_json)
paths = to_paths(var, prepend=None, wantlist=None)
to_tests = heapq.nlargest(1000, list(paths.keys()), key=len)
for to_test in to_tests:
gotten = get_path(
var, to_test, environment=self._environment, wantlist=False
)
gotten = get_path(var, to_test, environment=self._environment, wantlist=False)
self.assertEqual(gotten, paths[to_test])
def test_to_paths_empty_list(self):