Example #1
0
def test_invalid_choice_not_set():
    """Ensure an error is raised for no choice"""
    test_config = ApplicationConfiguration(
        application_name="test_config1",
        application_version="1.0",
        internals=Internals(),
        post_processor=None,
        subcommands=[
            SubCommand(
                name="subcommand1",
                description="subcommand1",
                version_added="v0.0",
            ),
        ],
        entries=[
            SettingsEntry(
                name="sb1",
                short_description="Subcommands",
                subcommand_value=True,
                value=SettingsEntryValue(default="welcome"),
                version_added="v0.0",
            ),
            SettingsEntry(
                name="e1",
                short_description="ex1",
                value=SettingsEntryValue(),
                version_added="v0.0",
            ),
        ],
    )
    with pytest.raises(ValueError, match="Current source not set for e1"):
        test_config.entry("e1").invalid_choice  # pylint: disable=expression-not-assigned
Example #2
0
def test_apply_cli_subset_none():
    """Ensure subset none works for apply CLI"""
    test_config = ApplicationConfiguration(
        application_name="test_application",
        post_processor=None,
        subcommands=[
            SubCommand(name="list", description="list"),
            SubCommand(name="run", description="run"),
        ],
        entries=[
            Entry(
                name="subcommand",
                short_description="Subcommands",
                subcommand_value=True,
                value=EntryValue(default="run"),
            ),
            Entry(
                name="z",
                apply_to_subsequent_cli=C.NONE,
                cli_parameters=CliParameters(short="-z"),
                short_description="the z parameter",
                value=EntryValue(),
            ),
        ],
    )
    configurator = Configurator(params=["list", "-z", "zebra"],
                                application_configuration=test_config,
                                initial=True)
    _messages, exit_messages = configurator.configure()
    assert not exit_messages

    assert isinstance(test_config.initial, ApplicationConfiguration)

    expected = [
        ("subcommand", "list"),
        ("z", "zebra"),
    ]
    for expect in expected:
        assert test_config.entry(expect[0]).value.current == expect[1]
        assert test_config.entry(expect[0]).value.source is C.USER_CLI

    configurator = Configurator(params=["run"],
                                application_configuration=test_config,
                                apply_previous_cli_entries=C.ALL)
    _messages, exit_messages = configurator.configure()
    assert not exit_messages

    expected = [
        ("subcommand", "run", C.USER_CLI),
        ("z", C.NOT_SET, C.NOT_SET),
    ]
    for expect in expected:
        assert test_config.entry(expect[0]).value.current == expect[1]
        assert test_config.entry(expect[0]).value.source is expect[2]