diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4149996467f0e65c3f277c858fef2670bbc7fd1c..c29a01fae3d831562f39d308584ed45f2fb05ec8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -83,7 +83,7 @@ jobs: # AK, 2020-12-13 rm pytools/mpiwrap.py - EXTRA_INSTALL="numpy frozendict immutabledict orderedsets" + EXTRA_INSTALL="numpy frozendict immutabledict orderedsets constantdict immutables pyrsistent" curl -L -O https://gitlab.tiker.net/inducer/ci-support/raw/main/build-and-test-py-project.sh . ./build-and-test-py-project.sh diff --git a/pytools/persistent_dict.py b/pytools/persistent_dict.py index b979214260874c3f8b0ba7fc8b87daf148d9ac6f..421e02a1d72fd099fcd20723e7461cba95a9074e 100644 --- a/pytools/persistent_dict.py +++ b/pytools/persistent_dict.py @@ -402,6 +402,9 @@ class KeyBuilder: (self.rec(self.new_hash(), (k, v)).digest() for k, v in key.items())) update_for_immutabledict = update_for_frozendict + update_for_constantdict = update_for_frozendict + update_for_PMap = update_for_frozendict # noqa: N815 + update_for_Map = update_for_frozendict # noqa: N815 # }}} diff --git a/pytools/test/test_persistent_dict.py b/pytools/test/test_persistent_dict.py index dd7f9a28c480aac28e81eacb9577b73cfd384c70..eb22ec65b9e44b26a9fe3a5aa1abe733e413eb40 100644 --- a/pytools/test/test_persistent_dict.py +++ b/pytools/test/test_persistent_dict.py @@ -421,33 +421,29 @@ def test_scalar_hashing(): assert keyb(np.clongdouble(1.1+2.2j)) == keyb(np.clongdouble(1.1+2.2j)) -def test_frozendict_hashing(): - pytest.importorskip("frozendict") - from frozendict import frozendict - - keyb = KeyBuilder() - - d = {"a": 1, "b": 2} - - assert keyb(frozendict(d)) == keyb(frozendict(d)) - assert keyb(frozendict(d)) != keyb(frozendict({"a": 1, "b": 3})) - assert keyb(frozendict(d)) == keyb(frozendict({"b": 2, "a": 1})) - - with pytest.raises(TypeError): - keyb(d) - +@pytest.mark.parametrize("dict_impl", ("immutabledict", "frozendict", + "constantdict", + ("immutables", "Map"), + ("pyrsistent", "pmap"))) +def test_dict_hashing(dict_impl): + if isinstance(dict_impl, str): + dict_package = dict_impl + dict_class = dict_impl + else: + dict_package = dict_impl[0] + dict_class = dict_impl[1] -def test_immutabledict_hashing(): - pytest.importorskip("immutabledict") - from immutabledict import immutabledict + pytest.importorskip(dict_package) + import importlib + dc = getattr(importlib.import_module(dict_package), dict_class) keyb = KeyBuilder() d = {"a": 1, "b": 2} - assert keyb(immutabledict(d)) == keyb(immutabledict(d)) - assert keyb(immutabledict(d)) != keyb(immutabledict({"a": 1, "b": 3})) - assert keyb(immutabledict(d)) == keyb(immutabledict({"b": 2, "a": 1})) + assert keyb(dc(d)) == keyb(dc(d)) + assert keyb(dc(d)) != keyb(dc({"a": 1, "b": 3})) + assert keyb(dc(d)) == keyb(dc({"b": 2, "a": 1})) def test_frozenset_hashing():