* Implement #8594

* Fix lint and BOTMETA entries.

* Fix BOTMETA

* Consolidate argument check, code simplification, and formatting. Remove test vars.

* Fix lint.

* retrigger checks

* Update plugins/plugin_utils/ansible_type.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/test/ansible_type.py

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Vladimir Botka 2024-07-13 13:32:36 +02:00 committed by GitHub
parent ca8ecb1df1
commit 8990f97b45
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 847 additions and 0 deletions

View file

@ -0,0 +1,5 @@
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
azp/posix/2

View file

@ -0,0 +1,7 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Integration tests
import_tasks: tasks.yml

View file

@ -0,0 +1,185 @@
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
# Substitution converts str to AnsibleUnicode
# -------------------------------------------
- name: String. AnsibleUnicode.
assert:
that: result == dtype
success_msg: '"abc" is {{ dtype }}'
fail_msg: '"abc" is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
data: "abc"
result: '{{ data | community.general.reveal_ansible_type }}'
dtype: 'AnsibleUnicode'
- name: String. AnsibleUnicode alias str.
assert:
that: result == dtype
success_msg: '"abc" is {{ dtype }}'
fail_msg: '"abc" is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
alias: {"AnsibleUnicode": "str"}
data: "abc"
result: '{{ data | community.general.reveal_ansible_type(alias) }}'
dtype: 'str'
- name: List. All items are AnsibleUnicode.
assert:
that: result == dtype
success_msg: '["a", "b", "c"] is {{ dtype }}'
fail_msg: '["a", "b", "c"] is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
data: ["a", "b", "c"]
result: '{{ data | community.general.reveal_ansible_type }}'
dtype: 'list[AnsibleUnicode]'
- name: Dictionary. All keys are AnsibleUnicode. All values are AnsibleUnicode.
assert:
that: result == dtype
success_msg: '{"a": "foo", "b": "bar", "c": "baz"} is {{ dtype }}'
fail_msg: '{"a": "foo", "b": "bar", "c": "baz"} is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
data: {"a": "foo", "b": "bar", "c": "baz"}
result: '{{ data | community.general.reveal_ansible_type }}'
dtype: 'dict[AnsibleUnicode, AnsibleUnicode]'
# No substitution and no alias. Type of strings is str
# ----------------------------------------------------
- name: String
assert:
that: result == dtype
success_msg: '"abc" is {{ dtype }}'
fail_msg: '"abc" is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
result: '{{ "abc" | community.general.reveal_ansible_type }}'
dtype: str
- name: Integer
assert:
that: result == dtype
success_msg: '123 is {{ dtype }}'
fail_msg: '123 is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
result: '{{ 123 | community.general.reveal_ansible_type }}'
dtype: int
- name: Float
assert:
that: result == dtype
success_msg: '123.45 is {{ dtype }}'
fail_msg: '123.45 is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
result: '{{ 123.45 | community.general.reveal_ansible_type }}'
dtype: float
- name: Boolean
assert:
that: result == dtype
success_msg: 'true is {{ dtype }}'
fail_msg: 'true is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
result: '{{ true | community.general.reveal_ansible_type }}'
dtype: bool
- name: List. All items are strings.
assert:
that: result == dtype
success_msg: '["a", "b", "c"] is {{ dtype }}'
fail_msg: '["a", "b", "c"] is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
result: '{{ ["a", "b", "c"] | community.general.reveal_ansible_type }}'
dtype: list[str]
- name: List of dictionaries.
assert:
that: result == dtype
success_msg: '[{"a": 1}, {"b": 2}] is {{ dtype }}'
fail_msg: '[{"a": 1}, {"b": 2}] is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
result: '{{ [{"a": 1}, {"b": 2}] | community.general.reveal_ansible_type }}'
dtype: list[dict]
- name: Dictionary. All keys are strings. All values are integers.
assert:
that: result == dtype
success_msg: '{"a": 1} is {{ dtype }}'
fail_msg: '{"a": 1} is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
result: '{{ {"a": 1} | community.general.reveal_ansible_type }}'
dtype: dict[str, int]
- name: Dictionary. All keys are strings. All values are integers.
assert:
that: result == dtype
success_msg: '{"a": 1, "b": 2} is {{ dtype }}'
fail_msg: '{"a": 1, "b": 2} is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
result: '{{ {"a": 1, "b": 2} | community.general.reveal_ansible_type }}'
dtype: dict[str, int]
# Type of strings is AnsibleUnicode or str
# ----------------------------------------
- name: Dictionary. The keys are integers or strings. All values are strings.
assert:
that: result == dtype
success_msg: 'data is {{ dtype }}'
fail_msg: 'data is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
alias: {"AnsibleUnicode": "str"}
data: {1: 'a', 'b': 'b'}
result: '{{ data | community.general.reveal_ansible_type(alias) }}'
dtype: dict[int|str, str]
- name: Dictionary. All keys are integers. All values are keys.
assert:
that: result == dtype
success_msg: 'data is {{ dtype }}'
fail_msg: 'data is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
alias: {"AnsibleUnicode": "str"}
data: {1: 'a', 2: 'b'}
result: '{{ data | community.general.reveal_ansible_type(alias) }}'
dtype: dict[int, str]
- name: Dictionary. All keys are strings. Multiple types values.
assert:
that: result == dtype
success_msg: 'data is {{ dtype }}'
fail_msg: 'data is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
alias: {"AnsibleUnicode": "str"}
data: {'a': 1, 'b': 1.1, 'c': 'abc', 'd': True, 'e': ['x', 'y', 'z'], 'f': {'x': 1, 'y': 2}}
result: '{{ data | community.general.reveal_ansible_type(alias) }}'
dtype: dict[str, bool|dict|float|int|list|str]
- name: List. Multiple types items.
assert:
that: result == dtype
success_msg: 'data is {{ dtype }}'
fail_msg: 'data is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
alias: {"AnsibleUnicode": "str"}
data: [1, 2, 1.1, 'abc', True, ['x', 'y', 'z'], {'x': 1, 'y': 2}]
result: '{{ data | community.general.reveal_ansible_type(alias) }}'
dtype: list[bool|dict|float|int|list|str]

View file

@ -0,0 +1,5 @@
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
azp/posix/2

View file

@ -0,0 +1,7 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Integration tests
import_tasks: tasks.yml

View file

@ -0,0 +1,248 @@
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
# Substitution converts str to AnsibleUnicode
# -------------------------------------------
- name: String. AnsibleUnicode.
assert:
that: data is community.general.ansible_type(dtype)
success_msg: '"abc" is {{ dtype }}'
fail_msg: '"abc" is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
data: "abc"
result: '{{ data | community.general.reveal_ansible_type }}'
dtype: 'AnsibleUnicode'
- name: String. AnsibleUnicode alias str.
assert:
that: data is community.general.ansible_type(dtype, alias)
success_msg: '"abc" is {{ dtype }}'
fail_msg: '"abc" is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
alias: {"AnsibleUnicode": "str"}
data: "abc"
result: '{{ data | community.general.reveal_ansible_type(alias) }}'
dtype: 'str'
- name: List. All items are AnsibleUnicode.
assert:
that: data is community.general.ansible_type(dtype)
success_msg: '["a", "b", "c"] is {{ dtype }}'
fail_msg: '["a", "b", "c"] is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
data: ["a", "b", "c"]
result: '{{ data | community.general.reveal_ansible_type }}'
dtype: 'list[AnsibleUnicode]'
- name: Dictionary. All keys are AnsibleUnicode. All values are AnsibleUnicode.
assert:
that: data is community.general.ansible_type(dtype)
success_msg: '{"a": "foo", "b": "bar", "c": "baz"} is {{ dtype }}'
fail_msg: '{"a": "foo", "b": "bar", "c": "baz"} is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
data: {"a": "foo", "b": "bar", "c": "baz"}
result: '{{ data | community.general.reveal_ansible_type }}'
dtype: 'dict[AnsibleUnicode, AnsibleUnicode]'
# No substitution and no alias. Type of strings is str
# ----------------------------------------------------
- name: String
assert:
that: '"abc" is community.general.ansible_type(dtype)'
success_msg: '"abc" is {{ dtype }}'
fail_msg: '"abc" is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
result: '{{ "abc" | community.general.reveal_ansible_type }}'
dtype: str
- name: Integer
assert:
that: '123 is community.general.ansible_type(dtype)'
success_msg: '123 is {{ dtype }}'
fail_msg: '123 is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
result: '{{ 123 | community.general.reveal_ansible_type }}'
dtype: int
- name: Float
assert:
that: '123.45 is community.general.ansible_type(dtype)'
success_msg: '123.45 is {{ dtype }}'
fail_msg: '123.45 is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
result: '{{ 123.45 | community.general.reveal_ansible_type }}'
dtype: float
- name: Boolean
assert:
that: 'true is community.general.ansible_type(dtype)'
success_msg: 'true is {{ dtype }}'
fail_msg: 'true is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
result: '{{ true | community.general.reveal_ansible_type }}'
dtype: bool
- name: List. All items are strings.
assert:
that: '["a", "b", "c"] is community.general.ansible_type(dtype)'
success_msg: '["a", "b", "c"] is {{ dtype }}'
fail_msg: '["a", "b", "c"] is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
result: '{{ ["a", "b", "c"] | community.general.reveal_ansible_type }}'
dtype: list[str]
- name: List of dictionaries.
assert:
that: '[{"a": 1}, {"b": 2}] is community.general.ansible_type(dtype)'
success_msg: '[{"a": 1}, {"b": 2}] is {{ dtype }}'
fail_msg: '[{"a": 1}, {"b": 2}] is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
result: '{{ [{"a": 1}, {"b": 2}] | community.general.reveal_ansible_type }}'
dtype: list[dict]
- name: Dictionary. All keys are strings. All values are integers.
assert:
that: '{"a": 1} is community.general.ansible_type(dtype)'
success_msg: '{"a": 1} is {{ dtype }}'
fail_msg: '{"a": 1} is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
result: '{{ {"a": 1} | community.general.reveal_ansible_type }}'
dtype: dict[str, int]
- name: Dictionary. All keys are strings. All values are integers.
assert:
that: '{"a": 1, "b": 2} is community.general.ansible_type(dtype)'
success_msg: '{"a": 1, "b": 2} is {{ dtype }}'
fail_msg: '{"a": 1, "b": 2} is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
result: '{{ {"a": 1, "b": 2} | community.general.reveal_ansible_type }}'
dtype: dict[str, int]
# Type of strings is AnsibleUnicode or str
# ----------------------------------------
- name: Dictionary. The keys are integers or strings. All values are strings.
assert:
that: data is community.general.ansible_type(dtype, alias)
success_msg: '{"1": "a", "b": "b"} is {{ dtype }}'
fail_msg: '{"1": "a", "b": "b"} is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
alias: {"AnsibleUnicode": "str"}
data: {1: 'a', 'b': 'b'}
result: '{{ data | community.general.reveal_ansible_type(alias) }}'
dtype: dict[int|str, str]
- name: Dictionary. All keys are integers. All values are keys.
assert:
that: data is community.general.ansible_type(dtype, alias)
success_msg: '{"1": "a", "2": "b"} is {{ dtype }}'
fail_msg: '{"1": "a", "2": "b"} is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
alias: {"AnsibleUnicode": "str"}
data: {1: 'a', 2: 'b'}
result: '{{ data | community.general.reveal_ansible_type(alias) }}'
dtype: dict[int, str]
- name: Dictionary. All keys are strings. Multiple types values.
assert:
that: data is community.general.ansible_type(dtype, alias)
success_msg: '{"a": 1, "b": 1.1, "c": "abc", "d": true, "e": ["x", "y", "z"], "f": {"x": 1, "y": 2}} is {{ dtype }}'
fail_msg: '{"a": 1, "b": 1.1, "c": "abc", "d": true, "e": ["x", "y", "z"], "f": {"x": 1, "y": 2}} is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
alias: {"AnsibleUnicode": "str"}
data: {'a': 1, 'b': 1.1, 'c': 'abc', 'd': True, 'e': ['x', 'y', 'z'], 'f': {'x': 1, 'y': 2}}
result: '{{ data | community.general.reveal_ansible_type(alias) }}'
dtype: dict[str, bool|dict|float|int|list|str]
- name: List. Multiple types items.
assert:
that: data is community.general.ansible_type(dtype, alias)
success_msg: '[1, 2, 1.1, "abc", true, ["x", "y", "z"], {"x": 1, "y": 2}] is {{ dtype }}'
fail_msg: '[1, 2, 1.1, "abc", true, ["x", "y", "z"], {"x": 1, "y": 2}] is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
alias: {"AnsibleUnicode": "str"}
data: [1, 2, 1.1, 'abc', True, ['x', 'y', 'z'], {'x': 1, 'y': 2}]
result: '{{ data | community.general.reveal_ansible_type(alias) }}'
dtype: list[bool|dict|float|int|list|str]
# Option dtype is list
# --------------------
- name: AnsibleUnicode or str
assert:
that: data is community.general.ansible_type(dtype)
success_msg: '"abc" is {{ dtype }}'
fail_msg: '"abc" is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
data: abc
result: '{{ data | community.general.reveal_ansible_type }}'
dtype: ['AnsibleUnicode', 'str']
- name: float or int
assert:
that: data is community.general.ansible_type(dtype)
success_msg: '123 is {{ dtype }}'
fail_msg: '123 is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
data: 123
result: '{{ data | community.general.reveal_ansible_type }}'
dtype: ['float', 'int']
- name: float or int
assert:
that: data is community.general.ansible_type(dtype)
success_msg: '123.45 is {{ dtype }}'
fail_msg: '123.45 is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
data: 123.45
result: '{{ data | community.general.reveal_ansible_type }}'
dtype: ['float', 'int']
# Multiple alias
# --------------
- name: int alias number
assert:
that: data is community.general.ansible_type(dtype, alias)
success_msg: '123 is {{ dtype }}'
fail_msg: '123 is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
alias: {"int": "number", "float": "number"}
data: 123
result: '{{ data | community.general.reveal_ansible_type(alias) }}'
dtype: number
- name: float alias number
assert:
that: data is community.general.ansible_type(dtype, alias)
success_msg: '123.45 is {{ dtype }}'
fail_msg: '123.45 is {{ result }}'
quiet: '{{ quiet_test | d(true) | bool }}'
vars:
alias: {"int": "number", "float": "number"}
data: 123.45
result: '{{ data | community.general.reveal_ansible_type(alias) }}'
dtype: number