<commit_before># Licensed under a 3-clause BSD style license - see LICENSE.rst

import functools
import inspect
import pickle

import pytest

from astropy.utils.decorators import (deprecated_attribute, deprecated, wraps,
                                      sharedmethod, classproperty,
                                      format_doc, deprecated_renamed_argument)
from astropy.utils.exceptions import AstropyDeprecationWarning, AstropyUserWarning
from astropy.tests.helper import catch_warnings


class NewDeprecationWarning(AstropyDeprecationWarning):
    """
    New Warning subclass to be used to test the deprecated decorator's
    ``warning_type`` parameter.
    """


def test_wraps():
    """
    Tests the compatibility replacement for functools.wraps which supports
    argument preservation across all supported Python versions.
    """

    def foo(a, b, c=1, d=2, e=3, **kwargs):
        """A test function."""

        return a, b, c, d, e, kwargs

    @wraps(foo)
    def bar(*args, **kwargs):
        return ('test',) + foo(*args, **kwargs)

    expected = ('test', 1, 2, 3, 4, 5, {'f': 6, 'g': 7})
    assert bar(1, 2, 3, 4, 5, f=6, g=7) == expected
    assert bar.__name__ == 'foo'

    if foo.__doc__ is not None:
        # May happen if using optimized opcode
        assert bar.__doc__ == "A test function."

    if hasattr(foo, '__qualname__'):
        assert bar.__qualname__ == foo.__qualname__

    argspec = inspect.getfullargspec(bar)
    assert argspec.varkw == 'kwargs'

    assert argspec.args == ['a', 'b', 'c', 'd', 'e']
    assert argspec.defaults == (1, 2, 3)


def test_deprecated_attribute():
    class DummyClass:<commit_msg>Fix one of the utils test<commit_after># Licensed under a 3-clause BSD style license - see LICENSE.rst

import functools
import inspect
import pickle

import pytest

from astropy.utils.decorators import (deprecated_attribute, deprecated, wraps,
                                      sharedmethod, classproperty,
                                      format_doc, deprecated_renamed_argument)
from astropy.utils.exceptions import AstropyDeprecationWarning, AstropyUserWarning
from astropy.tests.helper import catch_warnings


class NewDeprecationWarning(AstropyDeprecationWarning):
    """
    New Warning subclass to be used to test the deprecated decorator's
    ``warning_type`` parameter.
    """


def test_wraps():
    """
    Tests the compatibility replacement for functools.wraps which supports
    argument preservation across all supported Python versions.
    """

    def foo(a, b, c=1, d=2, e=3, **kwargs):
        """A test function."""

        return a, b, c, d, e, kwargs

    @wraps(foo)
    def bar(*args, **kwargs):
        return ('test',) + foo(*args, **kwargs)

    expected = ('test', 1, 2, 3, 4, 5, {'f': 6, 'g': 7})
    assert bar(1, 2, 3, 4, 5, f=6, g=7) == expected
    assert bar.__name__ == 'foo'

    if foo.__doc__ is not None:
        # May happen if using optimized opcode
        assert bar.__doc__ == "A test function."

    if hasattr(foo, '__qualname__'):
        assert bar.__qualname__ == foo.__qualname__

    sig = inspect.signature(bar)
    assert list(sig.parameters) == ['a', 'b', 'c', 'd', 'e', 'kwargs']

    defaults = [inspect._empty, inspect._empty, 1, 2, 3, inspect._empty]
    assert [p.default for p in sig.parameters.values()] == defaults


def test_deprecated_attribute():
    class DummyClass:
{'fraction_non_alphanumeric': 0.11518171160609614, 'fraction_numerical': 0.0123094958968347, 'mean_word_length': 2.954808806488992, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3090077', 'n_tokens_mistral': 1074, 'n_tokens_neox': 1012, 'n_words': 331}