aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--quality_control/__init__.py4
-rw-r--r--quality_control/average.py7
-rw-r--r--quality_control/errors.py8
-rw-r--r--quality_control/standard_error.py7
-rw-r--r--tests/qc/__init__.py0
-rw-r--r--tests/qc/qc/test_cells.py25
-rw-r--r--tests/qc/test_cells.py40
7 files changed, 66 insertions, 25 deletions
diff --git a/quality_control/__init__.py b/quality_control/__init__.py
new file mode 100644
index 0000000..a5df3aa
--- /dev/null
+++ b/quality_control/__init__.py
@@ -0,0 +1,4 @@
+"""
+Quality Control (qc): contains the logic for testing validity of values in the
+ uploaded files.
+"""
diff --git a/quality_control/average.py b/quality_control/average.py
new file mode 100644
index 0000000..6ed0da7
--- /dev/null
+++ b/quality_control/average.py
@@ -0,0 +1,7 @@
+"""Contain logic for checking average files"""
+import re
+
+from .errors import InvalidValue
+
+def valid_value(val):
+ return None
diff --git a/quality_control/errors.py b/quality_control/errors.py
new file mode 100644
index 0000000..961ce8e
--- /dev/null
+++ b/quality_control/errors.py
@@ -0,0 +1,8 @@
+"""Hold exceptions for QC package"""
+
+class InvalidValue(Exception):
+ """Raised when a function encounters an invalid value"""
+
+ def __init__(self, args):
+ Exception.__init__(self, args)
+
diff --git a/quality_control/standard_error.py b/quality_control/standard_error.py
new file mode 100644
index 0000000..9a91d1b
--- /dev/null
+++ b/quality_control/standard_error.py
@@ -0,0 +1,7 @@
+"""Contain logic for checking standard error files"""
+import re
+
+from .errors import InvalidValue
+
+def valid_value(val):
+ return None
diff --git a/tests/qc/__init__.py b/tests/qc/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/qc/__init__.py
diff --git a/tests/qc/qc/test_cells.py b/tests/qc/qc/test_cells.py
deleted file mode 100644
index 8f1e9ea..0000000
--- a/tests/qc/qc/test_cells.py
+++ /dev/null
@@ -1,25 +0,0 @@
-"""Test that values in cells within a line fulfill the required criteria"""
-
-from hypothesis import given
-from hypothesis import strategies as st
-
-@given(num_str=st.from_regex("^(?!([0-9]+\.([0-9]{3}|[0-9]{6,}))).*", fullmatch=True))
-def test_cell_value_errors_with_invalid_inputs(num_str):
- print(f"NUMBER STRING: {num_str}")
- assert False, "Not implemented"
-
-@given(num_str=st.from_regex("[0-9]+\.([0-9]{1,2}|[0-9]{4,})", fullmatch=True))
-def test_cell_average_value_errors_if_not_three_decimal_places(num_str):
- assert False, "Not implemented"
-
-@given(num_str=st.from_regex("[0-9]+\.[0-9]{3}", fullmatch=True))
-def test_cell_average_value_pass_if_three_decimal_places(num_str):
- assert False, "Not implemented"
-
-@given(num_str=st.from_regex("[0-9]+\.([0-9]{0,5})", fullmatch=True))
-def test_cell_standard_error_value_errors_if_less_than_six_decimal_places(num_str):
- assert False, "Not implemented"
-
-@given(num_str=st.from_regex("[0-9]+\.[0-9]{6,}", fullmatch=True))
-def test_cell_standard_error_value_pass_if_six_or_more_decimal_places(num_str):
- assert False, "Not implemented"
diff --git a/tests/qc/test_cells.py b/tests/qc/test_cells.py
new file mode 100644
index 0000000..b105286
--- /dev/null
+++ b/tests/qc/test_cells.py
@@ -0,0 +1,40 @@
+"""Test that values in cells within a line fulfill the required criteria"""
+
+import pytest
+from hypothesis import given
+from hypothesis import strategies as st
+
+from quality_control.errors import InvalidValue
+from quality_control.average import valid_value as avg_valid_value
+from quality_control.standard_error import valid_value as se_valid_value
+
+@given(num_str=st.from_regex("^(?!([0-9]+\.([0-9]{3}|[0-9]{6,}))).*", fullmatch=True))
+def test_cell_value_errors_with_invalid_inputs(num_str):
+ with pytest.raises(InvalidValue):
+ avg_valid_value(num_str)
+ with pytest.raises(InvalidValue):
+ se_valid_value(num_str)
+
+@given(num_str=st.from_regex("^[0-9]+\.([0-9]{1,2}|[0-9]{4,}$)", fullmatch=True))
+def test_cell_average_value_errors_if_not_three_decimal_places(num_str):
+ with pytest.raises(InvalidValue):
+ avg_valid_value(num_str)
+
+@given(num_str=st.from_regex("^[0-9]+\.[0-9]{3}$", fullmatch=True))
+def test_cell_average_value_pass_if_three_decimal_places(num_str):
+ processed = avg_valid_value(num_str)
+ assert (
+ isinstance(processed, float) and
+ processed == float(num_str))
+
+@given(num_str=st.from_regex("^[0-9]+\.([0-9]{0,5}$)", fullmatch=True))
+def test_cell_standard_error_value_errors_if_less_than_six_decimal_places(num_str):
+ with pytest.raises(InvalidValue):
+ se_valid_value(num_str)
+
+@given(num_str=st.from_regex("^[0-9]+\.[0-9]{6,}$", fullmatch=True))
+def test_cell_standard_error_value_pass_if_six_or_more_decimal_places(num_str):
+ processed = se_valid_value(num_str)
+ assert (
+ isinstance(processed, float) and
+ processed == float(num_str))