-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ProcessBuilder
: allow unsetting of inputs through attribute deletion (
#4419) The builder object was already able to delete set inputs through the `__delitem__` method, but `__delattr__` was not implemented causing `del builder.input_name` to raise. This is not consistent with how these inputs can be set or accessed as both `__getattr__` and `__setattr__` are implemented. Implementing `__delattr__` brings the implementation up to par for all attribute methods.
- Loading branch information
1 parent
1e1bdf2
commit bd6903d
Showing
2 changed files
with
68 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# -*- coding: utf-8 -*- | ||
########################################################################### | ||
# Copyright (c), The AiiDA team. All rights reserved. # | ||
# This file is part of the AiiDA code. # | ||
# # | ||
# The code is hosted on GitHub at https://github.com/aiidateam/aiida-core # | ||
# For further information on the license, see the LICENSE.txt file # | ||
# For further information please visit http://www.aiida.net # | ||
########################################################################### | ||
"""Tests for `aiida.engine.processes.builder.ProcessBuilder`.""" | ||
import pytest | ||
|
||
from aiida.calculations.arithmetic.add import ArithmeticAddCalculation | ||
from aiida.engine.processes.builder import ProcessBuilder | ||
from aiida import orm | ||
|
||
|
||
def test_access_methods(): | ||
"""Test for the access methods (setter, getter, delete). | ||
The setters are used again after calling the delete in order to check that they still work | ||
after the deletion (including the validation process). | ||
""" | ||
node_numb = orm.Int(4) | ||
node_dict = orm.Dict(dict={'value': 4}) | ||
|
||
# AS ITEMS | ||
builder = ProcessBuilder(ArithmeticAddCalculation) | ||
|
||
builder['x'] = node_numb | ||
assert dict(builder) == {'metadata': {'options': {}}, 'x': node_numb} | ||
|
||
del builder['x'] | ||
assert dict(builder) == {'metadata': {'options': {}}} | ||
|
||
with pytest.raises(ValueError): | ||
builder['x'] = node_dict | ||
|
||
builder['x'] = node_numb | ||
assert dict(builder) == {'metadata': {'options': {}}, 'x': node_numb} | ||
|
||
# AS ATTRIBUTES | ||
del builder | ||
builder = ProcessBuilder(ArithmeticAddCalculation) | ||
|
||
builder.x = node_numb | ||
assert dict(builder) == {'metadata': {'options': {}}, 'x': node_numb} | ||
|
||
del builder.x | ||
assert dict(builder) == {'metadata': {'options': {}}} | ||
|
||
with pytest.raises(ValueError): | ||
builder.x = node_dict | ||
|
||
builder.x = node_numb | ||
assert dict(builder) == {'metadata': {'options': {}}, 'x': node_numb} |