<commit_before>from __future__ import absolute_import, division, print_function

import functools
import inspect
import os
import sys
import warnings
from collections import OrderedDict, deque, defaultdict

import six
from more_itertools import flatten

import attr
import py
from py._code.code import FormattedExcinfo

import _pytest
from _pytest import nodes
from _pytest._code.code import TerminalRepr
from _pytest.compat import (
    NOTSET,
    exc_clear,
    _format_args,
    getfslineno,
    get_real_func,
    is_generator,
    isclass,
    getimfunc,
    getlocation,
    getfuncargnames,
    safe_getattr,
    FuncargnamesCompatAttr,
    get_real_method,
    _PytestWrapper,
)
from _pytest.deprecated import FIXTURE_FUNCTION_CALL, RemovedInPytest4Warning
from _pytest.outcomes import fail, TEST_OUTCOME

FIXTURE_MSG = 'fixtures cannot have "pytest_funcarg__" prefix and be decorated with @pytest.fixture:\n{}'


@attr.s(frozen=True)
class PseudoFixtureDef(object):
    cached_result = attr.ib()
    scope = attr.ib()


def pytest_sessionstart(session):
    import _pytest.python
    import _pytest.nodes

    scopename2class.update(
        {
            "package": _pytest.python.Package,
            "class": _pytest.python.Class,
            "module": _pytest.python.Module,
            "function": _pytest.nodes.Item,
            "session": _pytest.main.Session,
        }
    )
    session._fixturemanager = FixtureManager(session)


scopename2class = {}


scope2props = dict(session=())
scope2props["package"] = ("fspath",)
scope2props["module"] = ("fspath", "module")
scope2props["class"] = scope2props["module"] + ("cls",)
scope2props["instance"] = scope2props["class"] + ("instance",)
scope2props["function"] = scope2props["instance"] + ("function", "keywords")


def scopeproperty(name=None, doc=None):
    def decoratescope(func):
        scopename = name or func.__name__

        def provide(self):
            if func.__name__ in scope2props[self.scope]:
                return func(self)
            raise AttributeError(
                "%s not available in %s-scoped context" % (scopename, self.scope)
            )

        return property(provide, None, None, func.__doc__)

    return decoratescope


def get_scope_package(node, fixturedef):
    import pytest

    cls = pytest.Package
    current = node
    fixture_package_name = os.path.join(fixturedef.baseid, "__init__.py")
    while current and (
        type(current) is not cls or fixture_package_name != current.nodeid
    ):
        current = current.parent
    if current is None:
        return node.session
    return current
<commit_msg>Fix the package fixture ordering in Windows.<commit_after>from __future__ import absolute_import, division, print_function

import functools
import inspect
import os
import sys
import warnings
from collections import OrderedDict, deque, defaultdict

import six
from more_itertools import flatten

import attr
import py
from py._code.code import FormattedExcinfo

import _pytest
from _pytest import nodes
from _pytest._code.code import TerminalRepr
from _pytest.compat import (
    NOTSET,
    exc_clear,
    _format_args,
    getfslineno,
    get_real_func,
    is_generator,
    isclass,
    getimfunc,
    getlocation,
    getfuncargnames,
    safe_getattr,
    FuncargnamesCompatAttr,
    get_real_method,
    _PytestWrapper,
)
from _pytest.deprecated import FIXTURE_FUNCTION_CALL, RemovedInPytest4Warning
from _pytest.outcomes import fail, TEST_OUTCOME

FIXTURE_MSG = 'fixtures cannot have "pytest_funcarg__" prefix and be decorated with @pytest.fixture:\n{}'


@attr.s(frozen=True)
class PseudoFixtureDef(object):
    cached_result = attr.ib()
    scope = attr.ib()


def pytest_sessionstart(session):
    import _pytest.python
    import _pytest.nodes

    scopename2class.update(
        {
            "package": _pytest.python.Package,
            "class": _pytest.python.Class,
            "module": _pytest.python.Module,
            "function": _pytest.nodes.Item,
            "session": _pytest.main.Session,
        }
    )
    session._fixturemanager = FixtureManager(session)


scopename2class = {}


scope2props = dict(session=())
scope2props["package"] = ("fspath",)
scope2props["module"] = ("fspath", "module")
scope2props["class"] = scope2props["module"] + ("cls",)
scope2props["instance"] = scope2props["class"] + ("instance",)
scope2props["function"] = scope2props["instance"] + ("function", "keywords")


def scopeproperty(name=None, doc=None):
    def decoratescope(func):
        scopename = name or func.__name__

        def provide(self):
            if func.__name__ in scope2props[self.scope]:
                return func(self)
            raise AttributeError(
                "%s not available in %s-scoped context" % (scopename, self.scope)
            )

        return property(provide, None, None, func.__doc__)

    return decoratescope


def get_scope_package(node, fixturedef):
    import pytest

    cls = pytest.Package
    current = node
    fixture_package_name = "%s/%s" % (fixturedef.baseid, "__init__.py")
    while current and (
        type(current) is not cls or fixture_package_name != current.nodeid
    ):
        current = current.parent
    if current is None:
        return node.session
    return current

{'fraction_non_alphanumeric': 0.09503117324768562, 'fraction_numerical': 0.0049121481201587006, 'mean_word_length': 3.364385820280297, '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': '6309093', 'n_tokens_mistral': 1638, 'n_tokens_neox': 1661, 'n_words': 397}