예제 #1
0
파일: test_map.py 프로젝트: ilexconf/mapz
def test_apply_inplace(data):
    """Test applying modifying visitor in place."""

    zmap(data, modificator, inplace=True)

    assert data["name"] == "@Boris"

    assert data["music"]["songs"] == ["@Du Hast", "@Du Hast - Live"]
예제 #2
0
def to_uppercase(
    mapping: Union[Dict[Hashable, Any], Mapping[Hashable, Any]],
    inplace: bool = False,
    mapping_type: Type[Dict[Hashable, Any]] = dict,
) -> Dict[Hashable, Any]:
    """Uppercase all string keys.

    Args:
        mapping: Mapping structure to transform.
        inplace (bool): If True, replace the given mapping structure with the
            newly generated uppercased Dict. Defaults to False. Only works
            when the given mapping is a mutable dict-like object.
        mapping_type (Type): Which type to use when creating a new uppercased
            structure. Defaults to ``dict``.

    Returns:
        Dict: Uppercase Dict-like structure with all string keys transformed
        to uppercase.
    """

    return zmap(
        mapping,
        visitor=lambda k, v, **kwargs: (
            k.upper() if isinstance(k, str) else k,
            v,
        ),
        inplace=inplace,
        mapping_type=mapping_type,
    )
예제 #3
0
파일: test_map.py 프로젝트: ilexconf/mapz
def test_apply(data):
    """Test applying modifying visitor."""

    modified = zmap(data, modificator)

    assert modified["name"] == "@Boris"
    assert data["name"] == "Boris"

    assert modified["music"]["songs"] == ["@Du Hast", "@Du Hast - Live"]
    assert data["music"]["songs"] == ["Du Hast", "Du Hast - Live"]
예제 #4
0
파일: test_map.py 프로젝트: ilexconf/mapz
def test_default_modificator(data):
    """Test default map values that should not change anything."""

    assert zmap(data)["name"] == "Boris"