From f8c9469b3515df5f33feec459810c96cbfac318c Mon Sep 17 00:00:00 2001 From: Marnik Bercx Date: Tue, 11 May 2021 23:51:56 +0200 Subject: [PATCH] More tweakage and testing --- aiida_pseudo/cli/params/types.py | 2 +- aiida_pseudo/groups/mixins/cutoffs.py | 4 ++++ tests/groups/mixins/test_cutoffs.py | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/aiida_pseudo/cli/params/types.py b/aiida_pseudo/cli/params/types.py index 03f57b1..59dfae4 100644 --- a/aiida_pseudo/cli/params/types.py +++ b/aiida_pseudo/cli/params/types.py @@ -145,7 +145,7 @@ def __init__(self, quantity: typing.Optional[typing.List[str]] = None, **kwargs) self.quantity = quantity def convert(self, value, _, __): - """Check if the provided unit is a valid energy unit. + """Check if the provided unit is a valid unit for the defined quantity. :raises: `click.BadParameter` if the provided unit is not valid for the quantity defined for this instance. """ diff --git a/aiida_pseudo/groups/mixins/cutoffs.py b/aiida_pseudo/groups/mixins/cutoffs.py index c68a06b..b13ab20 100644 --- a/aiida_pseudo/groups/mixins/cutoffs.py +++ b/aiida_pseudo/groups/mixins/cutoffs.py @@ -132,7 +132,11 @@ def set_default_stringency(self, default_stringency: str) -> None: :param default_stringency: the default stringency to be used for the recommended cutoffs. :raises ValueError: if the provided default stringency is not in the tuple of available cutoff stringencies for the pseudo family. + :raises ValueError: if the user tries to unset the stringency by providing ``None`` as an input. """ + if default_stringency is None: + raise ValueError('the default stringency cannot be unset.') + self.validate_stringency(default_stringency) self.set_extra(self._key_default_stringency, default_stringency) diff --git a/tests/groups/mixins/test_cutoffs.py b/tests/groups/mixins/test_cutoffs.py index 045e7c8..3e31668 100644 --- a/tests/groups/mixins/test_cutoffs.py +++ b/tests/groups/mixins/test_cutoffs.py @@ -91,6 +91,9 @@ def test_set_default_stringency(get_pseudo_family, generate_cutoffs_dict): assert family.get_default_stringency() == 'low' + with pytest.raises(ValueError, match=r'the default stringency cannot be unset'): + family.set_default_stringency(None) + with pytest.raises(ValueError, match=r'stringency `nonexistent` is not one of the available cutoff stringencies'): family.set_default_stringency('nonexistent')