* Prevent Ansible 2.9 to choke on collections using deprecation by date or collection_name for deprecation calls. * Add changelog fragment. * Fix YAML. * Improve C# compatibility. * Add tests for AnsibleModule. * Fix var name. * Fix type. * Update C# code. * Show deprecation warning if removed_at_date is used for Python modules. * Update changelogs/fragments/69935-2.10-deprecation-support.yml Co-authored-by: Alicia Cozine <879121+acozine@users.noreply.github.com> * Prevent crash of validate-modules if 'removed_in' is not in 'deprecated'. Co-authored-by: Alicia Cozine <879121+acozine@users.noreply.github.com>
58 lines
2.0 KiB
Python
58 lines
2.0 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')
|
|
am.deprecate('deprecation3', '2.5', collection_name='foo.bar') # Ansible 2.10 compatibility
|
|
am.deprecate('deprecation4', date='2020-01-01') # Ansible 2.10 compatibility
|
|
am.deprecate('deprecation5', date='2020-01-01', collection_name='foo.bar') # Ansible 2.10 compatibility
|
|
|
|
with pytest.raises(SystemExit):
|
|
am.exit_json(deprecations=['deprecation6', ('deprecation7', '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'msg': u'deprecation2', u'version': '2.3'},
|
|
{u'msg': u'deprecation3', u'version': '2.5'},
|
|
{u'msg': u'deprecation4', u'version': None},
|
|
{u'msg': u'deprecation5', u'version': None},
|
|
{u'msg': u'deprecation6', u'version': None},
|
|
{u'msg': u'deprecation7', u'version': '2.4'},
|
|
]
|
|
|
|
|
|
@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},
|
|
]
|