Пример #1
0
def test_overrides_parser() -> None:
    overrides = ["x=10", "y=[1,2]", "z=a,b,c"]
    expected = [
        Override(
            type=OverrideType.CHANGE,
            key_or_group="x",
            value_type=ValueType.ELEMENT,
            _value=10,
            input_line=overrides[0],
        ),
        Override(
            type=OverrideType.CHANGE,
            key_or_group="y",
            value_type=ValueType.ELEMENT,
            _value=[1, 2],
            input_line=overrides[1],
        ),
        Override(
            type=OverrideType.CHANGE,
            key_or_group="z",
            value_type=ValueType.CHOICE_SWEEP,
            _value=["a", "b", "c"],
            input_line=overrides[2],
        ),
    ]
    parser = OverridesParser()
    ret = parser.parse_overrides(overrides)
    assert ret == expected
Пример #2
0
 def is_matching(override: Override, default: DefaultElement) -> bool:
     assert override.key_or_group == default.config_group
     if override.is_delete():
         return override.get_subject_package() == default.package
     else:
         return override.key_or_group == default.config_group and (
             override.pkg1 == default.package
             or override.pkg1 == "" and default.package is None)
Пример #3
0
def test_override_parsing(
    prefix: str,
    value: str,
    override_type: OverrideType,
    expected_key: str,
    expected_value: Any,
    expected_value_type: ValueType,
) -> None:
    line = prefix + value
    ret = OverridesParser.parse_rule(line, "override")
    expected = Override(
        input_line=line,
        type=override_type,
        key_or_group=expected_key,
        _value=expected_value,
        value_type=expected_value_type,
    )
    assert ret == expected
Пример #4
0
        type=override_type,
        key_or_group=expected_key,
        _value=expected_value,
        value_type=expected_value_type,
    )
    assert ret == expected


@pytest.mark.parametrize(  # type: ignore
    "value,expected",
    [
        (
            "~x",
            Override(
                type=OverrideType.DEL,
                key_or_group="x",
                value_type=None,
                _value=None,
            ),
        ),
        (
            "~x=10",
            Override(
                type=OverrideType.DEL,
                key_or_group="x",
                value_type=ValueType.ELEMENT,
                _value=10,
            ),
        ),
        (
            "~x=",
            Override(