-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add cli for rs2redcap (need test data)
- Loading branch information
Showing
3 changed files
with
49 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import os | ||
import pytest | ||
from click.testing import CliRunner | ||
from ..cli import main | ||
from shutil import copytree | ||
from pathlib import Path | ||
import csv | ||
|
||
def test_reproschema2redcap_success(): | ||
runner = CliRunner() | ||
|
||
with runner.isolated_filesystem(): | ||
# Copy necessary test data into the isolated filesystem | ||
original_data_dir = os.path.join(os.path.dirname(__file__), "test_rs2redcap_data") | ||
copytree(original_data_dir, "input_data") | ||
|
||
input_path = Path("input_data") # Using Path object | ||
output_csv_path = "output.csv" | ||
|
||
# Invoke the reproschema2redcap command | ||
result = runner.invoke(main, ['reproschema2redcap', str(input_path), output_csv_path]) | ||
|
||
# Print the output for debugging | ||
print(result.output) | ||
|
||
# Assert the expected outcomes | ||
assert result.exit_code == 0 | ||
assert f"Converted reproschema JSON from {input_path} to Redcap CSV at {output_csv_path}" in result.output | ||
|
||
# Check if the output CSV file has been created | ||
assert os.path.exists(output_csv_path) | ||
|
||
# Read and print the contents of the CSV file | ||
with open(output_csv_path, 'r', encoding='utf-8') as csv_file: | ||
reader = csv.reader(csv_file) | ||
csv_contents = list(reader) | ||
print("CSV File Contents:") | ||
for row in csv_contents: | ||
print(row) | ||
|
||
# Optionally, assert conditions about the CSV contents | ||
# For example, assert that the file is not empty | ||
assert len(csv_contents) > 0 |