def test_generate_options_dict():
    parameter = Parameter('test', ParameterType.BOOLEAN)
    conditions: List[Condition] = [
        Equal(parameter, True), Equal(parameter, True)
    ]
    res = _generate_options_dict(conditions)
    assert res == [('test == True', True), ('test != True', False)]
Esempio n. 2
0
def test_is_satisfied():
    param_1 = Parameter('regime', ParameterType.REGIME)
    param_2 = Parameter('date', ParameterType.DATE)
    condition_1 = Equal(param_1, Regime.A)
    condition_2 = Equal(param_1, Regime.E)
    condition_3 = Littler(param_2, 1, True)
    assert not AndCondition(frozenset([condition_1])).is_satisfied({})
    assert AndCondition(frozenset([condition_1
                                   ])).is_satisfied({param_1: Regime.A})
    assert OrCondition(frozenset([condition_1, condition_2
                                  ])).is_satisfied({param_1: Regime.A})
    assert OrCondition(frozenset([condition_1, condition_3
                                  ])).is_satisfied({param_1: Regime.A})
    assert not AndCondition(frozenset([condition_1, condition_2
                                       ])).is_satisfied({param_1: Regime.A})
    assert AndCondition(frozenset([condition_1, condition_3])).is_satisfied({
        param_1:
        Regime.A,
        param_2:
        0.5
    })
    assert OrCondition(frozenset([condition_2, condition_3])).is_satisfied({
        param_1:
        Regime.E,
        param_2:
        0.5
    })
    assert not OrCondition(frozenset([condition_1, condition_3])).is_satisfied(
        {
            param_1: Regime.E,
            param_2: 5
        })
def test_generate_equal_option_dicts_2():
    parameter = Parameter('regime', ParameterType.REGIME)
    conditions: List[Condition] = [
        Equal(parameter, Regime.A),
        Equal(parameter, Regime.NC)
    ]
    res = _generate_equal_option_dicts(conditions)
    expected = [
        ('regime == A', Regime.A),
        ('regime == E', Regime.E),
        ('regime == D', Regime.D),
        ('regime == NC', Regime.NC),
    ]
    assert expected == res
def test_extract_date_range():
    date_ = ParameterEnum.DATE_INSTALLATION.value
    dt_1 = datetime.now()
    dt_2 = dt_1 + timedelta(days=1)
    assert _extract_date_range(Range(date_, dt_1, dt_2)) == (dt_1, dt_2)
    assert _extract_date_range(Equal(date_, dt_1)) == (dt_1, dt_1)
    assert _extract_date_range(Littler(date_, dt_1)) == (None, dt_1)
    assert _extract_date_range(Greater(date_, dt_1)) == (dt_1, None)
def test_check_date_conditions_not_compatible():
    date_ = ParameterEnum.DATE_INSTALLATION.value
    dt_1 = datetime.now()
    dt_2 = dt_1 + timedelta(days=1)
    cd_1 = Range(date_, dt_1, dt_2)
    cd_2 = Equal(date_, dt_1)
    cd_3 = Littler(date_, dt_1)
    cd_4 = Greater(date_, dt_2)

    _check_date_conditions_not_compatible([cd_1], date_)
    _check_date_conditions_not_compatible([cd_1, cd_2], date_)
    _check_date_conditions_not_compatible([cd_1, cd_3, cd_4], date_)
    _check_date_conditions_not_compatible([cd_2], date_)
    _check_date_conditions_not_compatible([cd_3], date_)
    _check_date_conditions_not_compatible([cd_4], date_)

    cd_5 = Littler(date_, dt_2)
    cd_6 = Greater(date_, dt_1)
    with pytest.raises(ParametrizationError):
        _check_date_conditions_not_compatible([cd_5, cd_6], date_)
    with pytest.raises(ParametrizationError):
        _check_date_conditions_not_compatible([cd_1, cd_6], date_)
    with pytest.raises(ParametrizationError):
        _check_date_conditions_not_compatible([cd_5, cd_1], date_)
def test_check_discrete_conditions_not_compatible():
    reg = ParameterEnum.REGIME.value
    _check_discrete_conditions_not_compatible([Equal(reg, Regime.E)], reg)
    _check_discrete_conditions_not_compatible(
        [Equal(reg, Regime.E), Equal(reg, Regime.D)], reg)
    _check_discrete_conditions_not_compatible(
        [Equal(reg, Regime.E),
         Equal(reg, Regime.D),
         Equal(reg, Regime.A)], reg)
    _check_discrete_conditions_not_compatible([
        OrCondition(
            frozenset([
                Equal(reg, Regime.E),
                Equal(reg, Regime.D),
                Equal(reg, Regime.A)
            ]))
    ], reg)

    with pytest.raises(ParametrizationError):
        _check_discrete_conditions_not_compatible(
            [Equal(reg, Regime.E), Equal(reg, Regime.E)], reg)
    with pytest.raises(ParametrizationError):
        _check_discrete_conditions_not_compatible([
            OrCondition(frozenset([Equal(reg, Regime.E),
                                   Equal(reg, Regime.D)])),
            Equal(reg, Regime.D)
        ], reg)
    with pytest.raises(ParametrizationError):
        _check_discrete_conditions_not_compatible([
            OrCondition(
                frozenset([Littler(reg, Regime.E),
                           Equal(reg, Regime.D)])),
            Equal(reg, Regime.A)
        ], reg)
def test_check_conditions_not_compatible():
    for parameter in ParameterEnum:
        check_conditions_not_compatible([Equal(parameter.value, '')],
                                        parameter.value)