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)
def test_inputs_ParamGroupInputBase_attr_ib():
    attr1 = attr.fields(SomeParamGroup).attr1
    assert attr1.type is str
    assert attr1.default is UNCHANGED
    assert attr1.metadata[METADATA_PARAM_GROUP_KEY] == 'some_param_gr'

    attr2 = attr.fields(SomeParamGroup).attr2
    assert attr2.type is int
    assert attr2.default == 1
    assert attr2.metadata[METADATA_PARAM_GROUP_KEY] == 'some_param_gr'
def test_inputs_ParamDictItemInputBaseattr_ib():
    some_key_attr = attr.fields(SomeParamDictItem).some_key_attr
    assert some_key_attr.type is str
    assert some_key_attr.default is attr.NOTHING
    assert some_key_attr.metadata[METADATA_ARGPARSER]['help'] == (
        'some_key_attr descr')

    some_value_attr = attr.fields(SomeParamDictItem).some_value_attr
    assert some_value_attr.type is str
    assert some_value_attr.default == UNCHANGED
    assert some_value_attr.metadata[METADATA_ARGPARSER]['help'] == (
        'some_value_attr descr')
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'
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'))
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'))
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'
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'
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'
Beispiel #10
0
def test_ParserFiller_extract_positional_args_happy_path():
    SC = attr.make_class(
        "SC", {
            "x":
            attr.ib(metadata={
                METADATA_ARGPARSER: {
                    'action': 'store_bool',
                    'help': 'some help'
                }
            },
                    type=int)
        })
    ret = ParserFiller.extract_positional_args(SC, attr.fields_dict(SC))
    assert ret == ([attr.fields(SC).x], {})
Beispiel #11
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
Beispiel #12
0
def test_inputs_copy_attr_verify_attrs():
    some_cls = attr.make_class(
        "some_cls", {
            "some_attr":
            attr.ib(default=123,
                    validator=None,
                    metadata={'metadata_key': 1},
                    repr=False,
                    hash=None,
                    init=True,
                    type=str,
                    converter=None,
                    kw_only=True)
        })

    read_attr = attr.fields(some_cls).some_attr

    copied_attr = inputs.copy_attr(read_attr)

    assert copied_attr == read_attr
Beispiel #13
0
 def __source_rpm(self):
     if not self.target_build:
         raise ValueError('`target_build` should be specified')
     if self.dist_type == config.DistrType.BUNDLE and (
         self.url_cortx_deps !=
         attr.fields(type(self)).url_cortx_deps.default
     ):
         logger.warning(
             "`url_cortx_deps` value would be ignored "
             "for bundle distribution type"
         )
         self.url_cortx_deps = None
     if (
         not self.pypi_repo and
         self.dist_type != config.DistrType.BUNDLE
     ):
         logger.warning(
             "Custom pip repo cannot be used "
             "for non bundled distributions "
             "hence pip will be configured to install from pypi.org"
         )
         self.pypi_repo = True
Beispiel #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
Beispiel #15
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'))
Beispiel #16
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'
Beispiel #17
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'
Beispiel #18
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'
Beispiel #19
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 == ''
Beispiel #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'
Beispiel #21
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'))
Beispiel #22
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
Beispiel #23
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
Beispiel #24
0
    def __source_iso(self):
        if not self.iso_cortx:
            raise ValueError("ISO for CORTX is undefined")

        iso_names = []
        if self.iso_os:
            if self.iso_os.suffix != '.iso':
                raise ValueError(
                    ".iso extension is expected for OS ISO"
                )
            iso_names.append(self.iso_os.name)

        if self.iso_cortx.suffix != '.iso':
            raise ValueError(".iso extension is expected for CORTX ISO")
        iso_names.append(self.iso_cortx.name)

        if self.iso_cortx_deps:
            if self.iso_cortx_deps.suffix != '.iso':
                raise ValueError(
                    ".iso extension is expected for CORTX deps ISO"
                )
            if not self.pypi_repo:
                logger.warning(
                    "Custom python repo can be used only "
                    "for single ISO based setup "
                    "hence pip will be configured to install from pypi.org"
                )
                self.pypi_repo = True
            iso_names.append(self.iso_cortx_deps.name)

        if len(iso_names) != len(set(iso_names)):
            raise ValueError(
                "ISO files have collision in names"
            )

        if self.dist_type != config.DistrType.BUNDLE:
            logger.info(
                "The type of distribution would be set to "
                f"{config.DistrType.BUNDLE}"
            )
            self.dist_type = config.DistrType.BUNDLE

        if (
            self.target_build !=
            attr.fields(type(self)).target_build.default
        ):
            logger.warning(
                "`target_build` value would be ignored "
                "for ISO based installation"
            )

        release_sls = (
            config.BUNDLED_SALT_PILLAR_DIR / 'groups/all/release.sls'
        )
        # iso files will be mounted into dirs inside that directory
        base_dir = Path(
            utils.load_yaml(release_sls)['release']['base']['base_dir']
        )

        if not self.iso_cortx_deps:
            base_dir /= config.CORTX_SINGLE_ISO_DIR

        self.target_build = f'file://{base_dir}'

        if (
            self.url_cortx_deps !=
            attr.fields(type(self)).url_cortx_deps.default
        ):
            logger.warning(
                "`url_cortx_deps` value would be ignored "
                "for ISO based installation"
            )
            self.url_cortx_deps = None
Beispiel #25
0
def test_inputs_AttrParserArgs_name_for_positional():
    SC = attr.make_class("SC", {"x": attr.ib()})
    assert AttrParserArgs(attr.fields(SC).x).name == 'x'