Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 28, 2023
1 parent 3e72f25 commit 587b388
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
12 changes: 8 additions & 4 deletions reproschema/redcap2reproschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,15 +475,18 @@ def redcap2reproschema(
protocol_visibility_obj,
)


def main():
parser = argparse.ArgumentParser(description="Convert REDCap data dictionary to Reproschema format.")
parser = argparse.ArgumentParser(
description="Convert REDCap data dictionary to Reproschema format."
)
parser.add_argument("csv_file", help="Path to the REDCap data dictionary CSV file.")
parser.add_argument("yaml_file", help="Path to the Reproschema protocol YAML file.")
args = parser.parse_args()

# Read the YAML configuration
with open(args.yaml_file, "r") as f:
protocol = yaml.safe_load(f)
protocol = yaml.safe_load(f)

protocol_name = protocol.get("protocol_name")
protocol_display_name = protocol.get("protocol_display_name")
Expand All @@ -492,7 +495,7 @@ def main():
if not protocol_name:
raise ValueError("Protocol name not specified in the YAML file.")

protocol_name = protocol_name.replace(' ', '_') # Replacing spaces with underscores
protocol_name = protocol_name.replace(" ", "_") # Replacing spaces with underscores

# Check if the directory already exists
if not os.path.exists(protocol_name):
Expand All @@ -510,5 +513,6 @@ def main():
protocol_description,
)


if __name__ == "__main__":
main()
main()
15 changes: 7 additions & 8 deletions reproschema/tests/test_redcap2reproschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@
# Assuming your test files are located in a 'tests' directory
CSV_FILE_NAME = "redcap_dict.csv"
YAML_FILE_NAME = "redcap2rs.yaml"
CSV_TEST_FILE = os.path.join(
os.path.dirname(__file__), "test_data", CSV_FILE_NAME
)
YAML_TEST_FILE = os.path.join(
os.path.dirname(__file__), "test_data", YAML_FILE_NAME
)
CSV_TEST_FILE = os.path.join(os.path.dirname(__file__), "test_data", CSV_FILE_NAME)
YAML_TEST_FILE = os.path.join(os.path.dirname(__file__), "test_data", YAML_FILE_NAME)


def test_redcap2reproschema_success():
runner = CliRunner()
Expand All @@ -23,6 +20,8 @@ def test_redcap2reproschema_success():
shutil.copy(YAML_TEST_FILE, YAML_FILE_NAME)

# Run the command within the isolated filesystem
result = runner.invoke(main, ['redcap2reproschema', CSV_FILE_NAME, YAML_FILE_NAME])
result = runner.invoke(
main, ["redcap2reproschema", CSV_FILE_NAME, YAML_FILE_NAME]
)
print(result.output)
assert result.exit_code == 0
assert result.exit_code == 0
2 changes: 1 addition & 1 deletion templates/redcap2rs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ protocol_display_name: "Your protocol display name"

# Protocol Description:
# Provide a brief description of your protocol.
protocol_description: "Description for your protocol" # Example: "This protocol is for ..."
protocol_description: "Description for your protocol" # Example: "This protocol is for ..."

0 comments on commit 587b388

Please sign in to comment.