Exemplo n.º 1
0
def test_with_only_raises_attribute_error_when_second_argument_is_not_list():
    """
    Test datamegh.util.with_only() would return an Attribute error when attrs is an invalid
    argument.
    """

    with pytest.raises(AttributeError) as ex:
        with_only({}, 1)

    assert (ex.value.args[0] ==
            "Second argument must be a list, invalid argument received '1'.")
Exemplo n.º 2
0
def test_with_only_raises_type_error_when_first_argument_is_not_dictionary():
    """
    Test datamegh.util.with_only() would return an Attribute error when no arguments
    are provided to it.
    """

    with pytest.raises(TypeError) as ex:
        with_only()

    assert (
        ex.value.args[0] ==
        "with_only() missing 2 required positional arguments: 'src' and 'attrs'"
    )
Exemplo n.º 3
0
def test_with_only_raises_attribute_error_when_first_argument_is_not_dictionary(
):
    """
    Test datamegh.util.with_only() would return an Attribute error when src is an invalid
    argument.
    """

    with pytest.raises(AttributeError) as ex:
        with_only(1, [])

    assert (
        ex.value.args[0] ==
        "First argument must be a dictionary, invalid argument received '1'.")
Exemplo n.º 4
0
def test_with_only_returns_empty_dictionary_when_attrs_is_empty():
    """
    Test datamegh.util.with_only() would return an empty dictionary when empty attrs
    list is provided to it.
    """

    assert with_only({"key1": "value1", "key2": "value2"}, []) == {}
Exemplo n.º 5
0
def test_with_only_returns_dictionary_when_both_src_and_attrs_are_valid_arguments(
):
    """
    Test datamegh.util.with_only() would return a dictionary when a valid source
    and attrs are provided to it
    """

    assert with_only({
        "key1": "value1",
        "key2": "value2"
    }, ["key1"]) == {
        "key1": "value1"
    }