<commit_before>import inspect

from pyinstrument.low_level import stat_profile as stat_profile_c
from pyinstrument.low_level import stat_profile_python


class AClass:
    def get_frame_info_for_a_method(self, getter_function):
        frame = inspect.currentframe()
        assert frame
        return getter_function(frame)

    def get_frame_info_with_cell_variable(self, getter_function):
        frame = inspect.currentframe()
        assert frame

        def an_inner_function():
            # reference self to make it a cell variable
            if self:
                pass

        return getter_function(frame)

    @classmethod
    def get_frame_info_for_a_class_method(cls, getter_function):
        frame = inspect.currentframe()
        assert frame
        return getter_function(frame)


def test_frame_info():
    frame = inspect.currentframe()

    assert frame
    assert stat_profile_c.get_frame_info(frame) == stat_profile_python.get_frame_info(frame)


def test_frame_info_with_classes():
    instance = AClass()

    test_functions = [
        instance.get_frame_info_for_a_method,
        AClass.get_frame_info_for_a_class_method,
        instance.get_frame_info_with_cell_variable,
    ]

    for test_function in test_functions:
        assert test_function(stat_profile_c.get_frame_info) == test_function(
            stat_profile_python.get_frame_info
        )<commit_msg>test correct `__tracebackhide__==True` behavior in `test_frame_info.py`<commit_after>import inspect

from pyinstrument.low_level import stat_profile as stat_profile_c
from pyinstrument.low_level import stat_profile_python


class AClass:
    def get_frame_info_for_a_method(self, getter_function):
        __tracebackhide__ = True

        frame = inspect.currentframe()
        assert frame
        return getter_function(frame)

    def get_frame_info_with_cell_variable(self, getter_function):
        __tracebackhide__ = True

        frame = inspect.currentframe()
        assert frame

        def an_inner_function():
            # reference self to make it a cell variable
            if self:
                pass

        return getter_function(frame)

    @classmethod
    def get_frame_info_for_a_class_method(cls, getter_function):
        frame = inspect.currentframe()
        assert frame
        return getter_function(frame)


def test_frame_info():
    frame = inspect.currentframe()

    assert frame
    assert stat_profile_c.get_frame_info(frame) == stat_profile_python.get_frame_info(frame)


def test_frame_info_with_classes():
    instance = AClass()

    test_functions = [
        instance.get_frame_info_for_a_method,
        AClass.get_frame_info_for_a_class_method,
        instance.get_frame_info_with_cell_variable,
    ]

    for test_function in test_functions:
        c_frame_info = test_function(stat_profile_c.get_frame_info)
        py_frame_info = test_function(stat_profile_python.get_frame_info)

        assert c_frame_info == py_frame_info
{'fraction_non_alphanumeric': 0.057917643120187476, 'fraction_numerical': 0.0, 'mean_word_length': 3.2685714285714287, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3810743', 'n_tokens_mistral': 901, 'n_tokens_neox': 874, 'n_words': 172}