aboutsummaryrefslogtreecommitdiff
path: root/quality_control/standard_error.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-05-18 10:36:10 +0300
committerFrederick Muriuki Muriithi2022-05-18 10:36:10 +0300
commit582686e030b660f218cb7091aaab3cafa103465d (patch)
treee035d570c0a755031758770f4fcd3b240638e891 /quality_control/standard_error.py
parent4be0ad66b86e238dd92da191061ffc63bee3d09f (diff)
downloadgn-uploader-582686e030b660f218cb7091aaab3cafa103465d.tar.gz
Return errors when found or None otherwise
This commit adds a number of functions that return the error object when an error is found, or `None` otherwise. It avoids the use of exceptions as control flow constructs.
Diffstat (limited to 'quality_control/standard_error.py')
-rw-r--r--quality_control/standard_error.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/quality_control/standard_error.py b/quality_control/standard_error.py
index f1e33c4..022cc9b 100644
--- a/quality_control/standard_error.py
+++ b/quality_control/standard_error.py
@@ -1,6 +1,8 @@
"""Contain logic for checking standard error files"""
import re
+from typing import Union
+from .errors import InvalidValue
from .errors import InvalidCellValue
def valid_value(val):
@@ -11,3 +13,18 @@ def valid_value(val):
f"Invalid value '{val}'. "
"Expected string representing a number with at least six decimal "
"places.")
+
+def invalid_value(line_number: int, column_number: int, val: str) -> Union[
+ InvalidValue, None]:
+ """
+ Returns a `quality_control.errors.InvalidValue` object in the case where
+ `val` is not a valid input for standard error files, otherwise, it returns
+ `None`.
+ """
+ if re.search(r"^[0-9]+\.[0-9]{6,}$", val):
+ return None
+ return InvalidValue(
+ line_number, column_number, val, (
+ f"Invalid value '{val}'. "
+ "Expected string representing a number with at least six decimal "
+ "places."))