コード例 #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"