<commit_before>import sys

sys.path.insert(0, ".")
import unittest
from coalib.settings.FunctionMetadata import FunctionMetadata
from coalib.settings.Section import Section
from coalib.settings.Setting import Setting


class TestClass:

    def __init__(self, param1, param2, param3=5, param4: int=6):
        """
        Description

        :param param2: d
        :param param4: p4 desc
        :return:       ret
        """

    def good_function(self, a_param: int):
        pass

    def bad_function(self, bad_param: "no function"):
        pass


class FunctionMetadataTest(unittest.TestCase):

    def test_construction(self):
        self.check_function_metadata_data_set(FunctionMetadata("name"), "name")

    def test_from_function(self):
        uut = FunctionMetadata.from_function(self.test_from_function)
        self.check_function_metadata_data_set(uut, "test_from_function")
        # setattr on bound methods will fail, __dict__ will use the dict from
        # the unbound method which is ok.
        self.test_from_function.__dict__["__metadata__"] = (
            FunctionMetadata("t"))
        uut = FunctionMetadata.from_function(self.test_from_function)
        self.check_function_metadata_data_set(uut, "t")

        uut = FunctionMetadata.from_function(TestClass(5, 5).__init__)
        self.check_function_metadata_data_set(
            uut,
            "__init__",
            desc="Description",
            retval_desc="ret",
            non_optional_params={
                "param1": (uut.str_nodesc, None),
                "param2": ("d", None)<commit_msg>codestyle: Use builtin vars() instead of __dict__<commit_after>import sys

sys.path.insert(0, ".")
import unittest
from coalib.settings.FunctionMetadata import FunctionMetadata
from coalib.settings.Section import Section
from coalib.settings.Setting import Setting


class TestClass:

    def __init__(self, param1, param2, param3=5, param4: int=6):
        """
        Description

        :param param2: d
        :param param4: p4 desc
        :return:       ret
        """

    def good_function(self, a_param: int):
        pass

    def bad_function(self, bad_param: "no function"):
        pass


class FunctionMetadataTest(unittest.TestCase):

    def test_construction(self):
        self.check_function_metadata_data_set(FunctionMetadata("name"), "name")

    def test_from_function(self):
        uut = FunctionMetadata.from_function(self.test_from_function)
        self.check_function_metadata_data_set(uut, "test_from_function")
        # setattr on bound methods will fail, vars() will use the dict from
        # the unbound method which is ok.
        vars(self.test_from_function)["__metadata__"] = (
            FunctionMetadata("t"))
        uut = FunctionMetadata.from_function(self.test_from_function)
        self.check_function_metadata_data_set(uut, "t")

        uut = FunctionMetadata.from_function(TestClass(5, 5).__init__)
        self.check_function_metadata_data_set(
            uut,
            "__init__",
            desc="Description",
            retval_desc="ret",
            non_optional_params={
                "param1": (uut.str_nodesc, None),
                "param2": ("d", None)
{'fraction_non_alphanumeric': 0.09568188878533707, 'fraction_numerical': 0.008698353525939733, 'mean_word_length': 2.8333333333333335, 'pattern_counts': {'":': 4, '<': 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': '7477874', 'n_tokens_mistral': 941, 'n_tokens_neox': 920, 'n_words': 201}