2017-02-14 04:49:39 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
2017-12-05 20:43:13 +00:00
|
|
|
# Copyright (c) 2017 Ansible Project
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
2017-02-14 04:49:39 +00:00
|
|
|
|
|
|
|
import json
|
|
|
|
import sys
|
2017-11-28 23:43:24 +00:00
|
|
|
from collections import MutableMapping
|
|
|
|
from io import BytesIO
|
2017-02-14 04:49:39 +00:00
|
|
|
|
2017-11-28 23:43:24 +00:00
|
|
|
import pytest
|
2017-02-14 04:49:39 +00:00
|
|
|
|
|
|
|
import ansible.module_utils.basic
|
2017-11-28 23:43:24 +00:00
|
|
|
from ansible.module_utils.six import PY3, string_types
|
|
|
|
from ansible.module_utils._text import to_bytes
|
2017-02-14 04:49:39 +00:00
|
|
|
|
|
|
|
|
2017-12-05 20:43:13 +00:00
|
|
|
@pytest.mark.parametrize('stdin', [{}], indirect=['stdin'])
|
2017-11-28 23:43:24 +00:00
|
|
|
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']
|
|
|
|
|
|
|
|
|
2017-12-05 20:43:13 +00:00
|
|
|
@pytest.mark.parametrize('stdin', [{}], indirect=['stdin'])
|
2017-11-28 23:43:24 +00:00
|
|
|
def test_deprecate(am, capfd):
|
|
|
|
am.deprecate('deprecation1')
|
|
|
|
am.deprecate('deprecation2', '2.3')
|
|
|
|
|
|
|
|
with pytest.raises(SystemExit):
|
|
|
|
am.exit_json(deprecations=['deprecation3', ('deprecation4', '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': None},
|
|
|
|
{u'msg': u'deprecation4', u'version': '2.4'},
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2017-12-05 20:43:13 +00:00
|
|
|
@pytest.mark.parametrize('stdin', [{}], indirect=['stdin'])
|
2017-11-28 23:43:24 +00:00
|
|
|
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},
|
|
|
|
]
|