Skip to content

Commit d10601a

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 6bd6094 commit d10601a

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

reproschema/redcap2reproschema.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ def process_choices(choices_str, field_name):
201201
choices = []
202202
choices_value_type = []
203203
for ii, choice in enumerate(choices_str.split("|")):
204-
choice = choice.strip() # Strip leading/trailing whitespace for each choice
204+
choice = (
205+
choice.strip()
206+
) # Strip leading/trailing whitespace for each choice
205207
parts = [p.strip() for p in choice.split(",")]
206208

207209
# Handle the case where the choice is something like "1,"
@@ -215,11 +217,11 @@ def process_choices(choices_str, field_name):
215217
parts = [ii, parts[0]]
216218

217219
# Determine if value should be treated as an integer or string
218-
if parts[0] == '0':
220+
if parts[0] == "0":
219221
# Special case for "0", treat it as an integer
220222
value = 0
221223
choices_value_type.append("xsd:integer")
222-
elif parts[0].isdigit() and parts[0][0] == '0':
224+
elif parts[0].isdigit() and parts[0][0] == "0":
223225
# If it has leading zeros, treat it as a string
224226
value = parts[0]
225227
choices_value_type.append("xsd:string")

reproschema/tests/test_process_choices.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from ..cli import main
99
from ..redcap2reproschema import process_choices
1010

11+
1112
def test_process_choices_numeric_codes():
1213
# Test standard numeric codes with descriptions
1314
choices_str = "1, Male | 2, Female | 3, Other"
@@ -19,6 +20,7 @@ def test_process_choices_numeric_codes():
1920
]
2021
assert value_types == ["xsd:integer"]
2122

23+
2224
def test_process_choices_boolean():
2325
# Test boolean choices (Yes/No)
2426
choices_str = "1, Yes | 0, No"
@@ -29,17 +31,19 @@ def test_process_choices_boolean():
2931
]
3032
assert value_types == ["xsd:integer"]
3133

34+
3235
def test_process_choices_special_characters():
3336
# Test choices with special characters
3437
choices_str = "1, Option A | 2, \"Option B\" | 3, Option C with 'quotes'"
3538
choices, value_types = process_choices(choices_str, "special_chars")
3639
assert choices == [
3740
{"name": {"en": "Option A"}, "value": 1},
38-
{"name": {"en": "\"Option B\""}, "value": 2},
41+
{"name": {"en": '"Option B"'}, "value": 2},
3942
{"name": {"en": "Option C with 'quotes'"}, "value": 3},
4043
]
4144
assert value_types == ["xsd:integer"]
4245

46+
4347
def test_process_choices_with_missing_values():
4448
# Test choices with a missing value (commonly used for "Not applicable" or "Prefer not to say")
4549
choices_str = "1, Yes | 2, No | 99, Not applicable"
@@ -51,6 +55,7 @@ def test_process_choices_with_missing_values():
5155
]
5256
assert value_types == ["xsd:integer"]
5357

58+
5459
def test_process_choices_with_unicode():
5560
# Test choices with Unicode characters (e.g., accents, symbols)
5661
choices_str = "1, Café | 2, Niño | 3, Résumé | 4, ☺"
@@ -63,6 +68,7 @@ def test_process_choices_with_unicode():
6368
]
6469
assert value_types == ["xsd:integer"]
6570

71+
6672
def test_process_choices_alpha_codes():
6773
# Test alpha codes (e.g., categorical text codes)
6874
choices_str = "A, Apple | B, Banana | C, Cherry"
@@ -74,6 +80,7 @@ def test_process_choices_alpha_codes():
7480
]
7581
assert sorted(value_types) == ["xsd:string"]
7682

83+
7784
def test_process_choices_incomplete_values():
7885
# Test choices with missing descriptions
7986
choices_str = "1, Yes | 2, | 3, No"
@@ -85,6 +92,7 @@ def test_process_choices_incomplete_values():
8592
]
8693
assert value_types == ["xsd:integer"]
8794

95+
8896
def test_process_choices_numeric_strings():
8997
# Test numeric strings as values (e.g., not converted to integers)
9098
choices_str = "001, Option 001 | 002, Option 002 | 003, Option 003"
@@ -96,6 +104,7 @@ def test_process_choices_numeric_strings():
96104
]
97105
assert sorted(value_types) == ["xsd:string"]
98106

107+
99108
def test_process_choices_spaces_in_values():
100109
# Test choices with spaces in values and names
101110
choices_str = "A B, Choice AB | C D, Choice CD"
@@ -106,6 +115,7 @@ def test_process_choices_spaces_in_values():
106115
]
107116
assert sorted(value_types) == ["xsd:string"]
108117

118+
109119
# Run pytest if script is called directly
110120
if __name__ == "__main__":
111121
pytest.main()

0 commit comments

Comments
 (0)