Skip to content

Commit 8ed7160

Browse files
authored
Merge pull request #265 from NHSDigital/relative-test-data
Make paths to test data relative
2 parents c2deaf3 + fe1af10 commit 8ed7160

File tree

6 files changed

+82
-82
lines changed

6 files changed

+82
-82
lines changed

libs/mavis_constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ class mavis_file_types(Enum):
8383

8484

8585
class test_data_file_paths:
86-
PARENTAL_CONSENT_HPV: Final[str] = "test_data/ParentalConsent_HPV.xlsx"
87-
PARENTAL_CONSENT_DOUBLES: Final[str] = "test_data/ParentalConsent_Doubles.xlsx"
86+
PARENTAL_CONSENT_HPV: Final[str] = "ParentalConsent_HPV.xlsx"
87+
PARENTAL_CONSENT_DOUBLES: Final[str] = "ParentalConsent_Doubles.xlsx"
8888
VACCS_POSITIVE: Final[str] = "VACCS_HPV_POSITIVE"
8989
VACCS_NEGATIVE: Final[str] = "VACCS_HPV_NEGATIVE"
9090
VACCS_HIST_POSITIVE: Final[str] = "VACCS_HIST_HPV_POSITIVE"

libs/test_data.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import pathlib
1+
from pathlib import Path
22
from typing import Optional
33

44
import nhs_number
@@ -18,14 +18,14 @@ class TestData:
1818
A class to handle operations related to test data.
1919
"""
2020

21+
template_path = Path("test_data")
22+
working_path = Path("working")
23+
2124
def __init__(self):
22-
"""
23-
Initialize the testdata_operations class.
24-
"""
25-
self.mapping_df: pd.DataFrame = pd.read_csv("test_data/file_mapping.csv")
25+
self.file_mapping = pd.read_csv(self.template_path / "file_mapping.csv")
2626

27-
def read_file(self, path):
28-
return pathlib.Path(path).read_text(encoding="utf-8")
27+
def read_file(self, filename):
28+
return (self.template_path / filename).read_text(encoding="utf-8")
2929

3030
def create_file_from_template(
3131
self,
@@ -85,9 +85,8 @@ def create_file_from_template(
8585

8686
filename = f"{file_name_prefix}{get_current_datetime()}.csv"
8787

88-
path = pathlib.Path("working") / filename
88+
path = self.working_path / filename
8989
path.write_text("\n".join(_file_text), encoding="utf-8")
90-
9190
return str(path)
9291

9392
def get_new_nhs_no(self, valid=True) -> str:
@@ -119,23 +118,27 @@ def get_expected_errors(self, file_path: str):
119118
return file_content.splitlines() if file_content else None
120119

121120
def read_spreadsheet(
122-
self, file_path: str, clean_df: bool = True, sheet_name: str = "Sheet1"
121+
self, filename: str, sheet_name: str = "Sheet1"
123122
) -> pd.DataFrame:
124123
"""
125124
Read a spreadsheet into a DataFrame.
126125
127126
Args:
128-
file_path (str): Path to the spreadsheet file.
129-
clean_df (bool, optional): Whether to clean the DataFrame. Defaults to True.
127+
filename (str): Path to the spreadsheet file.
130128
sheet_name (str, optional): Name of the sheet to read. Defaults to "Sheet1".
131129
132130
Returns:
133131
pd.DataFrame: DataFrame containing the spreadsheet data.
134132
"""
135-
_df = pd.read_excel(
136-
file_path, sheet_name=sheet_name, header=0, dtype="str", index_col=0
133+
return self.clean_df(
134+
pd.read_excel(
135+
self.template_path / filename,
136+
sheet_name=sheet_name,
137+
header=0,
138+
dtype="str",
139+
index_col=0,
140+
)
137141
)
138-
return self.clean_df(df=_df) if clean_df else _df
139142

140143
def clean_df(self, df: pd.DataFrame) -> pd.DataFrame:
141144
"""
@@ -170,7 +173,7 @@ def get_file_paths(
170173
Returns:
171174
tuple[str, str]: Input and output file paths.
172175
"""
173-
query = self.mapping_df.query("ID==@file_paths")
176+
query = self.file_mapping.query("ID==@file_paths")
174177

175178
_input_template_path: str = query["INPUT_TEMPLATE"].to_string(index=False)
176179
_output_template_path: str = query["OUTPUT_TEMPLATE"].to_string(index=False)
@@ -210,17 +213,16 @@ def create_child_list_from_file(self, file_path: str, file_type: mavis_file_type
210213
_names_list = _file_df[_cols[0]] + ", " + _file_df[_cols[1]].values.tolist()
211214
return _names_list
212215

213-
def get_session_id(self, excel_path: str) -> str:
216+
def get_session_id(self, path: str) -> str:
214217
"""
215218
Get the session ID from an Excel file.
216219
217220
Args:
218-
excel_path (str): Path to the Excel file.
221+
path (str): Path to the Excel file.
219222
220223
Returns:
221224
str: Session ID.
222225
"""
223-
_df = self.read_spreadsheet(
224-
file_path=excel_path, clean_df=False, sheet_name="Vaccinations"
225-
)
226-
return _df["SESSION_ID"].iloc[0]
226+
227+
data_frame = pd.read_excel(path, sheet_name="Vaccinations")
228+
return data_frame["SESSION_ID"].iloc[0]

pages/sessions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def download_offline_recording_excel(self) -> str:
313313

314314
def get_session_id_from_offline_excel(self):
315315
file_path = self.download_offline_recording_excel()
316-
return self.tdo.get_session_id(excel_path=file_path)
316+
return self.tdo.get_session_id(file_path)
317317

318318
def add_gillick_competence(
319319
self, is_competent: bool, competence_details: str

test_data/file_mapping.csv

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
11
ID,INPUT_TEMPLATE,OUTPUT_TEMPLATE,FILE_PREFIX
2-
VACCS_HPV_POSITIVE,test_data/vaccs/i_positive.csv,test_data/vaccs/o_positive.csv,hpvpos
3-
VACCS_HPV_NEGATIVE,test_data/vaccs/i_negative.csv,test_data/vaccs/o_negative.csv,hpvneg
4-
VACCS_HIST_HPV_POSITIVE,test_data/vaccs/i_hist_positive.csv,test_data/vaccs/o_hist_positive.csv,hpvhistpos
5-
VACCS_HIST_HPV_NEGATIVE,test_data/vaccs/i_hist_negative.csv,test_data/vaccs/o_hist_negative.csv,hpvhistneg
6-
VACCS_HPV_DUP_1,test_data/vaccs/i_dup_1.csv,test_data/vaccs/o_dup_1.csv,hpvdup1
7-
VACCS_HPV_DUP_2,test_data/vaccs/i_dup_2.csv,test_data/vaccs/o_dup_2.csv,hpvdup2
8-
VACCS_HPV_INVALID_STRUCTURE,test_data/vaccs/i_invalid_structure.csv,test_data/vaccs/o_invalid_structure.csv,hpvstruc
9-
VACCS_HPV_EMPTY_FILE,test_data/vaccs/i_empty.csv,test_data/vaccs/o_empty.csv,hpvempty
10-
VACCS_HPV_HEADER_ONLY,test_data/vaccs/i_header_only.csv,test_data/vaccs/o_header_only.csv,hpvheadonly
11-
VACCS_HPV_MAV_853,test_data/vaccs/i_mav_853.csv,test_data/vaccs/o_mav_853.csv,hpvmav853
12-
VACCS_HPV_MAV_855,test_data/vaccs/i_mav_855.csv,test_data/vaccs/o_mav_855.csv,hpvmav855
13-
VACCS_HPV_DOSE_TWO,test_data/vaccs/i_dose_two.csv,test_data/vaccs/o_dose_two.csv,hpvdose2
14-
VACCS_MAV_1080,test_data/vaccs/i_mav_1080.csv,test_data/vaccs/o_mav_1080.csv,hpvmav1080
15-
VACCS_SYSTMONE_POSITIVE,test_data/vaccs/i_systmone_positive.csv,test_data/vaccs/o_systmone_positive.csv,systmonepos
16-
VACCS_SYSTMONE_NEGATIVE,test_data/vaccs/i_systmone_negative.csv,test_data/vaccs/o_systmone_negative.csv,systmoneneg
17-
VACCS_SYSTMONE_HIST_NEGATIVE,test_data/vaccs/i_systmone_hist_negative.csv,test_data/vaccs/o_systmone_hist_negative.csv,systmonehistneg
18-
VACCS_SYSTMONE_MAV_1080,test_data/vaccs/i_systmone_mav_1080.csv,test_data/vaccs/o_systmone_mav_1080.csv,systmonemav1080
19-
COHORTS_POSITIVE,test_data/cohorts/i_positive.csv,test_data/cohorts/o_positive.csv,cohortpos
20-
COHORTS_NEGATIVE,test_data/cohorts/i_negative.csv,test_data/cohorts/o_negative.csv,cohortneg
21-
COHORTS_INVALID_STRUCTURE,test_data/cohorts/i_invalid_structure.csv,test_data/cohorts/o_invalid_structure.csv,cohortstruc
22-
COHORTS_EMPTY_FILE,test_data/cohorts/i_empty.csv,test_data/cohorts/o_empty.csv,cohortempty
23-
COHORTS_HEADER_ONLY,test_data/cohorts/i_header_only.csv,test_data/cohorts/o_header_only.csv,cohortheadonly
24-
CHILD_POSITIVE,test_data/child/i_positive.csv,test_data/child/o_positive.csv,childpos
25-
CHILD_NEGATIVE,test_data/child/i_negative.csv,test_data/child/o_negative.csv,childneg
26-
CHILD_INVALID_STRUCTURE,test_data/child/i_invalid_structure.csv,test_data/child/o_invalid_structure.csv,childstruc
27-
CHILD_EMPTY_FILE,test_data/child/i_empty.csv,test_data/child/o_empty.csv,childempty
28-
CHILD_HEADER_ONLY,test_data/child/i_header_only.csv,test_data/child/o_header_only.csv,childheadonly
29-
CHILD_MAV_1080,test_data/child/i_mav_1080.csv,test_data/child/o_mav_1080.csv,childmav1080
30-
CLASS_POSITIVE,test_data/class_list/i_positive.csv,test_data/class_list/o_positive.csv,classpos
31-
CLASS_NEGATIVE,test_data/class_list/i_negative.csv,test_data/class_list/o_negative.csv,classneg
32-
CLASS_INVALID_STRUCTURE,test_data/class_list/i_invalid_structure.csv,test_data/class_list/o_invalid_structure.csv,classstruc
33-
CLASS_EMPTY_FILE,test_data/class_list/i_empty.csv,test_data/class_list/o_empty.csv,classempty
34-
CLASS_HEADER_ONLY,test_data/class_list/i_header_only.csv,test_data/class_list/o_header_only.csv,classheadonly
35-
CLASS_CHILDREN_FILTER,test_data/class_list/i_children_filter.csv,test_data/class_list/o_children_filter.csv,classfilter
36-
CLASS_YEAR_GROUP,test_data/class_list/i_year_group.csv,test_data/class_list/o_year_group.csv,classyeargrp
37-
CLASS_MAV_854,test_data/class_list/i_mav_854.csv,test_data/class_list/o_mav_854.csv,classmav854
38-
CLASS_SESSION_ID,test_data/class_list/i_session_id.csv,test_data/class_list/o_session_id.csv,classsessid
39-
CLASS_SINGLE_VACC,test_data/class_list/i_single_vacc.csv,test_data/class_list/o_single_vacc.csv,classsinglevacc
40-
CLASS_MAV_965,test_data/class_list/i_mav_965.csv,test_data/class_list/o_mav_965.csv,classmav965
41-
CLASS_CHANGE_NHSNO,test_data/class_list/i_change_nhsno.csv,test_data/class_list/o_change_nhsno.csv,classchangenhsno
42-
CLASS_MAV_1080,test_data/class_list/i_mav_1080.csv,test_data/class_list/o_mav_1080.csv,classmav1080
43-
COHORTS_NO_CONSENT,test_data/cohorts/i_no_consent.csv,test_data/cohorts/o_no_consent.csv,cohortnoconsent
44-
COHORTS_CONFLICTING_CONSENT,test_data/cohorts/i_conflicting_consent.csv,test_data/cohorts/o_conflicting_consent.csv,cohortconflict
45-
COHORTS_E2E_1,test_data/cohorts/i_e2e_1.csv,test_data/cohorts/o_e2e_1.csv,cohort_e2e
46-
COHORTS_UCR_MATCH,test_data/cohorts/i_ucr_match.csv,test_data/cohorts/o_ucr_match.csv,cohortmatch
47-
COHORTS_CONSENT_TWICE,test_data/cohorts/i_consent_twice.csv,test_data/cohorts/o_consent_twice.csv,cohorttwice
48-
COHORTS_CONFLICTING_GILLICK,test_data/cohorts/i_conflicting_gillick.csv,test_data/cohorts/o_conflicting_gillick.csv,cohortgillick
49-
COHORTS_FULL_NAME,test_data/cohorts/i_full_name.csv,test_data/cohorts/o_full_name.csv,cohortfullname
50-
COHORTS_MAV_927_PERF,test_data/cohorts/i_mav_927_perf.csv,test_data/cohorts/o_mav_927_perf.csv,cohortmav927perf
51-
COHORTS_MAV_909,test_data/cohorts/i_mav_909.csv,test_data/cohorts/o_mav_909.csv,cohortmav909
52-
COHORTS_MAV_853,test_data/cohorts/i_mav_853.csv,test_data/cohorts/o_mav_853.csv,cohortmav853
53-
CLASS_MOVES_CONFIRM_IGNORE,test_data/class_list/i_moves_1.csv,test_data/class_list/o_moves_1.csv,classmoves1
54-
CLASS_MOVES_UNKNOWN_HOMESCHOOLED,test_data/class_list/i_moves_2.csv,test_data/class_list/o_moves_2.csv,classmoves2
2+
VACCS_HPV_POSITIVE,vaccs/i_positive.csv,vaccs/o_positive.csv,hpvpos
3+
VACCS_HPV_NEGATIVE,vaccs/i_negative.csv,vaccs/o_negative.csv,hpvneg
4+
VACCS_HIST_HPV_POSITIVE,vaccs/i_hist_positive.csv,vaccs/o_hist_positive.csv,hpvhistpos
5+
VACCS_HIST_HPV_NEGATIVE,vaccs/i_hist_negative.csv,vaccs/o_hist_negative.csv,hpvhistneg
6+
VACCS_HPV_DUP_1,vaccs/i_dup_1.csv,vaccs/o_dup_1.csv,hpvdup1
7+
VACCS_HPV_DUP_2,vaccs/i_dup_2.csv,vaccs/o_dup_2.csv,hpvdup2
8+
VACCS_HPV_INVALID_STRUCTURE,vaccs/i_invalid_structure.csv,vaccs/o_invalid_structure.csv,hpvstruc
9+
VACCS_HPV_EMPTY_FILE,vaccs/i_empty.csv,vaccs/o_empty.csv,hpvempty
10+
VACCS_HPV_HEADER_ONLY,vaccs/i_header_only.csv,vaccs/o_header_only.csv,hpvheadonly
11+
VACCS_HPV_MAV_853,vaccs/i_mav_853.csv,vaccs/o_mav_853.csv,hpvmav853
12+
VACCS_HPV_MAV_855,vaccs/i_mav_855.csv,vaccs/o_mav_855.csv,hpvmav855
13+
VACCS_HPV_DOSE_TWO,vaccs/i_dose_two.csv,vaccs/o_dose_two.csv,hpvdose2
14+
VACCS_MAV_1080,vaccs/i_mav_1080.csv,vaccs/o_mav_1080.csv,hpvmav1080
15+
VACCS_SYSTMONE_POSITIVE,vaccs/i_systmone_positive.csv,vaccs/o_systmone_positive.csv,systmonepos
16+
VACCS_SYSTMONE_NEGATIVE,vaccs/i_systmone_negative.csv,vaccs/o_systmone_negative.csv,systmoneneg
17+
VACCS_SYSTMONE_HIST_NEGATIVE,vaccs/i_systmone_hist_negative.csv,vaccs/o_systmone_hist_negative.csv,systmonehistneg
18+
VACCS_SYSTMONE_MAV_1080,vaccs/i_systmone_mav_1080.csv,vaccs/o_systmone_mav_1080.csv,systmonemav1080
19+
COHORTS_POSITIVE,cohorts/i_positive.csv,cohorts/o_positive.csv,cohortpos
20+
COHORTS_NEGATIVE,cohorts/i_negative.csv,cohorts/o_negative.csv,cohortneg
21+
COHORTS_INVALID_STRUCTURE,cohorts/i_invalid_structure.csv,cohorts/o_invalid_structure.csv,cohortstruc
22+
COHORTS_EMPTY_FILE,cohorts/i_empty.csv,cohorts/o_empty.csv,cohortempty
23+
COHORTS_HEADER_ONLY,cohorts/i_header_only.csv,cohorts/o_header_only.csv,cohortheadonly
24+
CHILD_POSITIVE,child/i_positive.csv,child/o_positive.csv,childpos
25+
CHILD_NEGATIVE,child/i_negative.csv,child/o_negative.csv,childneg
26+
CHILD_INVALID_STRUCTURE,child/i_invalid_structure.csv,child/o_invalid_structure.csv,childstruc
27+
CHILD_EMPTY_FILE,child/i_empty.csv,child/o_empty.csv,childempty
28+
CHILD_HEADER_ONLY,child/i_header_only.csv,child/o_header_only.csv,childheadonly
29+
CHILD_MAV_1080,child/i_mav_1080.csv,child/o_mav_1080.csv,childmav1080
30+
CLASS_POSITIVE,class_list/i_positive.csv,class_list/o_positive.csv,classpos
31+
CLASS_NEGATIVE,class_list/i_negative.csv,class_list/o_negative.csv,classneg
32+
CLASS_INVALID_STRUCTURE,class_list/i_invalid_structure.csv,class_list/o_invalid_structure.csv,classstruc
33+
CLASS_EMPTY_FILE,class_list/i_empty.csv,class_list/o_empty.csv,classempty
34+
CLASS_HEADER_ONLY,class_list/i_header_only.csv,class_list/o_header_only.csv,classheadonly
35+
CLASS_CHILDREN_FILTER,class_list/i_children_filter.csv,class_list/o_children_filter.csv,classfilter
36+
CLASS_YEAR_GROUP,class_list/i_year_group.csv,class_list/o_year_group.csv,classyeargrp
37+
CLASS_MAV_854,class_list/i_mav_854.csv,class_list/o_mav_854.csv,classmav854
38+
CLASS_SESSION_ID,class_list/i_session_id.csv,class_list/o_session_id.csv,classsessid
39+
CLASS_SINGLE_VACC,class_list/i_single_vacc.csv,class_list/o_single_vacc.csv,classsinglevacc
40+
CLASS_MAV_965,class_list/i_mav_965.csv,class_list/o_mav_965.csv,classmav965
41+
CLASS_CHANGE_NHSNO,class_list/i_change_nhsno.csv,class_list/o_change_nhsno.csv,classchangenhsno
42+
CLASS_MAV_1080,class_list/i_mav_1080.csv,class_list/o_mav_1080.csv,classmav1080
43+
COHORTS_NO_CONSENT,cohorts/i_no_consent.csv,cohorts/o_no_consent.csv,cohortnoconsent
44+
COHORTS_CONFLICTING_CONSENT,cohorts/i_conflicting_consent.csv,cohorts/o_conflicting_consent.csv,cohortconflict
45+
COHORTS_E2E_1,cohorts/i_e2e_1.csv,cohorts/o_e2e_1.csv,cohort_e2e
46+
COHORTS_UCR_MATCH,cohorts/i_ucr_match.csv,cohorts/o_ucr_match.csv,cohortmatch
47+
COHORTS_CONSENT_TWICE,cohorts/i_consent_twice.csv,cohorts/o_consent_twice.csv,cohorttwice
48+
COHORTS_CONFLICTING_GILLICK,cohorts/i_conflicting_gillick.csv,cohorts/o_conflicting_gillick.csv,cohortgillick
49+
COHORTS_FULL_NAME,cohorts/i_full_name.csv,cohorts/o_full_name.csv,cohortfullname
50+
COHORTS_MAV_927_PERF,cohorts/i_mav_927_perf.csv,cohorts/o_mav_927_perf.csv,cohortmav927perf
51+
COHORTS_MAV_909,cohorts/i_mav_909.csv,cohorts/o_mav_909.csv,cohortmav909
52+
COHORTS_MAV_853,cohorts/i_mav_853.csv,cohorts/o_mav_853.csv,cohortmav853
53+
CLASS_MOVES_CONFIRM_IGNORE,class_list/i_moves_1.csv,class_list/o_moves_1.csv,classmoves1
54+
CLASS_MOVES_UNKNOWN_HOMESCHOOLED,class_list/i_moves_2.csv,class_list/o_moves_2.csv,classmoves2

tests/helpers/parental_consent_helper_doubles.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
class ParentalConsentHelper:
77
def __init__(self):
88
self.df = TestData().read_spreadsheet(
9-
file_path=test_data_file_paths.PARENTAL_CONSENT_DOUBLES
9+
test_data_file_paths.PARENTAL_CONSENT_DOUBLES
1010
)
1111

1212
def read_data_for_scenario(self, scenario_data) -> None:

tests/helpers/parental_consent_helper_hpv.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55

66
class ParentalConsentHelper:
77
def __init__(self):
8-
self.df = TestData().read_spreadsheet(
9-
file_path=test_data_file_paths.PARENTAL_CONSENT_HPV
10-
)
8+
self.df = TestData().read_spreadsheet(test_data_file_paths.PARENTAL_CONSENT_HPV)
119

1210
def read_data_for_scenario(self, scenario_data) -> None:
1311
_, _row = scenario_data

0 commit comments

Comments
 (0)