Ejemplo n.º 1
0
def test_attr_parser_args_value_from_str():
    assert AttrParserArgs.value_from_str('PRVSNR_NONE') is None
    assert AttrParserArgs.value_from_str('["1", "2", "3"]',
                                         v_type=List) == ['1', '2', '3']
    assert AttrParserArgs.value_from_str('["1", "2", "3"]',
                                         v_type='json') == ['1', '2', '3']
    assert AttrParserArgs.value_from_str('{"1": 2}', v_type='json') == {'1': 2}
Ejemplo n.º 2
0
def test_inputs_AttrParserArgs_type_default():
    SC = attr.make_class("SC", {"x": attr.ib()})
    attr_parser_type = AttrParserArgs(attr.fields(SC).x).type
    assert type(attr_parser_type) is functools.partial
    assert attr_parser_type.func == AttrParserArgs.value_from_str
    assert attr_parser_type.args == ()
    assert attr_parser_type.keywords == dict(v_type=attr.fields(SC).x.type)
Ejemplo n.º 3
0
def test_attr_parser_args_action_specified():
    SC = attr.make_class(
        "SC", {
            "x":
            attr.ib(default=None,
                    metadata={METADATA_ARGPARSER: dict(action='someaction')})
        })
    assert AttrParserArgs(attr.fields(SC).x).action == 'someaction'
Ejemplo n.º 4
0
def test_attr_parser_args_kwargs_keys_for_store_const():
    SC = attr.make_class(
        "SC", {
            "x":
            attr.ib(type=int,
                    metadata={METADATA_ARGPARSER: dict(action='store_const')})
        })
    assert set(AttrParserArgs(attr.fields(SC).x).kwargs.keys()) == set(
        ('action', 'metavar', 'default', 'help'))
Ejemplo n.º 5
0
def test_attr_parser_args_kwargs_keys_with_choices():
    SC = attr.make_class(
        "SC", {
            "x":
            attr.ib(type=str,
                    default='123',
                    metadata={METADATA_ARGPARSER: dict(choices='somechoices')})
        })
    assert set(AttrParserArgs(attr.fields(SC).x).kwargs.keys()) == set(
        ('action', 'metavar', 'default', 'help', 'type', 'choices'))
Ejemplo n.º 6
0
def test_attr_parser_args_const_from_metadata_for_optional():
    SC = attr.make_class(
        "SC", {
            "x":
            attr.ib(type=str,
                    metadata={
                        METADATA_ARGPARSER: {
                            'const': 'someconst'
                        },
                    })
        })
    assert AttrParserArgs(attr.fields(SC).x).const == 'someconst'
Ejemplo n.º 7
0
def test_inputs_AttrParserArgs_help_from_metadata_for_optional():
    SC = attr.make_class(
        "SC", {
            "x":
            attr.ib(type=str,
                    metadata={
                        METADATA_ARGPARSER: {
                            'help': 'some help'
                        },
                    })
        })
    assert AttrParserArgs(attr.fields(SC).x).help == 'some help'
Ejemplo n.º 8
0
def test_inputs_AttrParserArgs_metavar_from_metadata_for_optional():
    SC = attr.make_class(
        "SC", {
            "x":
            attr.ib(type=str,
                    metadata={
                        METADATA_ARGPARSER: {
                            'metavar': 'SOME-METAVAR'
                        },
                    },
                    default='123')
        })
    assert AttrParserArgs(attr.fields(SC).x).metavar == 'SOME-METAVAR'
Ejemplo n.º 9
0
def test_inputs_AttrParserArgs_type_custom():
    def some_fun(value):
        pass

    SC = attr.make_class(
        "SC", {
            "x":
            attr.ib(type=str,
                    metadata={
                        METADATA_ARGPARSER: {
                            'type': some_fun
                        },
                    },
                    default='123')
        })
    assert AttrParserArgs(attr.fields(SC).x).type == some_fun
Ejemplo n.º 10
0
def test_attr_parser_args_kwargs_keys_for_boolean():
    SC = attr.make_class("SC", {"x": attr.ib(type=bool, default=False)})
    assert set(AttrParserArgs(attr.fields(SC).x).kwargs.keys()) == set(
        ('action', 'help'))
Ejemplo n.º 11
0
def test_inputs_AttrParserArgs_kwargs_keys_by_default():
    SC = attr.make_class("SC", {"x": attr.ib(type=str, default='123')})
    assert set(AttrParserArgs(attr.fields(SC).x).kwargs.keys()) == set(
        ('action', 'metavar', 'default', 'help', 'type'))
Ejemplo n.º 12
0
def test_attr_parser_args_name_for_optional():
    SC = attr.make_class("SC", {"x": attr.ib(default=None)})
    assert AttrParserArgs(attr.fields(SC).x).name == '--x'
Ejemplo n.º 13
0
def test_inputs_AttrParserArgs_help_by_default_for_optional():
    SC = attr.make_class("SC", {"x": attr.ib(type=str, default='123')})
    assert AttrParserArgs(attr.fields(SC).x).help == ''
Ejemplo n.º 14
0
def test_inputs_AttrParserArgs_no_metavar_for_positional():
    SC = attr.make_class("SC", {"x": attr.ib()})
    assert AttrParserArgs(attr.fields(SC).x).metavar is None
Ejemplo n.º 15
0
def test_inputs_AttrParserArgs_name_for_optional_with_underscore():
    SC = attr.make_class("SC", {"x_y": attr.ib(default=None)})
    assert AttrParserArgs(attr.fields(SC).x_y).name == '--x-y'
Ejemplo n.º 16
0
def test_inputs_AttrParserArgs_default_not_set():
    SC = attr.make_class("SC", {"x": attr.ib()})
    assert AttrParserArgs(attr.fields(SC).x).name == 'x'
    assert AttrParserArgs(attr.fields(SC).x).default is None
Ejemplo n.º 17
0
def test_attr_parser_args_default_set():
    SC = attr.make_class("SC", {"x": attr.ib(default=123)})
    assert AttrParserArgs(attr.fields(SC).x).name == '--x'
    assert AttrParserArgs(attr.fields(SC).x).default == 123
Ejemplo n.º 18
0
def test_inputs_AttrParserArgs_name_for_positional():
    SC = attr.make_class("SC", {"x": attr.ib()})
    assert AttrParserArgs(attr.fields(SC).x).name == 'x'
Ejemplo n.º 19
0
def test_inputs_AttrParserArgs_action_for_boolean():
    SC = attr.make_class("SC", {"x": attr.ib(default=None, type=bool)})
    assert AttrParserArgs(attr.fields(SC).x).action == 'store_true'
Ejemplo n.º 20
0
def test_inputs_AttrParserArgs_action_by_default():
    SC = attr.make_class("SC", {"x": attr.ib(default=None)})
    assert AttrParserArgs(attr.fields(SC).x).action == 'store'