<commit_before>from collections import namedtuple
import unittest

from parse_this import create_parser, parse_class
from test.utils import captured_output
from parse_this.core import (
    _get_args_and_defaults,
    NoDefault,
    _get_default_help_message,
    Self,
    _get_parseable_methods,
    Class,
    _prepare_doc,
    _get_arg_parser,
    _get_args_to_parse,
    ParseThisError,
    _check_types,
    _get_parser_call_method,
    _call,
    _call_method_from_namespace,
)


def no_docstring():
    pass


def with_args(a, b):
    pass


@parse_class()
class Parseable(object):
    @create_parser(Self, int)
    def __init__(self, a):
        self._a = a

    @create_parser(Self, int)
    def _private_method(self, b):
        return self._a * b

    def not_parseable(self, c):
        return self._a * c

    @create_parser(Self, int)
    def parseable(self, d):
        return self._a * d

    @classmethod
    @create_parser(Class, int)
    def cls_method(cls, e):
        return e * e


@parse_class(parse_private=True)
class ParseableWithPrivateMethod(object):
    @create_parser(Self, int)
    def __init__(self, a):
        self._a = a

    @create_parser(Self, int)
    def _private_method(self, b):
        return self._a * b

    def not_parseable(self, c):
        return self._a * c

    @create_parser(Self, int)
    def parseable(self, d):
        return self._a * d

    @classmethod
    @create_parser(Class, int)
    def cls_method(cls, e):
        return e * e


def blank_line_in_wrong_place(one, two):
    """I put the blank line after arguments ...

    Args:
        one: this help is #1

        two: this once won't appear sadly
    """
    return one * two


def parse_me_full_docstring(one, two, three=12):
    """Could use some parsing.

    Args:
        one: some stuff shouldn't be written down
        two: I can turn 2 syllables words into 6 syllables words
        three: I don't like the number three

    Returns:
        the first string argument concatenated with itself 'two' times and the
        last parameters multiplied by itself
    """
    return one * two, three * three


def parse_me_no_docstring(one, two, three):
    return one * two, three * three


def multiline_docstring(one, two, three):
    """I am a sneaky function.

    Args:
        one: this one is a no brainer
        three: noticed you're missing docstring for two and
          I'm multiline too!

    Returns:
        the first string argument concatenated with itself 'two' times and the
        last parameters multiplied by itself
    """
    return one * two, three * three


def different_delimiter_charsiter(one, two, three):
    """I am a sneaky function.

    Args:
        one -- this one is a no brainer even with dashes
        three -- noticed you're missing docstring for two and
          I'm multiline too!

    Returns:
        the first string argument concatenated with itself 'two' times and the
        last parameters multiplied by itself
    """
    return one * two, three * three


@create_parser(str, int)
def concatenate_string(string, nb_concat):
    return string * nb_concat


@create_parser(int, str)
def has_none_default_value(a, b=None):
    return a, b


@create_parser(int)
def has_flags(a, b=False):
    return a, b


@create_parser(bool)
def has_bool_arguments(a):
    return a


class TestCore(unittest.TestCase):
    def test_get_args_and_defaults_fill_no_default(self):
        args_and_defaults = _get_args_and_defaults(
            ["first", "second", "third"], ("default_value",)
        )
        self.assertListEqual(
            args_and_defaults,
            [("first", NoDefault), ("second", NoDefault), ("third", "default_value")],
        )

    def test_get_args_and_defaults_no_args(self):
        self.assertListEqual(_get_args_and_defaults([], ()), [])

    def test_get_args_and_defaults_no_default(self):
        self.assertListEqual(
            _get_args_and_defaults(["first", "second"], ()),
            [("first", NoDefault), ("second", NoDefault)],
        )

    def test_get_default_help_message_no_docstring(self):
        (description, _) = _get_default_help_message(no_docstring, [])
        self.assertIsNotNone(description)
        self.assertIn(no_docstring.__name__, description)

    def test_get_default_help_message_add_default_args_help(self):
        (_, args_help) = _get_default_help_message(with_args, ["a", "b"])
        self.assertListEqual(sorted(list(args_help.keys())), ["a", "b"])
        (_, args_help) = _get_default_help_message(
            with_args, ["a", "b"], None, {"a": "I have an help message"}
        )
        self.assertListEqual(sorted(list(args_help.keys())), ["a", "b"])
<commit_msg>Add test for uncovered method<commit_after>from collections import namedtuple
import unittest

from parse_this import create_parser, parse_class
from test.utils import captured_output
from parse_this.core import (
    _get_args_and_defaults,
    NoDefault,
    _get_default_help_message,
    Self,
    _get_parseable_methods,
    Class,
    _prepare_doc,
    _get_arg_parser,
    _get_args_to_parse,
    ParseThisError,
    _check_types,
    _get_parser_call_method,
    _call,
    _call_method_from_namespace,
    identity_type,
)


def no_docstring():
    pass


def with_args(a, b):
    pass


@parse_class()
class Parseable(object):
    @create_parser(Self, int)
    def __init__(self, a):
        self._a = a

    @create_parser(Self, int)
    def _private_method(self, b):
        return self._a * b

    def not_parseable(self, c):
        return self._a * c

    @create_parser(Self, int)
    def parseable(self, d):
        return self._a * d

    @classmethod
    @create_parser(Class, int)
    def cls_method(cls, e):
        return e * e


@parse_class(parse_private=True)
class ParseableWithPrivateMethod(object):
    @create_parser(Self, int)
    def __init__(self, a):
        self._a = a

    @create_parser(Self, int)
    def _private_method(self, b):
        return self._a * b

    def not_parseable(self, c):
        return self._a * c

    @create_parser(Self, int)
    def parseable(self, d):
        return self._a * d

    @classmethod
    @create_parser(Class, int)
    def cls_method(cls, e):
        return e * e


def blank_line_in_wrong_place(one, two):
    """I put the blank line after arguments ...

    Args:
        one: this help is #1

        two: this once won't appear sadly
    """
    return one * two


def parse_me_full_docstring(one, two, three=12):
    """Could use some parsing.

    Args:
        one: some stuff shouldn't be written down
        two: I can turn 2 syllables words into 6 syllables words
        three: I don't like the number three

    Returns:
        the first string argument concatenated with itself 'two' times and the
        last parameters multiplied by itself
    """
    return one * two, three * three


def parse_me_no_docstring(one, two, three):
    return one * two, three * three


def multiline_docstring(one, two, three):
    """I am a sneaky function.

    Args:
        one: this one is a no brainer
        three: noticed you're missing docstring for two and
          I'm multiline too!

    Returns:
        the first string argument concatenated with itself 'two' times and the
        last parameters multiplied by itself
    """
    return one * two, three * three


def different_delimiter_charsiter(one, two, three):
    """I am a sneaky function.

    Args:
        one -- this one is a no brainer even with dashes
        three -- noticed you're missing docstring for two and
          I'm multiline too!

    Returns:
        the first string argument concatenated with itself 'two' times and the
        last parameters multiplied by itself
    """
    return one * two, three * three


@create_parser(str, int)
def concatenate_string(string, nb_concat):
    return string * nb_concat


@create_parser(int, str)
def has_none_default_value(a, b=None):
    return a, b


@create_parser(int)
def has_flags(a, b=False):
    return a, b


@create_parser(bool)
def has_bool_arguments(a):
    return a


class TestCore(unittest.TestCase):
    def test_identity_type(self):
        self.assertEqual(None, identity_type(None))

    def test_get_args_and_defaults_fill_no_default(self):
        args_and_defaults = _get_args_and_defaults(
            ["first", "second", "third"], ("default_value",)
        )
        self.assertListEqual(
            args_and_defaults,
            [("first", NoDefault), ("second", NoDefault), ("third", "default_value")],
        )

    def test_get_args_and_defaults_no_args(self):
        self.assertListEqual(_get_args_and_defaults([], ()), [])

    def test_get_args_and_defaults_no_default(self):
        self.assertListEqual(
            _get_args_and_defaults(["first", "second"], ()),
            [("first", NoDefault), ("second", NoDefault)],
        )

    def test_get_default_help_message_no_docstring(self):
        (description, _) = _get_default_help_message(no_docstring, [])
        self.assertIsNotNone(description)
        self.assertIn(no_docstring.__name__, description)

    def test_get_default_help_message_add_default_args_help(self):
        (_, args_help) = _get_default_help_message(with_args, ["a", "b"])
        self.assertListEqual(sorted(list(args_help.keys())), ["a", "b"])
        (_, args_help) = _get_default_help_message(
            with_args, ["a", "b"], None, {"a": "I have an help message"}
        )
        self.assertListEqual(sorted(list(args_help.keys())), ["a", "b"])

{'fraction_non_alphanumeric': 0.09882747068676717, 'fraction_numerical': 0.0010469011725293131, 'mean_word_length': 2.937757625721352, 'pattern_counts': {'":': 2, '<': 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': '1631358', 'n_tokens_mistral': 3088, 'n_tokens_neox': 2971, 'n_words': 815}