1
1
import csv
2
2
from datetime import datetime
3
+ from time import sleep
3
4
from unittest import TestCase , main
4
5
5
6
from trd_cli .conversions import convert_generic , extract_participant_info , QUESTIONNAIRES
@@ -13,7 +14,7 @@ def test_convert_generic(self):
13
14
expectations = {
14
15
"phq9" : {
15
16
"phq9_response_id" : "1589930675" ,
16
- "phq9_datetime" : "2024-11-04 12 :59:24.9477348+00:00" ,
17
+ "phq9_datetime" : "2024-11-04T12 :59:24.9477348+00:00" ,
17
18
"phq9_1_interest_float" : "3.0" ,
18
19
"phq9_2_depression_float" : "3.0" ,
19
20
"phq9_3_sleep_float" : "3.0" ,
@@ -35,7 +36,7 @@ def test_convert_generic(self):
35
36
"gad7_6_irritable_float" : "2.0" ,
36
37
"gad7_7_afraid_float" : "3.0" ,
37
38
"gad7_8_difficult_float" : "0.0" ,
38
- "gad7_datetime" : "2024-11-05 12 :05:43.5629631+00:00" ,
39
+ "gad7_datetime" : "2024-11-05T12 :05:43.5629631+00:00" ,
39
40
"gad7_score_total_float" : "12.0" ,
40
41
},
41
42
"mania" : {
@@ -45,12 +46,12 @@ def test_convert_generic(self):
45
46
"mania_3_sleep_float" : "1.0" ,
46
47
"mania_4_talking_float" : "1.0" ,
47
48
"mania_5_activity_float" : "2.0" ,
48
- "mania_datetime" : "2024-11-05 12 :05:59.3055890+00:00" ,
49
+ "mania_datetime" : "2024-11-05T12 :05:59.3055890+00:00" ,
49
50
"mania_score_total_float" : "6.0" ,
50
51
},
51
52
"reqol10" : {
52
53
"reqol10_response_id" : "1504524233" ,
53
- "reqol10_datetime" : "2024-11-05 12 :07:38.7956557+00:00" ,
54
+ "reqol10_datetime" : "2024-11-05T12 :07:38.7956557+00:00" ,
54
55
"reqol10_1_everyday_tasks_float" : "3.0" ,
55
56
"reqol10_2_trust_others_float" : "2.0" ,
56
57
"reqol10_3_unable_to_cope_float" : "1.0" ,
@@ -66,7 +67,7 @@ def test_convert_generic(self):
66
67
},
67
68
"wsas" : {
68
69
"wsas_response_id" : "1212115884" ,
69
- "wsas_datetime" : "2024-11-05 12 :08:48.0135908+00:00" ,
70
+ "wsas_datetime" : "2024-11-05T12 :08:48.0135908+00:00" ,
70
71
"wsas_1_work_float" : "3.0" ,
71
72
"wsas_2_management_float" : "5.0" ,
72
73
"wsas_3_social_leisure_float" : "3.0" ,
@@ -84,6 +85,11 @@ def test_convert_generic(self):
84
85
if q_code is not None and q_code not in done :
85
86
with self .subTest (q_name = q_code ):
86
87
done .append (q_code )
88
+ if q_code not in expectations .keys ():
89
+ if q_code == "consent" :
90
+ continue
91
+ else :
92
+ self .fail (f"Unhandled questionnaire response of type { q_code } ." )
87
93
result = convert_generic (r )
88
94
self .assertEqual (expectations [q_code ], result )
89
95
@@ -98,6 +104,7 @@ def test_extract_info(self):
98
104
responses = csv .DictReader (f , delimiter = "|" )
99
105
response = next (responses )
100
106
private , public = extract_participant_info (response )
107
+ sleep (0.1 )
101
108
self .assertGreater (datetime .now ().isoformat (), private ["datetime" ])
102
109
self .assertGreater (datetime .now ().isoformat (), public ["info_datetime" ])
103
110
private ["datetime" ] = None
0 commit comments