about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-01-05 07:35:04 +0300
committerFrederick Muriuki Muriithi2024-01-05 07:35:04 +0300
commit65c9f923a5057c99c18f43e2c1f0284d8293d9a3 (patch)
treedf89b2f06cf14c7e161598477c22f055576a7848
parent5f5cc8503ec10319ee4d9e7d6bd739cc6190561c (diff)
downloadgn-uploader-65c9f923a5057c99c18f43e2c1f0284d8293d9a3.tar.gz
Revert "QC: Check for only one decimal place."
This reverts commit c213b0010c3ddc8d3215adab65bd489a9b884e30.

After a larger discussion with Arthur, Rob and Pjotr present, it was
verified that the strict checks are important. This reverts the commit
that allowed for looser checks.
-rw-r--r--quality_control/average.py6
-rw-r--r--quality_control/standard_error.py6
-rw-r--r--tests/qc/test_cells.py23
-rw-r--r--tests/qc/test_cells_average.py4
-rw-r--r--tests/qc/test_cells_standard_error.py4
5 files changed, 15 insertions, 28 deletions
diff --git a/quality_control/average.py b/quality_control/average.py
index 95b6c4a..ad732d0 100644
--- a/quality_control/average.py
+++ b/quality_control/average.py
@@ -9,8 +9,8 @@ def invalid_value(line_number: int, column_number: int, val: str) -> Union[
     """Return an `InvalidValue` object if `val` is not a valid "averages"
     value."""
     return cell_error(
-        r"^[0-9]+\.[0-9]{1,}$", val, line=line_number,
+        r"^([0-9]+\.[0-9]{3}|[0-9]+\.?0*)$", val, line=line_number,
         column=column_number, value=val, message=(
             f"Invalid value '{val}'. "
-            "Expected string representing a number with at least one decimal "
-            "place."))
+            "Expected string representing a number with exactly three "
+            "decimal places."))
diff --git a/quality_control/standard_error.py b/quality_control/standard_error.py
index a1646bc..90beb8a 100644
--- a/quality_control/standard_error.py
+++ b/quality_control/standard_error.py
@@ -13,8 +13,8 @@ def invalid_value(
     `None`.
     """
     return cell_error(
-        r"^[0-9]+\.[0-9]{1,}$", val, line=line_number,
+        r"^([0-9]+\.[0-9]{6,}|[0-9]+\.?0*)$", val, line=line_number,
         column=column_number, value=val, message=(
             f"Invalid value '{val}'. "
-            "Expected string representing a number with at least one "
-            "decimal place."))
+            "Expected string representing a number with at least six "
+            "decimal places."))
diff --git a/tests/qc/test_cells.py b/tests/qc/test_cells.py
index 51e8bcf..2bb3358 100644
--- a/tests/qc/test_cells.py
+++ b/tests/qc/test_cells.py
@@ -1,8 +1,7 @@
 """Test that values in cells within a line fulfill the required criteria"""
+
 import re
 from random import randint
-
-import pytest
 from hypothesis import given
 from hypothesis import strategies as st
 
@@ -12,7 +11,7 @@ from quality_control.standard_error import invalid_value as se_invalid_value
 
 @pytest.mark.unit_test
 @given(num_str=st.from_regex(
-    r"^(?!([0-9]+\.[0-9]{1,}|0+)).*", fullmatch=True))
+    r"^(?!(([0-9]+\.([0-9]{3}|[0-9]{6,}))|[0-9]+\.?0*)).*", fullmatch=True))
 def test_cell_value_errors_with_invalid_inputs2(num_str):
     """
     GIVEN: `num_str` is an arbitrary string that is an invalid input,
@@ -24,14 +23,12 @@ def test_cell_value_errors_with_invalid_inputs2(num_str):
     assert avg_invalid_value(0, 0, num_str) == InvalidValue(
         0, 0, num_str, (
             f"Invalid value '{num_str}'. Expected string representing a number "
-            "with at least one decimal place."))
+            "with exactly three decimal places."))
     assert se_invalid_value(0, 0, num_str) == InvalidValue(
         0, 0, num_str, (
             f"Invalid value '{num_str}'. Expected string representing a number "
-            "with at least one decimal place."))
+            "with at least six decimal places."))
 
-@pytest.mark.skip(reason=("Checks changed. We now enforce values must have at "
-                          "least one decimal place"))
 @given(num_str=st.from_regex(
     r"^[0-9]+\.([0-9]{1,2}|[0-9]{4,}$)", fullmatch=True).filter(
         lambda param: not re.match(r"^[0-9]+\.0+$", param)))
@@ -49,11 +46,10 @@ def test_cell_average_value_errors_if_not_three_decimal_places2(num_str):
             f"Invalid value '{num_str}'. Expected string representing a number "
             "with exactly three decimal places."))
 
-@pytest.mark.unit_test
-@given(num_str=st.from_regex(r"^[0-9]+\.[0-9]{1,}$", fullmatch=True))
+@given(num_str=st.from_regex(r"^[0-9]+\.[0-9]{3}$", fullmatch=True))
 def test_cell_average_value_pass_if_three_decimal_places(num_str):
     """
-    GIVEN: `num_str` is a string representing a number with at least one
+    GIVEN: `num_str` is a string representing a number with exactly three
       decimal places, e.g. 2.924, 39.483
     WHEN: `num_str` is provided as an argument to `avg_invalid_value` function,
     THEN: `avg_invalid_value` returns `None`
@@ -61,8 +57,6 @@ def test_cell_average_value_pass_if_three_decimal_places(num_str):
     line, col = randint(0, 100), randint(0, 20)
     assert avg_invalid_value(line, col, num_str) is None
 
-@pytest.mark.skip(reason=("Checks changed. We now enforce values must have at "
-                          "least one decimal place"))
 @given(num_str=st.from_regex(r"^[0-9]+\.([0-9]{0,5}$)", fullmatch=True).filter(
     lambda param: not re.match(r"^[0-9]+\.?0*$", param)))
 def test_cell_standard_error_value_errors_if_less_than_six_decimal_places2(num_str):
@@ -79,11 +73,10 @@ def test_cell_standard_error_value_errors_if_less_than_six_decimal_places2(num_s
             f"Invalid value '{num_str}'. Expected string representing a number "
             "with at least six decimal places."))
 
-@pytest.mark.unit_test
-@given(num_str=st.from_regex(r"^[0-9]+\.[0-9]{1,}$", fullmatch=True))
+@given(num_str=st.from_regex(r"^[0-9]+\.[0-9]{6,}$", fullmatch=True))
 def test_cell_standard_error_value_pass_if_six_or_more_decimal_places(num_str):
     """
-    GIVEN: `num_str` is a string representing a number with one or more
+    GIVEN: `num_str` is a string representing a number with six or more
       decimal places, e.g. 2.938434, 39.4837343
     WHEN: `num_str` is provided as an argument to `se_invalid_value` function,
     THEN: `se_invalid_value` returns `None`
diff --git a/tests/qc/test_cells_average.py b/tests/qc/test_cells_average.py
index cf23e13..68fd4ec 100644
--- a/tests/qc/test_cells_average.py
+++ b/tests/qc/test_cells_average.py
@@ -1,14 +1,10 @@
 """Test average values."""
 from random import randint
-
-import pytest
 from hypothesis import given
 from hypothesis import strategies as st
 
 from quality_control.average import invalid_value as avg_invalid_value
 
-@pytest.mark.skip(reason=("Checks changed. We now enforce values must have at "
-                          "least one decimal place"))
 @given(num_str=st.from_regex(r"^[0-9]+$", fullmatch=True))
 def test_cell_average_value_pass_if_no_decimal_places(num_str):
     """
diff --git a/tests/qc/test_cells_standard_error.py b/tests/qc/test_cells_standard_error.py
index 754db22..90c13cf 100644
--- a/tests/qc/test_cells_standard_error.py
+++ b/tests/qc/test_cells_standard_error.py
@@ -1,14 +1,12 @@
 """Test standard error values."""
 from random import randint
 
-import pytest
+
 from hypothesis import given
 from hypothesis import strategies as st
 
 from quality_control.standard_error import invalid_value
 
-@pytest.mark.skip(reason=("Checks changed. We now enforce values must have at "
-                          "least one decimal place"))
 @given(num_str=st.from_regex(r"^[0-9]+\.?0*", fullmatch=True))
 def test_cell_standard_error_value_errors_if_less_than_six_decimal_places2(num_str):
     """