|
20 | 20 | _tear_down = True |
21 | 21 | verbose = False |
22 | 22 |
|
23 | | -test_user_data_dir = pathlib.Path('./tests/user_data') |
24 | | -test_user_data_dir.mkdir(exist_ok=True) |
| 23 | +pathlib.Path('./tests/user_data').mkdir(exist_ok=True) |
| 24 | +pathlib.Path('./tests/user_data/lab').mkdir(exist_ok=True) |
25 | 25 |
|
26 | 26 | sessions_dirs = ['subject1/session1', |
27 | 27 | 'subject2/session1', |
|
34 | 34 | # -------------------- HELPER CLASS -------------------- |
35 | 35 |
|
36 | 36 |
|
| 37 | +def write_csv(content, path): |
| 38 | + """ |
| 39 | + General function for writing strings to lines in CSV |
| 40 | + :param path: pathlib PosixPath |
| 41 | + :param content: list of strings, each as row of CSV |
| 42 | + """ |
| 43 | + with open(path, 'w') as f: |
| 44 | + for line in content: |
| 45 | + f.write(line+'\n') |
| 46 | + |
| 47 | + |
37 | 48 | class QuietStdOut: |
38 | 49 | """If verbose set to false, used to quiet tear_down table.delete prints""" |
39 | 50 | def __enter__(self): |
@@ -121,6 +132,147 @@ def pipeline(): |
121 | 132 | pipeline.subject.Subject.delete() |
122 | 133 |
|
123 | 134 |
|
| 135 | +@pytest.fixture |
| 136 | +def lab_csv(): |
| 137 | + """ Create a 'labs.csv' file""" |
| 138 | + lab_content = ["lab,lab_name,institution,address," |
| 139 | + + "time_zone,location,location_description", |
| 140 | + "LabA,The Example Lab,Example Uni," |
| 141 | + + "'221B Baker St,London NW1 6XE,UK',UTC+0," |
| 142 | + + "Example Building,'2nd floor lab dedicated to all " |
| 143 | + + "fictional experiments.'", |
| 144 | + "LabB,The Other Lab,Other Uni," |
| 145 | + + "'Oxford OX1 2JD, United Kingdom',UTC+0," |
| 146 | + + "Other Building,'fictional campus dedicated to imaginary" |
| 147 | + + "experiments.'"] |
| 148 | + lab_csv_path = pathlib.Path('./tests/user_data/lab/labs.csv') |
| 149 | + write_csv(lab_content, lab_csv_path) |
| 150 | + |
| 151 | + yield lab_content, lab_csv_path |
| 152 | + lab_csv_path.unlink() |
| 153 | + |
| 154 | + |
| 155 | +@pytest.fixture |
| 156 | +def lab_project_csv(): |
| 157 | + """ Create a 'projects.csv' file""" |
| 158 | + lab_project_content = ["project,project_description,repository_url," |
| 159 | + + "repository_name,codeurl", |
| 160 | + "ProjA,Example project to populate element-lab," |
| 161 | + + "https://github.com/datajoint/element-lab/," |
| 162 | + + "element-lab,https://github.com/datajoint/element" |
| 163 | + + "-lab/tree/main/element_lab", |
| 164 | + "ProjB,Other example project to populate element-" |
| 165 | + + "lab,https://github.com/datajoint/element-session" |
| 166 | + + "/,element-session,https://github.com/datajoint/" |
| 167 | + + "element-session/tree/main/element_session"] |
| 168 | + lab_project_csv_path = pathlib.Path('./tests/user_data/lab/projects.csv') |
| 169 | + write_csv(lab_project_content, lab_project_csv_path) |
| 170 | + |
| 171 | + yield lab_project_content, lab_project_csv_path |
| 172 | + lab_project_csv_path.unlink() |
| 173 | + |
| 174 | + |
| 175 | +@pytest.fixture |
| 176 | +def lab_project_users_csv(): |
| 177 | + """ Create a 'project_users.csv' file""" |
| 178 | + lab_project_user_content = ["user,project", |
| 179 | + "Sherlock,ProjA", |
| 180 | + "Sherlock,ProjB", |
| 181 | + "Watson,ProjB", |
| 182 | + "Dr. Candace Pert,ProjA", |
| 183 | + "User1,ProjA"] |
| 184 | + lab_project_user_csv_path = pathlib.Path('./tests/user_data/lab/\ |
| 185 | + project_users.csv') |
| 186 | + write_csv(lab_project_user_content, lab_project_user_csv_path) |
| 187 | + |
| 188 | + yield lab_project_user_content, lab_project_user_csv_path |
| 189 | + lab_project_user_csv_path.unlink() |
| 190 | + |
| 191 | + |
| 192 | +@pytest.fixture |
| 193 | +def lab_publications_csv(): |
| 194 | + """ Create a 'publications.csv' file""" |
| 195 | + lab_publication_content = ["project,publication", |
| 196 | + "ProjA,arXiv:1807.11104", |
| 197 | + "ProjA,arXiv:1807.11104v1"] |
| 198 | + lab_publication_csv_path = pathlib.Path('./tests/user_data/lab/\ |
| 199 | + publications.csv') |
| 200 | + write_csv(lab_publication_content, lab_publication_csv_path) |
| 201 | + |
| 202 | + yield lab_publication_content, lab_publication_csv_path |
| 203 | + lab_publication_csv_path.unlink() |
| 204 | + |
| 205 | + |
| 206 | +@pytest.fixture |
| 207 | +def lab_keywords_csv(): |
| 208 | + """ Create a 'keywords.csv' file""" |
| 209 | + lab_keyword_content = ["project,keyword", |
| 210 | + "ProjA,Study", |
| 211 | + "ProjA,Example", |
| 212 | + "ProjB,Alternate"] |
| 213 | + lab_keyword_csv_path = pathlib.Path('./tests/user_data/lab/keywords.csv') |
| 214 | + write_csv(lab_keyword_content, lab_keyword_csv_path) |
| 215 | + |
| 216 | + yield lab_keyword_content, lab_keyword_csv_path |
| 217 | + lab_keyword_csv_path.unlink() |
| 218 | + |
| 219 | + |
| 220 | +@pytest.fixture |
| 221 | +def lab_protocol_csv(): |
| 222 | + """ Create a 'protocols.csv' file""" |
| 223 | + lab_protocol_content = ["protocol,protocol_type,protocol_description", |
| 224 | + "ProtA,IRB expedited review,Protocol for managing " |
| 225 | + + "data ingestion", |
| 226 | + "ProtB,Alternative Method,Limited protocol for " |
| 227 | + + "piloting only"] |
| 228 | + lab_protocol_csv_path = pathlib.Path('./tests/user_data/lab/protocols.csv') |
| 229 | + write_csv(lab_protocol_content, lab_protocol_csv_path) |
| 230 | + |
| 231 | + yield lab_protocol_content, lab_protocol_csv_path |
| 232 | + lab_protocol_csv_path.unlink() |
| 233 | + |
| 234 | + |
| 235 | +@pytest.fixture |
| 236 | +def lab_user_csv(): |
| 237 | + """ Create a 'users.csv' file""" |
| 238 | + lab_user_content = ["lab,user,user_role,user_email,user_cellphone", |
| 239 | + "LabA,Sherlock,PI,Sherlock@BakerSt.com," |
| 240 | + + "+44 20 7946 0344", |
| 241 | + "LabA,Watson,Dr,DrWatson@BakerSt.com,+44 73 8389 1763", |
| 242 | + "LabB,Dr. Candace Pert,PI,Pert@gmail.com," |
| 243 | + + "+44 74 4046 5899", |
| 244 | + "LabA,User1,Lab Tech,fake@email.com,+44 1632 960103", |
| 245 | + "LabB,User2,Lab Tech,fake2@email.com,+44 1632 960102"] |
| 246 | + lab_user_csv_path = pathlib.Path('./tests/user_data/lab/users.csv') |
| 247 | + write_csv(lab_user_content, lab_user_csv_path) |
| 248 | + |
| 249 | + yield lab_user_content, lab_user_csv_path |
| 250 | + lab_user_csv_path.unlink() |
| 251 | + |
| 252 | + |
| 253 | +@pytest.fixture |
| 254 | +def ingest_lab(pipeline, lab_csv, lab_project_csv, lab_publications_csv, |
| 255 | + lab_keywords_csv, lab_protocol_csv, lab_user_csv, |
| 256 | + lab_project_users_csv): |
| 257 | + """ From workflow_array_ephys ingest.py, import ingest_lab, run """ |
| 258 | + from workflow_array_ephys.ingest import ingest_lab |
| 259 | + _, lab_csv_path = lab_csv |
| 260 | + _, lab_project_csv_path = lab_project_csv |
| 261 | + _, lab_publication_csv_path = lab_publications_csv |
| 262 | + _, lab_keyword_csv_path = lab_keywords_csv |
| 263 | + _, lab_protocol_csv_path = lab_protocol_csv |
| 264 | + _, lab_user_csv_path = lab_user_csv |
| 265 | + _, lab_project_user_csv_path = lab_project_users_csv |
| 266 | + ingest_lab(lab_csv_path=lab_csv_path, |
| 267 | + project_csv_path=lab_project_csv_path, |
| 268 | + publication_csv_path=lab_publication_csv_path, |
| 269 | + keyword_csv_path=lab_keyword_csv_path, |
| 270 | + protocol_csv_path=lab_protocol_csv_path, |
| 271 | + users_csv_path=lab_user_csv_path, |
| 272 | + project_user_csv_path=lab_project_user_csv_path, verbose=verbose) |
| 273 | + return |
| 274 | + |
| 275 | + |
124 | 276 | @pytest.fixture |
125 | 277 | def subjects_csv(): |
126 | 278 | """ Create a 'subjects.csv' file""" |
@@ -160,11 +312,23 @@ def ingest_subjects(pipeline, subjects_csv): |
160 | 312 | @pytest.fixture |
161 | 313 | def sessions_csv(test_data): |
162 | 314 | """ Create a 'sessions.csv' file""" |
163 | | - input_sessions = pd.DataFrame(columns=['subject', 'session_dir']) |
| 315 | + input_sessions = pd.DataFrame(columns=['subject', 'session_dir', 'session_note', |
| 316 | + 'user']) |
164 | 317 | input_sessions.subject = ['subject1', 'subject2', 'subject2', |
165 | 318 | 'subject3', 'subject4', 'subject5', |
166 | 319 | 'subject6'] |
167 | 320 | input_sessions.session_dir = sessions_dirs |
| 321 | + input_sessions.session_note = ['Data collection notes', |
| 322 | + 'Data collection notes', |
| 323 | + 'Interrupted session', |
| 324 | + 'Data collection notes', |
| 325 | + 'Successful data collection', |
| 326 | + 'Successful data collection', |
| 327 | + 'Ambient temp abnormally low'] |
| 328 | + input_sessions.user = ['User2', 'User2', 'User2', |
| 329 | + 'User1', 'User2', 'User1', |
| 330 | + 'User2'] |
| 331 | + |
168 | 332 | input_sessions = input_sessions.set_index('subject') |
169 | 333 |
|
170 | 334 | sessions_csv_path = pathlib.Path('./tests/user_data/sessions.csv') |
@@ -211,7 +375,7 @@ def ephys_insertionlocation(pipeline, ingest_sessions): |
211 | 375 | depth=0, |
212 | 376 | theta=0, |
213 | 377 | phi=0, |
214 | | - beta=0)) |
| 378 | + beta=0), skip_duplicates=True) |
215 | 379 | yield |
216 | 380 |
|
217 | 381 | if _tear_down: |
|
0 commit comments