# Path: invenio_records/dictutils.py
# def clear_none(d):
#     """Clear None values and empty dicts from a dict."""
#     del_keys = []
#     for k, v in d.items():
#         if v is None:
#             del_keys.append(k)
#         elif isinstance(v, dict):
#             clear_none(v)
#             if v == {}:
#                 del_keys.append(k)
#         elif isinstance(v, list):
#             clear_none_list(v)
#             if v == []:
#                 del_keys.append(k)
# 
#     # Delete the keys (cannot be done during the dict iteration)
#     for k in del_keys:
#         del d[k]
# 
# def dict_lookup(source, lookup_key, parent=False):
#     """Make a lookup into a dict based on a dot notation.
# 
#     Examples of the supported dot notation:
# 
#     - ``'a'`` - Equivalent to ``source['a']``
#     - ``'a.b'`` - Equivalent to ``source['a']['b']``
#     - ``'a.b.0'`` - Equivalent to ``source['a']['b'][0]`` (for lists)
# 
#     List notation is also supported:
# 
#     - `['a']``
#     - ``['a','b']``
#     - ``['a','b', 0]``
# 
#     :param source: The dictionary object to perform the lookup in.
#     :param parent: If parent argument is True, returns the parent node of
#                    matched object.
#     :param lookup_key: A string using dot notation, or a list of keys.
#     """
#     # Copied from dictdiffer (CERN contributed part) and slightly modified.
#     keys = parse_lookup_key(lookup_key)
# 
#     if parent:
#         keys = keys[:-1]
# 
#     # Lookup the key
#     value = source
#     for key in keys:
#         try:
#             if isinstance(value, list):
#                 key = int(key)
#             value = value[key]
#         except (TypeError, IndexError, ValueError) as exc:
#             raise KeyError(lookup_key) from exc
#     return value


from copy import deepcopy
from invenio_records.dictutils import clear_none, dict_lookup
import pytest
        'd': ['1', None, []],
        'e': [{'a': None, 'b': []}],
    }

    clear_none(d)
    # Modifications are done in place, so gotta test after the function call.
    assert d == {'d': ['1']}

    d = {
        'a': None,
        'b': [
            {'a': '1', 'b': None},
        ],
    }
    clear_none(d)
    # Modifications are done in place, so gotta test after the function call.
    assert d == {'b': [{'a': '1'}]}


def test_dict_lookup():
    """Test lookup by a key."""
    d = {
        'a': 1,
        'b': {
            'c': None
        },
        'd': ['1', '2'],
    }
    assert dict_lookup(d, 'a') == d['a']
    assert dict_lookup(d, 'b') == d['b']

# Path: invenio_records/dictutils.py
# def clear_none(d):
#     """Clear None values and empty dicts from a dict."""
#     del_keys = []
#     for k, v in d.items():
#         if v is None:
#             del_keys.append(k)
#         elif isinstance(v, dict):
#             clear_none(v)
#             if v == {}:
#                 del_keys.append(k)
#         elif isinstance(v, list):
#             clear_none_list(v)
#             if v == []:
#                 del_keys.append(k)
# 
#     # Delete the keys (cannot be done during the dict iteration)
#     for k in del_keys:
#         del d[k]
# 
# def dict_lookup(source, lookup_key, parent=False):
#     """Make a lookup into a dict based on a dot notation.
# 
#     Examples of the supported dot notation:
# 
#     - ``'a'`` - Equivalent to ``source['a']``
#     - ``'a.b'`` - Equivalent to ``source['a']['b']``
#     - ``'a.b.0'`` - Equivalent to ``source['a']['b'][0]`` (for lists)
# 
#     List notation is also supported:
# 
#     - `['a']``
#     - ``['a','b']``
#     - ``['a','b', 0]``
# 
#     :param source: The dictionary object to perform the lookup in.
#     :param parent: If parent argument is True, returns the parent node of
#                    matched object.
#     :param lookup_key: A string using dot notation, or a list of keys.
#     """
#     # Copied from dictdiffer (CERN contributed part) and slightly modified.
#     keys = parse_lookup_key(lookup_key)
# 
#     if parent:
#         keys = keys[:-1]
# 
#     # Lookup the key
#     value = source
#     for key in keys:
#         try:
#             if isinstance(value, list):
#                 key = int(key)
#             value = value[key]
#         except (TypeError, IndexError, ValueError) as exc:
#             raise KeyError(lookup_key) from exc
#     return value


# Path: tests/test_dictutils.py
from copy import deepcopy
from invenio_records.dictutils import clear_none, dict_lookup
import pytest

        'd': ['1', None, []],
        'e': [{'a': None, 'b': []}],
    }

    clear_none(d)
    # Modifications are done in place, so gotta test after the function call.
    assert d == {'d': ['1']}

    d = {
        'a': None,
        'b': [
            {'a': '1', 'b': None},
        ],
    }
    clear_none(d)
    # Modifications are done in place, so gotta test after the function call.
    assert d == {'b': [{'a': '1'}]}


def test_dict_lookup():
    """Test lookup by a key."""
    d = {
        'a': 1,
        'b': {
            'c': None
        },
        'd': ['1', '2'],
    }
    assert dict_lookup(d, 'a') == d['a']
    assert dict_lookup(d, 'b') == d['b']

    assert dict_lookup(d, 'b.c') == d['b']['c']