def test_choices_not_iterable(): with pytest.raises((ParameterError, ValueError)): # Value error comes from argparse (would be caught in dict_parser as well) EntryPoint([{ "name": "test", "flags": "--flag", "choices": 3, }])
def _harpy_entrypoint(params): options, rest = EntryPoint(harpy_params(), strict=False).parse(params) if options.natdeltas is not None and options.nattunes is not None: raise AttributeError( "Colliding options found: --nattunes and --natdeltas. Choose only one" ) if options.tunes is not None and options.autotunes is not None: raise AttributeError( "Colliding options found: --tunes and --autotunes. Choose only one" ) if options.tunes is None and options.autotunes is None: raise AttributeError( "One of the options --tunes and --autotunes has to be used.") if options.svd_dominance_limit <= 0.0: raise AttributeError("SVD dominance limit should be positive") if options.bad_bpms is None: options.bad_bpms = [] if options.wrong_polarity_bpms is None: options.wrong_polarity_bpms = [] if options.is_free_kick: options.window = "rectangle" return options, rest
def test_missing_flag_replaced_by_name_in_multiple_lists(): ep = EntryPoint([{ "name": "test" }, { "name": "thermos_coffee" }, { "name": "tee_kessel", "flags": ['--tee_kessel'] }]) assert len(ep.parameter[0]) == 2 assert ep.parameter[0]['flags'] == ['--test'] assert ep.parameter[0]['name'] == 'test' assert len(ep.parameter[1]) == 2 assert ep.parameter[1]['flags'] == ['--thermos_coffee'] assert ep.parameter[1]['name'] == 'thermos_coffee' assert len(ep.parameter[2]) == 2 assert ep.parameter[2]['flags'] == ['--tee_kessel'] assert ep.parameter[2]['name'] == 'tee_kessel'
def get_parsed_opt(opt, other_opt): """ Get all accelerator related options as a nice dict. """ accel = ACCELS[opt.accel] parser = EntryPoint(accel.get_parameters(), strict=True) accel_opt = parser.parse(other_opt) return {**opt, **accel_opt}
def _optics_entrypoint(params): return EntryPoint(optics_params(), strict=False).parse(params)
def test_missing_flag_replaced_by_name(): ep = EntryPoint([{"name": "test"}]) assert len(ep.parameter[0]) == 2 assert ep.parameter[0]['flags'] == ['--test'] assert ep.parameter[0]['name'] == 'test'
def test_wrong_param_creation_other(): with pytest.raises(TypeError): EntryPoint([{"name": "test", "flags": "--flag", "other": "unknown"}])
def test_wrong_param_creation_name(): with pytest.raises(ParameterError): EntryPoint([{"flags": "--flag"}])
def test_wrong_length_default_for_nargs(): with pytest.raises(ParameterError): EntryPoint([{"name": "test", "nargs": 2, "default": [1, 2, 3]}])
def test_empty_list_default_for_nargs_plus(): with pytest.raises(ParameterError): EntryPoint([{"name": "test", "nargs": "+", "default": []}])