-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_bpc_redcap_export_mapping.py
115 lines (103 loc) · 3.36 KB
/
test_bpc_redcap_export_mapping.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import pytest
from unittest import mock
import pandas as pd
import synapseclient
from geniesp import bpc_redcap_export_mapping as bpc_export
@pytest.fixture
def mock_syn():
yield mock.Mock(spec=synapseclient.Synapse)
def test_that_get_drug_variable_names_gets_expected_list():
var_names = bpc_export.get_drug_variable_names()
assert var_names == [
"drugs_drug_1",
"drugs_drug_oth1",
"drugs_drug_2",
"drugs_drug_oth2",
"drugs_drug_3",
"drugs_drug_oth3",
"drugs_drug_4",
"drugs_drug_oth4",
"drugs_drug_5",
"drugs_drug_oth5",
]
def test_get_mapping_data_calls_grs_if_use_grs_is_true(mock_syn):
with mock.patch.object(mock_syn, "get") as mock_get, mock.patch.object(
pd, "read_csv"
):
bpc_export.get_mapping_data(
syn=mock_syn, synid_file_grs="synGRS", synid_file_dd="synDD", use_grs=True
)
mock_get.assert_called_with("synGRS")
def test_get_mapping_data_calls_dd_if_use_grs_is_false(mock_syn):
with mock.patch.object(mock_syn, "get") as mock_get, mock.patch.object(
pd, "read_csv"
):
bpc_export.get_mapping_data(
syn=mock_syn, synid_file_grs="synGRS", synid_file_dd="synDD", use_grs=False
)
mock_get.assert_called_with("synDD")
@pytest.mark.parametrize(
"input_mapping, var_names, output_mapping",
[
(
pd.DataFrame(
{
"Variable / Field Name": ["drugs_drug_1", "drugs_drug_2"],
"Choices, Calculations, OR Slider Labels": [
"D001, Aspirin | D002, Ibuprofen | D003, Paracetamol",
"D004, Tylenol |",
],
}
),
["drugs_drug_1", "drugs_drug_2"],
{
"Aspirin": "D001",
"Ibuprofen": "D002",
"Paracetamol": "D003",
"Tylenol": "D004",
},
),
(
pd.DataFrame(
{
"Variable / Field Name": ["drugs_drug_1"],
"Choices, Calculations, OR Slider Labels": ["D001, Aspirin|"],
}
),
["drugs_drug_1"],
{"Aspirin": "D001"},
),
(
pd.DataFrame(
{
"Variable / Field Name": ["ethnicity"],
"Choices, Calculations, OR Slider Labels": ["1"],
}
),
["drugs_drug_1"],
{},
),
(
pd.DataFrame(
{
"Variable / Field Name": ["drugs_drug_1"],
"Choices, Calculations, OR Slider Labels": [
"D001, Aspirin (alternative) | D002, Ibuprofen | D003, Paracetamol"
],
"extra_column" : ["test1"]
}
),
["drugs_drug_1"],
{"Aspirin": "D001", "Ibuprofen": "D002", "Paracetamol": "D003"},
),
],
ids=[
"multiple_drug_vars",
"empty_split",
"nothing_to_parse",
"parenthesis_split",
],
)
def test_that_parse_drug_mappings(input_mapping, var_names, output_mapping):
result = bpc_export.parse_drug_mappings(mapping=input_mapping, var_names=var_names)
assert result == output_mapping