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

Implement next and iter for the Node.open deprecation wrapper #4399

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions aiida/orm/nodes/node.py
Expand Up @@ -67,6 +67,12 @@ def __getattr__(self, key):
def __del__(self):
self._warn_if_not_entered('del')

def __iter__(self):
return self._fileobj.__iter__()

def __next__(self):
return self._fileobj.__next__()

def read(self, *args, **kwargs):
self._warn_if_not_entered('read')
return self._fileobj.read(*args, **kwargs)
Expand Down
18 changes: 18 additions & 0 deletions tests/orm/node/test_node.py
Expand Up @@ -9,6 +9,7 @@
###########################################################################
# pylint: disable=too-many-public-methods
"""Tests for the Node ORM class."""
import io
import os
import tempfile

Expand Down Expand Up @@ -842,3 +843,20 @@ def test_store_from_cache():
assert clone.is_stored
assert clone.get_cache_source() == data.uuid
assert data.get_hash() == clone.get_hash()


@pytest.mark.usefixtures('clear_database_before_test')
def test_open_wrapper():
"""Test the wrapper around the return value of ``Node.open``.

This should be remove in v2.0.0 because the wrapper should be removed.
"""
filename = 'test'
node = Node()
node.put_object_from_filelike(io.StringIO('test'), filename)

# Both `iter` and `next` should not raise
next(node.open(filename))
iter(node.open(filename))
node.open(filename).__next__()
node.open(filename).__iter__()