def test_deprecate_with_version(reset): deprecate(msg='Deprecation message', version='2.14') assert warnings._global_deprecations == [{ 'msg': 'Deprecation message', 'version': '2.14', 'collection_name': None }]
def test_get_deprecation_messages(deprecation_messages): for d in deprecation_messages: deprecate(**d) accessor_deprecations = get_deprecation_messages() assert isinstance(accessor_deprecations, tuple) assert len(accessor_deprecations) == 3
def test_deprecate_message_only(reset): deprecate('Deprecation message') assert warnings._global_deprecations == [{ 'msg': 'Deprecation message', 'version': None, 'collection_name': None }]
def test_deprecate_with_date(reset): deprecate(msg='Deprecation message', date='2199-12-31') assert warnings._global_deprecations == [{ 'msg': 'Deprecation message', 'date': '2199-12-31', 'collection_name': None }]
def test_deprecate_with_collection(reset): deprecate(msg='Deprecation message', collection_name='ansible.builtin') assert warnings._global_deprecations == [{ 'msg': 'Deprecation message', 'version': None, 'collection_name': 'ansible.builtin' }]
def test_deprecate_with_date_and_collection(reset): deprecate(msg='Deprecation message', date='2199-12-31', collection_name='ansible.builtin') assert warnings._global_deprecations == [{ 'msg': 'Deprecation message', 'date': '2199-12-31', 'collection_name': 'ansible.builtin' }]
def validate(self, parameters): result = super(ModuleArgumentSpecValidator, self).validate(parameters) for d in result._deprecations: deprecate( "Alias '{name}' is deprecated. See the module docs for more information" .format(name=d['name']), version=d.get('version'), date=d.get('date'), collection_name=d.get('collection_name')) for w in result._warnings: warn('Both option {option} and its alias {alias} are set.'.format( option=w['option'], alias=w['alias'])) return result
def test_deprecate_failure(test_case): with pytest.raises(TypeError, match='deprecate requires a string not a %s' % type(test_case)): deprecate(test_case)
def test_multiple_deprecations(deprecation_messages): for d in deprecation_messages: deprecate(**d) assert deprecation_messages == warnings._global_deprecations
def test_deprecate_with_version(): deprecate(msg='Deprecation message', version='2.14') assert warnings._global_deprecations == [{'msg': 'Deprecation message', 'version': '2.14'}]
def test_deprecate_message_only(): deprecate('Deprecation message') assert warnings._global_deprecations == [{'msg': 'Deprecation message', 'version': None}]
def __init__(self): deprecate("FileLock is not reliable and has never been used in core for that reason. There is no current alternative that works across POSIX targets", version='2.16') self.lockfd = None
def test_deprecate_with_version_and_collection(): deprecate(msg='Deprecation message', version='2.14', collection_name='ansible.builtin') assert warnings._global_deprecations == [ {'msg': 'Deprecation message', 'version': '2.14', 'collection_name': 'ansible.builtin'}]
def validate(self, *args, **kwargs): """Validate module parameters against argument spec. :Example: validator = ArgumentSpecValidator(argument_spec, parameters) passeded = validator.validate() :param argument_spec: Specification of parameters, type, and valid values :type argument_spec: dict :param parameters: Parameters provided to the role :type parameters: dict :returns: True if no errors were encountered, False if any errors were encountered. :rtype: bool """ self._no_log_values.update(set_fallbacks(self.argument_spec, self._validated_parameters)) alias_warnings = [] alias_deprecations = [] try: alias_results, legal_inputs = handle_aliases(self.argument_spec, self._validated_parameters, alias_warnings, alias_deprecations) except (TypeError, ValueError) as e: alias_results = {} legal_inputs = None self._add_error(to_native(e)) for option, alias in alias_warnings: warn('Both option %s and its alias %s are set.' % (option, alias)) for deprecation in alias_deprecations: deprecate("Alias '%s' is deprecated. See the module docs for more information" % deprecation['name'], version=deprecation.get('version'), date=deprecation.get('date'), collection_name=deprecation.get('collection_name')) self._no_log_values.update(list_no_log_values(self.argument_spec, self._validated_parameters)) if legal_inputs is None: legal_inputs = list(alias_results.keys()) + list(self.argument_spec.keys()) self._unsupported_parameters.update(get_unsupported_parameters(self.argument_spec, self._validated_parameters, legal_inputs)) self._no_log_values.update(set_defaults(self.argument_spec, self._validated_parameters, False)) try: check_required_arguments(self.argument_spec, self._validated_parameters) except TypeError as e: self._add_error(to_native(e)) validate_argument_types(self.argument_spec, self._validated_parameters, errors=self._error_messages) validate_argument_values(self.argument_spec, self._validated_parameters, errors=self._error_messages) self._no_log_values.update(set_defaults(self.argument_spec, self._validated_parameters)) validate_sub_spec(self.argument_spec, self._validated_parameters, errors=self._error_messages, no_log_values=self._no_log_values, unsupported_parameters=self._unsupported_parameters) if self._unsupported_parameters: self._add_error('Unsupported parameters: %s' % ', '.join(sorted(list(self._unsupported_parameters)))) self._sanitize_error_messages() if self.error_messages: return False else: return True