<commit_before>from __future__ import print_function
from functools import wraps
from functools import partial

import imp
import sys
import pytest
# import pytest.runner

from compat import PY2, PY3, exec_

PYPY = '__pypy__' in sys.builtin_module_names

OBJECTS_CODE = """
class TargetBaseClass(object):
    "documentation"

class Target(TargetBaseClass):
    "documentation"

def target():
    "documentation"
    pass
"""

objects = imp.new_module('objects')
exec_(OBJECTS_CODE, objects.__dict__, objects.__dict__)


def load_implementation(name):
    class mod:
        type = name
        if name == "slots":
            from lazy_object_proxy.slots import Proxy
        elif name == "simple":
            from lazy_object_proxy.simple import Proxy
        elif name == "cext":
            try:
                from lazy_object_proxy.cext import Proxy
            except ImportError:
                if PYPY:
                    pytest.skip(msg="C Extension not available.")
                else:
                    raise
        elif name == "objproxies":
            Proxy = pytest.importorskip("objproxies").LazyProxy
        elif name == "django":
            Proxy = pytest.importorskip("django.utils.functional").SimpleLazyObject
        else:
            raise RuntimeError("Unsupported param: %r." % name)
    return mod


@pytest.fixture(scope="module", params=[
    "slots", "cext",
    "simple",
    # "external-django", "external-objproxies"
])
def lazy_object_proxy(request):
    return load_implementation(request.param)


def xfail_simple(test_func):
    from lazy_object_proxy.simple import Proxy
    @wraps(test_func)
    def xfail_wrapper(lazy_object_proxy):
        if lazy_object_proxy.Proxy is Proxy:
            pytest.xfail(reason="The lazy_object_proxy.simple.Proxy has some limitations.")
    return xfail_wrapper


def test_attributes(lazy_object_proxy):
    def function1(*args, **kwargs):
        return args, kwargs

    function2 = lazy_object_proxy.Proxy(lambda: function1)

    assert function2.__wrapped__ == function1


def test_get_wrapped(lazy_object_proxy):
    def function1(*args, **kwargs):
        return args, kwargs

    function2 = lazy_object_proxy.Proxy(lambda: function1)

    assert function2.__wrapped__ == function1

    function3 = lazy_object_proxy.Proxy(lambda: function2)

    assert function3.__wrapped__ == function1

def test_set_wrapped(lazy_object_proxy):
    def function1(*args, **kwargs):
        return args, kwargs

    function2 = lazy_object_proxy.Proxy(lambda: function1)

    assert function2 == function1
    assert function2.__wrapped__ is function1
    assert function2.__name__ == function1.__name__

    if PY3:
        assert function2.__qualname__ == function1.__qualname__

    function2.__wrapped__ = None

    if lazy_object_proxy.type != 'simple':
        assert not hasattr(function1, '__wrapped__')<commit_msg>Wasn't necessary.<commit_after>from __future__ import print_function
from functools import wraps
from functools import partial

import imp
import sys
import pytest
# import pytest.runner

from compat import PY2, PY3, exec_

PYPY = '__pypy__' in sys.builtin_module_names

OBJECTS_CODE = """
class TargetBaseClass(object):
    "documentation"

class Target(TargetBaseClass):
    "documentation"

def target():
    "documentation"
    pass
"""

objects = imp.new_module('objects')
exec_(OBJECTS_CODE, objects.__dict__, objects.__dict__)


def load_implementation(name):
    class mod:
        type = name
        if name == "slots":
            from lazy_object_proxy.slots import Proxy
        elif name == "simple":
            from lazy_object_proxy.simple import Proxy
        elif name == "cext":
            try:
                from lazy_object_proxy.cext import Proxy
            except ImportError:
                if PYPY:
                    pytest.skip(msg="C Extension not available.")
                else:
                    raise
        elif name == "objproxies":
            Proxy = pytest.importorskip("objproxies").LazyProxy
        elif name == "django":
            Proxy = pytest.importorskip("django.utils.functional").SimpleLazyObject
        else:
            raise RuntimeError("Unsupported param: %r." % name)
    return mod


@pytest.fixture(scope="module", params=[
    "slots", "cext",
    "simple",
    # "external-django", "external-objproxies"
])
def lazy_object_proxy(request):
    return load_implementation(request.param)


def xfail_simple(test_func):
    from lazy_object_proxy.simple import Proxy
    @wraps(test_func)
    def xfail_wrapper(lazy_object_proxy):
        if lazy_object_proxy.Proxy is Proxy:
            pytest.xfail(reason="The lazy_object_proxy.simple.Proxy has some limitations.")
    return xfail_wrapper


def test_attributes(lazy_object_proxy):
    def function1(*args, **kwargs):
        return args, kwargs

    function2 = lazy_object_proxy.Proxy(lambda: function1)

    assert function2.__wrapped__ == function1


def test_get_wrapped(lazy_object_proxy):
    def function1(*args, **kwargs):
        return args, kwargs

    function2 = lazy_object_proxy.Proxy(lambda: function1)

    assert function2.__wrapped__ == function1

    function3 = lazy_object_proxy.Proxy(lambda: function2)

    assert function3.__wrapped__ == function1

def test_set_wrapped(lazy_object_proxy):
    def function1(*args, **kwargs):
        return args, kwargs

    function2 = lazy_object_proxy.Proxy(lambda: function1)

    assert function2 == function1
    assert function2.__wrapped__ is function1
    assert function2.__name__ == function1.__name__

    if PY3:
        assert function2.__qualname__ == function1.__qualname__

    function2.__wrapped__ = None

    assert not hasattr(function1, '__wrapped__')
{'fraction_non_alphanumeric': 0.08833246391931839, 'fraction_numerical': 0.010432968179447054, 'mean_word_length': 3.0910384068278804, 'pattern_counts': {'":': 10, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4417461', 'n_tokens_mistral': 1727, 'n_tokens_neox': 1689, 'n_words': 401}