Exemple #1
0
def test_assert_step_arguments_should_use_explcitly_specified_type_and_value():
    # GIVEN
    actual_step_arguments = {"str-arg1": "value"}
    expected_step_arguments = {"str-arg1": {"type": "str", "value": "value"}}

    # WHEN
    actual_errors = assert_step_arguments(
        actual_step_arguments, expected_step_arguments
    )

    # THEN
    assert len(actual_errors) == 0
Exemple #2
0
def test_assert_step_arguments_should_use_specified_cast_for_explicit_value():
    # GIVEN
    actual_step_arguments = {"int-arg1": 42}
    expected_step_arguments = {"int-arg1": {"type": "int", "value": "42", "cast": True}}

    # WHEN
    actual_errors = assert_step_arguments(
        actual_step_arguments, expected_step_arguments
    )

    # THEN
    assert len(actual_errors) == 0
Exemple #3
0
def test_assert_step_arguments_should_correctly_compare_dicts():
    # GIVEN
    actual_step_arguments = {"dict-arg1": {"key1": 1, "key2": 2}}
    expected_step_arguments = {"dict-arg1": {"key1": 1, "key2": 2}}

    # WHEN
    actual_errors = assert_step_arguments(
        actual_step_arguments, expected_step_arguments
    )

    # THEN
    assert len(actual_errors) == 0
Exemple #4
0
def test_assert_step_arguments_should_fail_if_dicts_dont_match():
    # GIVEN
    actual_step_arguments = {"dict-arg1": {"key1": 1, "key2": 2}}
    expected_step_arguments = {"dict-arg1": {"key1": 0, "key2": 0}}

    # WHEN
    actual_errors = assert_step_arguments(
        actual_step_arguments, expected_step_arguments
    )

    # THEN
    assert len(actual_errors) == 1
Exemple #5
0
def test_assert_step_arguments_should_pass_if_arguments_match():
    # GIVEN
    actual_step_arguments = {"arg1": "value", "arg2": 2}
    expected_step_arguments = {"arg1": "value", "arg2": 2}

    # WHEN
    actual_errors = assert_step_arguments(
        actual_step_arguments, expected_step_arguments
    )

    # THEN
    assert len(actual_errors) == 0
Exemple #6
0
def test_assert_step_arguments_should_use_repr_if_specified_along_with_explcit_type_and_value():
    # GIVEN
    actual_step_arguments = {"str-arg1": "value"}
    expected_step_arguments = {
        "str-arg1": {"use_repr": True, "type": "str", "value": "'value'"}
    }

    # WHEN
    actual_errors = assert_step_arguments(
        actual_step_arguments, expected_step_arguments
    )

    # THEN
    assert len(actual_errors) == 0
Exemple #7
0
def test_assert_step_arguments_should_fail_if_unable_to_cast():
    # GIVEN
    actual_step_arguments = {"int-arg1": 42}
    expected_step_arguments = {
        "int-arg1": {"type": "int", "value": "not-an-int", "cast": True}
    }

    # WHEN
    actual_errors = assert_step_arguments(
        actual_step_arguments, expected_step_arguments
    )

    # THEN
    assert len(actual_errors) == 1
    assert actual_errors[0] == ('Failed to cast "not-an-int" to given type "int"')
Exemple #8
0
def test_assert_step_arguments_should_fail_if_argument_values_have_type_mismatch():
    # GIVEN
    actual_step_arguments = {"int-arg1": 42}
    expected_step_arguments = {"int-arg1": "42"}

    # WHEN
    actual_errors = assert_step_arguments(
        actual_step_arguments, expected_step_arguments
    )

    # THEN
    assert len(actual_errors) == 1
    assert actual_errors[0] == (
        'Expected argument "int-arg1" is of type "str" but should be "int"'
    )
Exemple #9
0
def test_assert_step_arguments_should_fail_if_expected_argument_value_doesnt_match():
    # GIVEN
    actual_step_arguments = {"arg1": "value", "arg2": 2}
    expected_step_arguments = {"arg1": "not-correct-value", "arg2": 2}

    # WHEN
    actual_errors = assert_step_arguments(
        actual_step_arguments, expected_step_arguments
    )

    # THEN
    assert len(actual_errors) == 1
    assert actual_errors[0] == (
        'Expected argument "arg1" with value "not-correct-value" does not match value "value"'
    )
Exemple #10
0
def test_assert_step_arguments_should_fail_if_expected_argument_is_not_present():
    # GIVEN
    actual_step_arguments = {"arg1": None, "arg2": None}
    expected_step_arguments = {"not-existing-arg": "value1"}

    # WHEN
    actual_errors = assert_step_arguments(
        actual_step_arguments, expected_step_arguments
    )

    # THEN
    assert len(actual_errors) == 1
    assert actual_errors[0] == (
        "Expected argument \"not-existing-arg\" is not in matched arguments ['arg1', 'arg2']"
    )
Exemple #11
0
def test_assert_step_arguments_should_fail_if_specified_value_has_not_explictly_specified_type():
    # GIVEN
    actual_step_arguments = {"str-arg1": "value"}
    expected_step_arguments = {"str-arg1": {"type": "str", "value": 42}}

    # WHEN
    actual_errors = assert_step_arguments(
        actual_step_arguments, expected_step_arguments
    )

    # THEN
    assert len(actual_errors) == 1
    assert actual_errors[0] == (
        "Conflicting argument configuration: "
        'given value is actually of type "int" although it should match a value of type "str"'
    )
Exemple #12
0
def test_assert_step_arguments_should_fail_if_type_is_not_known_for_cast():
    # GIVEN
    actual_step_arguments = {"int-arg1": 42}
    expected_step_arguments = {
        "int-arg1": {"type": "UnknownType", "value": "42", "cast": True}
    }

    # WHEN
    actual_errors = assert_step_arguments(
        actual_step_arguments, expected_step_arguments
    )

    # THEN
    assert len(actual_errors) == 1
    assert actual_errors[0] == (
        'Cannot cast to type "UnknownType" because it is unknown'
    )
Exemple #13
0
def test_assert_step_arguments_should_collect_all_argument_mismatched():
    # GIVEN
    actual_step_arguments = {"arg1": "value", "arg2": 2}
    expected_step_arguments = OrderedDict([("arg1", "not-correct-value"), ("arg2", -1)])

    # WHEN
    actual_errors = assert_step_arguments(
        actual_step_arguments, expected_step_arguments
    )

    # THEN
    assert len(actual_errors) == 2
    assert actual_errors[0] == (
        'Expected argument "arg1" with value "not-correct-value" does not match value "value"'
    )
    assert actual_errors[1] == (
        'Expected argument "arg2" with value "-1" does not match value "2"'
    )