示例#1
0
def test_none_condop():
    step = Step(cond_op=StepConditionOperator.NONE, conditions=[
        NonEmpty({"v": {"variable": "a"}}),
        NonEmpty({"v": {"variable": "b"}}),
    ], actions=[SetDebugFlag({})])
    context = Context.from_variables(a=False, b=False)
    step.execute(context)
    assert context.get("debug")
示例#2
0
def test_basic_exec():
    script = get_test_script()

    # `en` is not in the conditions
    context = Context.from_variables(order_language="en")
    script.execute(context)
    assert not context.get("success")

    # `fi` is matched by the first condition and cond_op is 'or'
    context = Context.from_variables(order_language="fi")
    script.execute(context)
    assert context.get("success")

    # `ja` is matched by the other condition, and cond_op is 'or'
    context = Context.from_variables(order_language="ja")
    script.execute(context)
    assert context.get("success")
示例#3
0
def test_basic_exec():
    script = get_test_script()

    # `en` is not in the conditions
    context = Context.from_variables(order_language="en")
    script.execute(context)
    assert not context.get("success")

    # `fi` is matched by the first condition and cond_op is 'or'
    context = Context.from_variables(order_language="fi")
    script.execute(context)
    assert context.get("success")

    # `ja` is matched by the other condition, and cond_op is 'or'
    context = Context.from_variables(order_language="ja")
    script.execute(context)
    assert context.get("success")
示例#4
0
def test_disabled_steps():
    script = get_test_script()
    steps = script.get_steps()
    steps[0].enabled = False
    script.set_steps(steps)
    # Disabled steps don't run
    context = Context.from_variables()
    script.execute(context)
    assert not context.get("success")
示例#5
0
def test_disabled_steps():
    script = get_test_script()
    steps = script.get_steps()
    steps[0].enabled = False
    script.set_steps(steps)
    # Disabled steps don't run
    context = Context.from_variables()
    script.execute(context)
    assert not context.get("success")
示例#6
0
def test_none_condop():
    step = Step(cond_op=StepConditionOperator.NONE,
                conditions=[
                    NonEmpty({"v": {
                        "variable": "a"
                    }}),
                    NonEmpty({"v": {
                        "variable": "b"
                    }}),
                ],
                actions=[SetDebugFlag({})])
    context = Context.from_variables(a=False, b=False)
    step.execute(context)
    assert context.get("debug")
示例#7
0
def test_condops(cond_op):
    step = Step(cond_op=cond_op, conditions=[
        NonEmpty({"v": {"variable": "a"}}),
        NonEmpty({"v": {"variable": "b"}}),
    ], actions=[SetDebugFlag({})])
    context = Context.from_variables(a=True, b=False)
    step.execute(context)
    if cond_op == StepConditionOperator.ALL:
        assert not context.get("debug")
    elif cond_op == StepConditionOperator.ANY:
        assert context.get("debug")
    elif cond_op == StepConditionOperator.NONE:
        assert not context.get("debug")
    else:
        raise ValueError("Unexpected condop %r" % cond_op)
示例#8
0
def test_condops(cond_op):
    step = Step(cond_op=cond_op,
                conditions=[
                    NonEmpty({"v": {
                        "variable": "a"
                    }}),
                    NonEmpty({"v": {
                        "variable": "b"
                    }}),
                ],
                actions=[SetDebugFlag({})])
    context = Context.from_variables(a=True, b=False)
    step.execute(context)
    if cond_op == StepConditionOperator.ALL:
        assert not context.get("debug")
    elif cond_op == StepConditionOperator.ANY:
        assert context.get("debug")
    elif cond_op == StepConditionOperator.NONE:
        assert not context.get("debug")
    else:
        raise ValueError("Unexpected condop %r" % cond_op)
示例#9
0
def test_binding_fallthrough():
    ctx = Context.from_variables()
    b = Binding("x", default="foo")
    assert b.get_value(ctx, {"variable": "var"}) == "foo"
    assert b.get_value(ctx, {}) == "foo"
示例#10
0
def test_empty():
    ie = Empty({"v": {"variable": "v"}})
    assert ie.test(Context.from_variables(v=False))
    assert ie.test(Context.from_variables(v=()))
    assert ie.test(Context.from_variables(v=0))
    assert not ie.test(Context.from_variables(v=6))
示例#11
0
def test_non_empty():
    ie = NonEmpty({"v": {"variable": "v"}})
    assert ie.test(Context.from_variables(v=True))
    assert not ie.test(Context.from_variables(v=""))
    assert not ie.test(Context.from_variables(v=0))
示例#12
0
def test_text_equal():
    ie = TextEqual({"v1": {"variable": "v"}, "v2": {"constant": "   Foo   "}})
    assert ie.test(Context.from_variables(v="foo"))
    assert ie.test(Context.from_variables(v="Foo"))
    assert ie.test(Context.from_variables(v="Foo  "))
    assert not ie.test(Context.from_variables(v="faa"))
示例#13
0
def test_integer_equals():
    ie = IntegerEqual({"v1": {"variable": "v"}, "v2": {"constant": 42}})
    assert ie.test(Context.from_variables(v=42))
    assert ie.test(Context.from_variables(v="42"))
    assert not ie.test(Context.from_variables(v="442"))
    assert not ie.test(Context.from_variables(v=True))
示例#14
0
def test_binding_fallthrough():
    ctx = Context.from_variables()
    b = Binding("x", default="foo")
    assert b.get_value(ctx, {"variable": "var"}) == "foo"
    assert b.get_value(ctx, {}) == "foo"
示例#15
0
def test_conditionless_step_executes():
    step = Step(actions=[SetDebugFlag({})])
    context = Context()
    step.execute(context)
    assert context.get("debug")
示例#16
0
def test_conditionless_step_executes():
    step = Step(actions=[SetDebugFlag({})])
    context = Context()
    step.execute(context)
    assert context.get("debug")