Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dict: implement items() method #5333

Merged
merged 1 commit into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions aiida/orm/nodes/data/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ def keys(self):
for key in self.attributes.keys():
yield key

def items(self):
"""Iterator of all items stored in the Dict node."""
for key, value in self.attributes_items():
yield key, value

@property
def dict(self):
"""Return an instance of `AttributeManager` that transforms the dictionary into an attribute dict.
Expand Down
7 changes: 7 additions & 0 deletions tests/orm/nodes/data/test_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ def test_keys(dictionary):
assert sorted(node.keys()) == sorted(dictionary.keys())


@pytest.mark.usefixtures('clear_database_before_test')
def test_items(dictionary):
"""Test the ``items`` method."""
node = Dict(dictionary)
assert sorted(node.items()) == sorted(dictionary.items())


@pytest.mark.usefixtures('clear_database_before_test')
def test_get_dict(dictionary):
"""Test the ``get_dict`` method."""
Expand Down