<commit_before>from __future__ import print_function

import imp
import pickle
import platform
import sys
import weakref
from datetime import date
from datetime import datetime
from decimal import Decimal
from functools import partial
import gc

import pytest

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 FakeModule:
        subclass = False
        kind = 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)

        Proxy

    return FakeModule


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


@pytest.fixture(scope="module", params=[True, False], ids=['subclassed', 'normal'])
def lop_subclass(request, lop_implementation):
    if request.param:
        class submod(lop_implementation):
            subclass = True
            Proxy = type("SubclassOf_" + lop_implementation.Proxy.__name__,
                         (lop_implementation.Proxy,), {})

        return submod
    else:
        return lop_implementation


@pytest.fixture(scope="function")
def lazy_object_proxy(request, lop_subclass):
    if request.node.get_marker('xfail_subclass'):
        request.applymarker(pytest.mark.xfail(
            reason="This test can't work because subclassing disables certain "
                   "features like __doc__ and __module__ proxying."
        ))
    if request.node.get_marker('xfail_simple'):
        request.applymarker(pytest.mark.xfail(
            reason="The lazy_object_proxy.simple.Proxy has some limitations."
        ))

    return lop_subclass


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
<commit_msg>Add a test for __round__.<commit_after>from __future__ import print_function

import imp
import pickle
import platform
import sys
import weakref
from datetime import date
from datetime import datetime
from decimal import Decimal
from functools import partial
import gc

import pytest

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 FakeModule:
        subclass = False
        kind = 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)

        Proxy

    return FakeModule


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


@pytest.fixture(scope="module", params=[True, False], ids=['subclassed', 'normal'])
def lop_subclass(request, lop_implementation):
    if request.param:
        class submod(lop_implementation):
            subclass = True
            Proxy = type("SubclassOf_" + lop_implementation.Proxy.__name__,
                         (lop_implementation.Proxy,), {})

        return submod
    else:
        return lop_implementation


@pytest.fixture(scope="function")
def lazy_object_proxy(request, lop_subclass):
    if request.node.get_marker('xfail_subclass'):
        request.applymarker(pytest.mark.xfail(
            reason="This test can't work because subclassing disables certain "
                   "features like __doc__ and __module__ proxying."
        ))
    if request.node.get_marker('xfail_simple'):
        request.applymarker(pytest.mark.xfail(
            reason="The lazy_object_proxy.simple.Proxy has some limitations."
        ))

    return lop_subclass


def test_round(lazy_object_proxy):
    proxy = lazy_object_proxy.Proxy(lambda: 1.2)
    assert round(proxy) == 1


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

{'fraction_non_alphanumeric': 0.09297757407104272, 'fraction_numerical': 0.003110165329841218, 'mean_word_length': 2.8283208020050123, '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': '1056335', 'n_tokens_mistral': 1801, 'n_tokens_neox': 1741, 'n_words': 424}