aboutsummaryrefslogtreecommitdiff
path: root/quality_control
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-02-12 13:03:35 +0300
committerFrederick Muriuki Muriithi2024-02-12 18:17:42 +0300
commit092ae35512b3ef236622c4ab9dfe2bafb221ded7 (patch)
tree276d985f68b89051ed031486cac0b233b9345eec /quality_control
parent68696caeedde3636aff34db048a4490fbf51edf3 (diff)
downloadgn-uploader-092ae35512b3ef236622c4ab9dfe2bafb221ded7.tar.gz
Refactor: Use new decimal places checker.
Diffstat (limited to 'quality_control')
-rw-r--r--quality_control/checks.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/quality_control/checks.py b/quality_control/checks.py
index 28b9ab5..475eb9e 100644
--- a/quality_control/checks.py
+++ b/quality_control/checks.py
@@ -2,6 +2,8 @@
import re
from typing import Optional
+from .errors import InvalidValue
+
def decimal_places_pattern(mini: int, maxi: Optional[int] = None) -> re.Pattern:
"""
Generate a regular expression for checking numbers
@@ -49,3 +51,19 @@ def decimal_places_pattern(mini: int, maxi: Optional[int] = None) -> re.Pattern:
+ r"}"
+ r")$"
)
+
+def decimal_points_error(lineno: int,
+ field: str,
+ value: str,
+ mini: int,
+ maxi: Optional[int] = None) -> Optional[InvalidValue]:
+ """
+ Check that 'value' in a decimal number with the appropriate decimal places.
+ """
+ if not bool(decimal_places_pattern(mini, maxi).match(value)):
+ return InvalidValue(lineno, field, value, (
+ f"Invalid value '{value}'. Expected numerical value " +
+ f"with at least {mini} decimal places" +
+ (f" and at most {maxi} decimal places" if maxi is not None else "")
+ + "."))
+ return None