consistent behavior with other classes
python dictionary operates in-place, so wrappers for out-of-place behavior let it use like the other DAMASK classes
This commit is contained in:
parent
9a278daa3f
commit
5f1399acc3
|
@ -99,6 +99,30 @@ class Config(dict):
|
|||
fhandle.write(yaml.dump(self,Dumper=NiceDumper,**kwargs))
|
||||
|
||||
|
||||
def add(self,d):
|
||||
"""
|
||||
Add dictionary.
|
||||
|
||||
d : dict
|
||||
Dictionary to append.
|
||||
"""
|
||||
duplicate = self.copy()
|
||||
duplicate.update(d)
|
||||
return duplicate
|
||||
|
||||
|
||||
def delete(self,key):
|
||||
"""
|
||||
Delete item.
|
||||
|
||||
key : dict
|
||||
Label of the key to remove.
|
||||
"""
|
||||
duplicate = self.copy()
|
||||
del duplicate[key]
|
||||
return duplicate
|
||||
|
||||
|
||||
@property
|
||||
@abc.abstractmethod
|
||||
def is_complete(self):
|
||||
|
|
|
@ -22,6 +22,10 @@ class TestConfig:
|
|||
with open(tmp_path/'config.yaml') as f:
|
||||
assert Config.load(f) == config
|
||||
|
||||
def test_add_remove(self):
|
||||
config = Config()
|
||||
assert config.add({'hello':'world'}).delete('hello') == config
|
||||
|
||||
def test_repr(self,tmp_path):
|
||||
config = Config()
|
||||
config['A'] = 1
|
||||
|
|
Loading…
Reference in New Issue