Skip to content

Commit 696bbb8

Browse files
committed
docstrings for parsers and test parsers
1 parent 1e33dc1 commit 696bbb8

File tree

7 files changed

+35
-5
lines changed

7 files changed

+35
-5
lines changed

lambdas/shared/src/common/validator/parsers/csv_parser.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ def __init__(self):
1616
self.csv_file_data = {}
1717

1818
# parse the CSV into a Dictionary
19+
"""
20+
Takes a CSV file with numerous fields (that uses pipe delimiter) and parses it into a list of dictionaries using csv.DictReader.
21+
Then create a key for each header and attached a list of all the value to that key. So a one to many relationship
22+
is created between the header and the values.
23+
"""
24+
1925
def parse_csv_file(self, csv_filename: str, delimiter: str = "|") -> None:
2026
with open(csv_filename, newline="", encoding="utf-8") as file:
2127
csv_to_dict = csv.DictReader(file, delimiter=delimiter)
@@ -25,6 +31,12 @@ def parse_csv_file(self, csv_filename: str, delimiter: str = "|") -> None:
2531
for key in csv_header_to_keys:
2632
self.csv_file_data[key].append(row[key])
2733

34+
"""
35+
Retrieves all values associated with the specified column header (key).
36+
:param field_name: The column header whose values are to be retrieved.
37+
:return: A list of values under the specified column header or key.
38+
"""
39+
2840
# retrieve a column of data to work with
2941
def get_key_value(self, field_name: str) -> list[str]:
3042
retrieve_column_data = self.csv_file_data[field_name]

lambdas/shared/src/common/validator/validator.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# Main validation engine
1+
"""
2+
1. Runs the CSV and FHIR Parsers (where Extraction of the values occurs and collates extraction error reports)
3+
2. Runs the Expresssion Checker against each expression in the schema
4+
3. Collects all error records and builds the final error report
5+
"""
26

37
from enum import Enum
48

@@ -213,7 +217,6 @@ def run_validation(
213217

214218
return self.error_records
215219

216-
# -------------------------------------------------------------------------
217220
# Report Generation
218221
# Build the error Report
219222
def build_error_report(self, event_id):

lambdas/shared/tests/test_common/validator/test_csv_parser.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99

1010
class TestCSVParser(unittest.TestCase):
11+
"""
12+
Unit tests for the CSVParser class to ensure correct parsing of Full CSV files
13+
"""
14+
1115
def _write_temp_csv(self, content: str) -> str:
1216
fd, path = tempfile.mkstemp(suffix=".csv")
1317
Path(path).write_text(content, encoding="utf-8")
@@ -24,13 +28,12 @@ def test_parse_file_with_pipe_delimiter(self):
2428
Path(path).unlink(missing_ok=True)
2529

2630
def test_missing_column_raises_keyerror(self):
27-
csv_content = "a|b\n1|2\n"
28-
path = self._write_temp_csv(csv_content)
31+
path = self._write_temp_csv(CSV_FILE)
2932
try:
3033
p = CSVParser()
3134
p.parse_csv_file(path, delimiter="|")
3235
with self.assertRaises(KeyError):
33-
_ = p.get_key_value("c")
36+
_ = p.get_key_value("NHS_CODE")
3437
finally:
3538
Path(path).unlink(missing_ok=True)
3639

lambdas/shared/tests/test_common/validator/test_key_data.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55

66
class TestKeyData(unittest.TestCase):
7+
"""
8+
Unit tests for the KeyData lookup class to ensure correct key code validation
9+
"""
10+
711
def setUp(self):
812
self.kd = KeyData()
913

lambdas/shared/tests/test_common/validator/test_lookup_data.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55

66
class TestLookUpData(unittest.TestCase):
7+
"""
8+
Unit tests for the LookUpData lookup class to ensure correct lookup code validation
9+
"""
10+
711
def setUp(self):
812
self.lookup = LookUpData()
913

lambdas/shared/tests/test_common/validator/test_validate_csv_row.py renamed to lambdas/shared/tests/test_common/validator/test_validation_csv_row.py

File renamed without changes.

lambdas/shared/tests/test_common/validator/test_validation_csv_small.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77

88
class TestValidator(unittest.TestCase):
9+
"""
10+
Unit tests for the CSV validation logic using the Validator class with a small CSV schema.
11+
"""
12+
913
def setUp(self):
1014
self.parent_folder = Path(__file__).parent
1115
schema_file_path = self.parent_folder / "test_schemas/test_small_schema.json"

0 commit comments

Comments
 (0)