Commit 7e719534 authored by Lauri Himanen's avatar Lauri Himanen
Browse files

Updated the exception messages for missing basis set information.

parent 2d7d0b1b
......@@ -62,7 +62,7 @@ class MethodNormalizer():
try:
method_dict.check(recursive=True)
except (KeyError, ValueError) as e:
self.logger.info("Could not create method hash, missing required information: {}".format(str(e)))
self.logger.info("Could not create method hash: {}".format(e))
else:
method.method_hash = method_dict.hash()
......@@ -72,11 +72,11 @@ class MethodNormalizer():
def group_eos_hash(self, method: Method, material: Material, repr_method: Section):
eos_dict = RestrictedDict(
mandatory_keys=(
mandatory_keys=[
"upload_id",
"method_hash",
"formula",
),
],
forbidden_values=[None]
)
......@@ -93,7 +93,7 @@ class MethodNormalizer():
try:
eos_dict.check(recursive=True)
except (KeyError, ValueError) as e:
self.logger.info("Could not create EOS hash, missing required information: {}".format(str(e)))
self.logger.info("Could not create EOS hash: {}".format(e))
else:
method.group_eos_hash = eos_dict.hash()
......@@ -146,7 +146,7 @@ class MethodNormalizer():
try:
param_dict.check(recursive=True)
except (KeyError, ValueError) as e:
self.logger.info("Could not create parameter variation hash, missing required information: {}".format(str(e)))
self.logger.info("Could not create parameter variation hash: {}".format(e))
else:
method.group_parametervariation_hash = param_dict.hash()
......
......@@ -562,7 +562,7 @@ class RestrictedDict(OrderedDict):
optional_keys: Keys that are optional.
forbidden_values: Values that are forbidden. Only supports hashable values.
lazy: If false, the values are checked already when inserting. If
true, the values are only checked manually by calling the
True, the values should be manually checked by calling the
check()-function.
"""
super().__init__()
......@@ -595,7 +595,7 @@ class RestrictedDict(OrderedDict):
# Check that only the defined keys are used
if key not in self._mandatory_keys and key not in self._optional_keys:
raise KeyError("The key {} is not allowed.".format(key))
raise KeyError("The key '{}' is not allowed.".format(key))
# Check that forbidden values are not used.
try:
......@@ -604,7 +604,7 @@ class RestrictedDict(OrderedDict):
pass # Unhashable value will not match
else:
if match:
raise ValueError("The value {} is not allowed.".format(key))
raise ValueError("The value '{}' is not allowed.".format(key))
super().__setitem__(key, value)
......@@ -612,22 +612,23 @@ class RestrictedDict(OrderedDict):
# Check that only the defined keys are used
for key in self.keys():
if key not in self._mandatory_keys and key not in self._optional_keys:
raise KeyError("The key {} is not allowed.".format(key))
raise KeyError("The key '{}' is not allowed.".format(key))
# Check that all mandatory values are all defined
for key in self._mandatory_keys:
if key not in self:
raise KeyError("The mandatory key {} is not present.".format(key))
raise KeyError("The mandatory key '{}' is not present.".format(key))
# Check that forbidden values are not used.
for value in self.values():
for key, value in self.items():
match = False
try:
match = value in self._forbidden_values
except TypeError:
pass # Unhashable value will not match
else:
if match:
raise ValueError("The value {} is not allowed.".format(key))
raise ValueError("The value '{}' is not allowed but was set for key '{}'.".format(value, key))
# Check recursively
if recursive:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment