Skip to content

Commit

Permalink
tests: add tests for filter_dict_keys
Browse files Browse the repository at this point in the history
  • Loading branch information
yashlamba authored and slint committed Feb 19, 2024
1 parent a316741 commit f7e18cf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
21 changes: 20 additions & 1 deletion tests/test_dictutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@

import pytest

from invenio_records.dictutils import clear_none, dict_lookup, dict_merge
from invenio_records.dictutils import (
clear_none,
dict_lookup,
dict_merge,
filter_dict_keys,
)


def test_clear_none():
Expand Down Expand Up @@ -78,3 +83,17 @@ def test_dict_merge():
"foo2": "bar2",
"metadata": {"field1": 3, "field2": "test"},
}


def test_filter_dict_keys():
"""Test filter dict keys."""
source = {
"foo1": {"bar1": 1, "bar2": 2},
"foo2": 1,
"foo3": {"bar1": {"foo4": 0}, "bar2": 1, "bar3": 2},
"foo4": {},
}

assert filter_dict_keys(
source, ["foo1.bar1", "foo2", "foo3.bar1.foo4", "foo3.bar3"]
) == {"foo1": {"bar1": 1}, "foo2": 1, "foo3": {"bar1": {"foo4": 0}, "bar3": 2}}
6 changes: 3 additions & 3 deletions tests/test_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def local_ref_resolver_store_factory():

@pytest.fixture(scope="module")
def app_config(app_config):
app_config[
"RECORDS_REFRESOLVER_CLS"
] = "invenio_records.resolver.InvenioRefResolver"
app_config["RECORDS_REFRESOLVER_CLS"] = (
"invenio_records.resolver.InvenioRefResolver"
)
app_config["RECORDS_REFRESOLVER_STORE"] = local_ref_resolver_store_factory()
return app_config

Expand Down

0 comments on commit f7e18cf

Please sign in to comment.