ansible/test/units/module_utils/basic/test_deprecate_warn.py
Felix Fontein a862ff2d43
Deprecation revisited (#69926)
* Allow to specify collection_name separately for deprecation.

* Use new functionality in Ansible.

* Use new functionality in tests.

* Update tagging/untagging functions.

* Update pylint deprecated sanity test.

* Update validate-modules. Missing are basic checks for version_added (validate semantic version format for collections).

* Improve version validation. Re-add version_added validation.

* Make sure collection names are added to return docs before schema validation.

* Extra checks to avoid crashes on bad data.

* Make C# module utils code work, and update/extend tests.

* Add changelog fragment.

* Stop extracting collection name from potentially tagged versions/dates.

* Simplify C# code.

* Update Windows modules docs.

* Forgot semicolons.
2020-06-09 15:21:19 -07:00

70 lines
3.1 KiB
Python

# -*- coding: utf-8 -*-
#
# Copyright (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
import json
import pytest
@pytest.mark.parametrize('stdin', [{}], indirect=['stdin'])
def test_warn(am, capfd):
am.warn('warning1')
with pytest.raises(SystemExit):
am.exit_json(warnings=['warning2'])
out, err = capfd.readouterr()
assert json.loads(out)['warnings'] == ['warning1', 'warning2']
@pytest.mark.parametrize('stdin', [{}], indirect=['stdin'])
def test_deprecate(am, capfd):
am.deprecate('deprecation1')
am.deprecate('deprecation2', '2.3') # pylint: disable=ansible-deprecated-no-collection-name
am.deprecate('deprecation3', version='2.4') # pylint: disable=ansible-deprecated-no-collection-name
am.deprecate('deprecation4', date='2020-03-10') # pylint: disable=ansible-deprecated-no-collection-name
am.deprecate('deprecation5', collection_name='ansible.builtin')
am.deprecate('deprecation6', '2.3', collection_name='ansible.builtin')
am.deprecate('deprecation7', version='2.4', collection_name='ansible.builtin')
am.deprecate('deprecation8', date='2020-03-10', collection_name='ansible.builtin')
with pytest.raises(SystemExit):
am.exit_json(deprecations=['deprecation9', ('deprecation10', '2.4')])
out, err = capfd.readouterr()
output = json.loads(out)
assert ('warnings' not in output or output['warnings'] == [])
assert output['deprecations'] == [
{u'msg': u'deprecation1', u'version': None, u'collection_name': None},
{u'msg': u'deprecation2', u'version': '2.3', u'collection_name': None},
{u'msg': u'deprecation3', u'version': '2.4', u'collection_name': None},
{u'msg': u'deprecation4', u'date': '2020-03-10', u'collection_name': None},
{u'msg': u'deprecation5', u'version': None, u'collection_name': 'ansible.builtin'},
{u'msg': u'deprecation6', u'version': '2.3', u'collection_name': 'ansible.builtin'},
{u'msg': u'deprecation7', u'version': '2.4', u'collection_name': 'ansible.builtin'},
{u'msg': u'deprecation8', u'date': '2020-03-10', u'collection_name': 'ansible.builtin'},
{u'msg': u'deprecation9', u'version': None, u'collection_name': None},
{u'msg': u'deprecation10', u'version': '2.4', u'collection_name': None},
]
@pytest.mark.parametrize('stdin', [{}], indirect=['stdin'])
def test_deprecate_without_list(am, capfd):
with pytest.raises(SystemExit):
am.exit_json(deprecations='Simple deprecation warning')
out, err = capfd.readouterr()
output = json.loads(out)
assert ('warnings' not in output or output['warnings'] == [])
assert output['deprecations'] == [
{u'msg': u'Simple deprecation warning', u'version': None, u'collection_name': None},
]
@pytest.mark.parametrize('stdin', [{}], indirect=['stdin'])
def test_deprecate_without_list(am, capfd):
with pytest.raises(AssertionError) as ctx:
am.deprecate('Simple deprecation warning', date='', version='')
assert ctx.value.args[0] == "implementation error -- version and date must not both be set"