Skip to content

Commit 51d30b7

Browse files
committed
final improvments on tests
1 parent e1e847d commit 51d30b7

File tree

4 files changed

+7
-26
lines changed

4 files changed

+7
-26
lines changed

reproschema/redcap2reproschema.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def clean_header(header):
1616
cleaned_header[cleaned_key] = v
1717
return cleaned_header
1818

19+
1920
def normalize_condition(condition_str):
2021
# Regular expressions for various pattern replacements
2122
re_parentheses = re.compile(r"\(([0-9]*)\)")
@@ -42,6 +43,7 @@ def normalize_condition(condition_str):
4243

4344
return condition_str.strip()
4445

46+
4547
def process_visibility(data):
4648
condition = data.get("Branching Logic (Show field only if...)")
4749
if condition:
@@ -94,7 +96,6 @@ def parse_field_type_and_value(field, input_type_map):
9496
return input_type, value_type
9597

9698

97-
9899
def process_choices(field_type, choices_str):
99100
if field_type not in ["radio", "dropdown"]: # Handle only radio and dropdown types
100101
return None

reproschema/reproschema2redcap.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ def get_csv_data(dir_path):
164164
if item_json:
165165
row_data = process_item(item_json, activity_path.stem)
166166
csv_data.append(row_data)
167-
print(f"Processed item {item_path}")
168167

169168
# Break after finding the first _schema file
170169
break

reproschema/tests/test_redcap2reproschema.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@
1414
os.path.dirname(__file__), "test_redcap2rs_data", YAML_FILE_NAME
1515
)
1616

17-
def test_redcap2reproschema_success(tmpdir):
17+
def test_redcap2reproschema(tmpdir):
1818
runner = CliRunner()
1919

20-
# Define the paths to the CSV and YAML files in the temporary directory
2120
temp_csv_file = tmpdir.join(CSV_FILE_NAME)
2221
temp_yaml_file = tmpdir.join(YAML_FILE_NAME)
2322

24-
# Copy the test files to the temporary directory
2523
shutil.copy(CSV_TEST_FILE, str(temp_csv_file)) # Convert to string
2624
shutil.copy(YAML_TEST_FILE, str(temp_yaml_file)) # Convert to string
2725

@@ -32,12 +30,9 @@ def test_redcap2reproschema_success(tmpdir):
3230
protocol = yaml.safe_load(file)
3331
protocol_name = protocol.get("protocol_name", "").replace(" ", "_")
3432

35-
# Run the command with the path arguments pointing to the temp directory files
3633
result = runner.invoke(
3734
main, ["redcap2reproschema", str(temp_csv_file), str(temp_yaml_file)] # Convert to string
3835
)
3936

40-
# Assertions
4137
assert result.exit_code == 0, f"The command failed to execute successfully: {result.output}"
4238
assert os.path.isdir(protocol_name), f"Expected output directory '{protocol_name}' does not exist"
43-
print("Command output:", result.output)

reproschema/tests/test_reproschema2redcap.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,35 @@
55
from shutil import copytree, rmtree
66
from pathlib import Path
77
import csv
8-
import tempfile
98

10-
def test_reproschema2redcap_success():
9+
def test_reproschema2redcap(tmpdir):
1110
runner = CliRunner()
1211

1312
with runner.isolated_filesystem():
14-
# Create a temporary directory for output
15-
temp_dir = tempfile.mkdtemp(dir='.')
16-
print(f"Temporary directory: {temp_dir}")
1713
# Copy necessary test data into the isolated filesystem
1814
original_data_dir = os.path.join(
1915
os.path.dirname(__file__), "test_rs2redcap_data", "test_redcap2rs"
2016
)
2117
copytree(original_data_dir, "input_data")
2218

23-
input_path = Path("input_data") # Using Path object
24-
output_csv_path = os.path.join(temp_dir, "output.csv")
19+
input_path = Path("input_data")
20+
output_csv_path = os.path.join(tmpdir, "output.csv")
2521

26-
# Invoke the reproschema2redcap command
2722
result = runner.invoke(
2823
main, ["reproschema2redcap", str(input_path), output_csv_path]
2924
)
3025

31-
# Print the output for debugging
3226
print(result.output)
3327

34-
# Assert the expected outcomes
3528
assert result.exit_code == 0
3629

37-
# Check if the output CSV file has been created
3830
assert os.path.exists(output_csv_path)
3931

40-
# Read and print the contents of the CSV file
4132
with open(output_csv_path, "r", encoding="utf-8") as csv_file:
4233
reader = csv.reader(csv_file)
4334
csv_contents = list(reader)
44-
print("CSV File Contents:")
45-
for row in csv_contents:
46-
print(row)
4735

48-
# Optionally, assert conditions about the CSV contents
49-
# For example, assert that the file has more than just headers
5036
assert len(csv_contents) > 1 # More than one row indicates content beyond headers
5137

5238
# Clean up temporary directory after use (optional)
53-
# rmtree(temp_dir)
39+
# rmtree(tmpdir)

0 commit comments

Comments
 (0)