<commit_before>import unittest
import allbase.args as args
from collections import namedtuple
import allbase.base as base


class TestArgs(unittest.TestCase):

    def test_parse(self):

        fix = namedtuple('fix', 'input num bases valid reason')
        tests = [
            fix(
                input=[],
                num=None,
                bases=None,
                valid=False,
                reason='no input arguments'
            ),
            fix(
                input=['12'],
                num=12,
                bases=[base.dec, base.hex, base.oct, base.bin],
                valid=True,
                reason=None
            ),
            fix(
                input=['12', '-b', 'd'],
                num=12,
                bases=[base.dec],
                valid=True,
                reason=None
            ),
            fix(
                input=['12', '-b', 'doob'],
                num=12,
                bases=[base.dec, base.oct, base.oct, base.bin],
                valid=True,
                reason=None
            ),
            fix(
                input=['12', '-b', 'doaob'],
                num=12,
                bases=None,
                valid=False,
                reason="unknown base: 'a'",
            ),
            fix(
                input=['asdf'],
                num=None,
                bases=None,
                valid=False,
                reason="not a number: 'asdf'"
            ),
            fix(
                input=[' '],
                num=None,
                bases=None,
                valid=False,
                reason="not a number: ' '"
            ),
            fix(
                input=['-12'],
                num=None,
                bases=None,
                valid=False,
                reason='negative numbers are not allowed: -12'
            ),
            fix(
                input=['12.1'],
                num=None,
                bases=None,
                valid=False,
                reason='floating point numbers are not allowed: 12.1'
            ),
            fix(
                input=['12.0'],
                num=None,
                bases=None,
                valid=False,
                reason='floating point numbers are not allowed: 12.0'
            ),
        ]

        for i, t in enumerate(tests):
            num, bases, valid, reason = args.parse(t.input)

            template = "subtest {0}):\n\tinput = {1!r}\n\t"\
                "num\n\t\texpected={2}\n\t\tobtained={3}\n\t"\
                "bases\n\t\texpected={4}\n\t\tobtained={5}\n\t"\
                "valid\n\t\texpected={6}\n\t\tobtained={7}\n\t"\
                "reason\n\t\texpected={8!r}\n\t\tobtained={9!r}\n\t"
            comment = template.format(i, t.input,
                                      t.num, num,
                                      t.bases, bases,
                                      t.valid, valid,
                                      t.reason, reason)

            self.assertEqual(num, t.num, comment)
            self.assertEqual(bases, t.bases, comment)
            self.assertEqual(valid, t.valid, comment)
            self.assertEqual(reason, t.reason, comment)<commit_msg>simplify error for wrong input number<commit_after>import unittest
import allbase.args as args
from collections import namedtuple
import allbase.base as base


class TestArgs(unittest.TestCase):

    def test_parse(self):

        fix = namedtuple('fix', 'input num bases valid reason')
        tests = [
            fix(
                input=[],
                num=None,
                bases=None,
                valid=False,
                reason='no input arguments'
            ),
            fix(
                input=['12'],
                num=12,
                bases=[base.dec, base.hex, base.oct, base.bin],
                valid=True,
                reason=None
            ),
            fix(
                input=['12', '-b', 'd'],
                num=12,
                bases=[base.dec],
                valid=True,
                reason=None
            ),
            fix(
                input=['12', '-b', 'doob'],
                num=12,
                bases=[base.dec, base.oct, base.oct, base.bin],
                valid=True,
                reason=None
            ),
            fix(
                input=['12', '-b', 'doaob'],
                num=12,
                bases=None,
                valid=False,
                reason="unknown base: 'a'",
            ),
            fix(
                input=['asdf'],
                num=None,
                bases=None,
                valid=False,
                reason="need a positive integer, got 'asdf'"
            ),
            fix(
                input=[' '],
                num=None,
                bases=None,
                valid=False,
                reason="need a positive integer, got ' '"
            ),
            fix(
                input=['-12'],
                num=None,
                bases=None,
                valid=False,
                reason="need a positive integer, got '-12'"
            ),
            fix(
                input=['12.1'],
                num=None,
                bases=None,
                valid=False,
                reason="need a positive integer, got '12.1'"
            ),
            fix(
                input=['12.0'],
                num=None,
                bases=None,
                valid=False,
                reason="need a positive integer, got '12.0'"
            ),
        ]

        for i, t in enumerate(tests):
            num, bases, valid, reason = args.parse(t.input)

            template = "subtest {0}):\n\tinput = {1!r}\n\t"\
                "num\n\t\texpected={2}\n\t\tobtained={3}\n\t"\
                "bases\n\t\texpected={4}\n\t\tobtained={5}\n\t"\
                "valid\n\t\texpected={6}\n\t\tobtained={7}\n\t"\
                "reason\n\t\texpected={8!r}\n\t\tobtained={9!r}\n\t"
            comment = template.format(i, t.input,
                                      t.num, num,
                                      t.bases, bases,
                                      t.valid, valid,
                                      t.reason, reason)

            self.assertEqual(num, t.num, comment)
            self.assertEqual(bases, t.bases, comment)
            self.assertEqual(valid, t.valid, comment)
            self.assertEqual(reason, t.reason, comment)
{'fraction_non_alphanumeric': 0.1231626179792666, 'fraction_numerical': 0.012997060188766826, 'mean_word_length': 0.9599757428744694, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5032619', 'n_tokens_mistral': 1838, 'n_tokens_neox': 1695, 'n_words': 336}