Commit f776f5b9 authored by Tim Schoof's avatar Tim Schoof
Browse files

Do not call converters twice

If a config option uses a converter, it should not be called during
command line parsing because it is already called during construction by
attr.
parent 64df2de1
Pipeline #14413 passed with stage
in 50 seconds
......@@ -143,7 +143,9 @@ def create_cli_parser_for_attribute(attribute, parser, prefix, short_prefix):
required = False
if attribute.converter:
typ = attribute.converter
# Do not convert the type in the parser as that will already be
# done during construction
typ = None
else:
typ = attribute.type
......
from collections import OrderedDict
import logging
from AsapoWorker.configurable import Configurable, Config
from AsapoWorker.configuration import create_config, \
create_yaml_from_configurable_class, create_instance_from_configurable, \
......@@ -475,6 +476,21 @@ def test_create_instance_overwrite_options_via_kwargs():
assert instance.extern_attribute is extern_attribute
def test_create_cli_parser_type_converter():
@Configurable
class UsesConverter:
level = Config(
"Log Level", type=int, converter=logging.getLevelName)
parser = create_cli_parser_from_configurable_class(UsesConverter)
options = parser.parse_args(["--UsesConverter.level", "DEBUG"])
instance = create_instance_from_configurable(
UsesConverter, parsed_args_to_dict(options)["UsesConverter"])
assert instance.level == logging.DEBUG
def test_create_instance_from_configurable_zero():
@Configurable
class Foo:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment