Beispiel #1
0
def test_append_safe_noExcept():
    ## GIVEN a simple dict with list
    d = {"a": [1]}

    ## WHEN calling append_safe
    append_safe(d, "a", 2)

    ## THEN append_safe() will append elem at index
    assert d == {"a": [1, 2]}
Beispiel #2
0
def test_append_safe_no_except():
    """Test to append_safe"""
    # GIVEN a simple dict with list
    a_dict = {"a": [1]}

    # WHEN calling append_safe
    append_safe(a_dict, "a", 2)

    # THEN append_safe() will append elem at index
    assert a_dict == {"a": [1, 2]}
Beispiel #3
0
def test_append_safe_Except():
    ## GIVEN a simple dict with list
    d = {}

    ## WHEN calling append_safe() on a empty
    append_safe(d, "a", 2)

    ## THEN list.append exception is caught in try/except and
    ## program execution continues
    assert d == {"a": [2]}
Beispiel #4
0
def test_append_safe_except():
    """Test to append_safe empty dict"""
    # GIVEN a simple dict with list
    a_dict = {}

    # WHEN calling append_safe() on a empty
    append_safe(a_dict, "a", 2)

    # THEN list.append exception is caught in try/except and
    # program execution continues
    assert a_dict == {"a": [2]}
def test_append_safe_except():
    """Test to append_safe empty dict"""
    # GIVEN a simple dict with list
    a_dict = {}

    # WHEN calling append() on a empty dict
    # THEN KeyError exception is raised
    with pytest.raises(KeyError):
        a_dict["2"].append(2)

    # WHEN calling append_safe() on a empty
    append_safe(a_dict, "a", 2)

    # THEN list.append exception is caught in try/except and
    # program execution continues
    assert a_dict == {"a": [2]}