aboutsummaryrefslogtreecommitdiff
path: root/quality_control/standard_error.py
blob: 022cc9b2e6339325d034d4dcefcae832dcfb7280 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""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):
    """Checks whether `val` is a valid value for standard errors"""
    if re.search(r"^[0-9]+\.[0-9]{6,}$", val):
        return float(val)
    raise InvalidCellValue(
        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."))