From bd516e958af22e57c18cacf0cb22552c2a237bd8 Mon Sep 17 00:00:00 2001 From: Josh Cook <39419448+jhrcook@users.noreply.github.com> Date: Tue, 23 Nov 2021 10:28:49 -0500 Subject: [PATCH] fix: R encoding of pathlib.Path objects (#1201) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: support converting Path objects for R * test: test for converting Path objects to R * Update script.py * test: Snakemake test for R encoding pathlib.Path objects (missing files) * fix: touch file to make expected-results dir appear in git Co-authored-by: Johannes Köster --- .../Snakefile | 18 ++++++++++++++++++ .../expected-results/.github_touch | 0 .../r-script.R | 9 +++++++++ .../text-file.txt | 0 tests/tests.py | 4 ++++ 5 files changed, 31 insertions(+) create mode 100644 tests/test_converting_path_for_r_script/Snakefile create mode 100644 tests/test_converting_path_for_r_script/expected-results/.github_touch create mode 100644 tests/test_converting_path_for_r_script/r-script.R create mode 100644 tests/test_converting_path_for_r_script/text-file.txt diff --git a/tests/test_converting_path_for_r_script/Snakefile b/tests/test_converting_path_for_r_script/Snakefile new file mode 100644 index 000000000..c19e776e7 --- /dev/null +++ b/tests/test_converting_path_for_r_script/Snakefile @@ -0,0 +1,18 @@ + +from pathlib import Path + + +rule all: + input: + out_file="out-file.txt" + + +rule step1: + input: + text_file=Path("text-file.txt") + params: + param_dir=Path("dir") + output: + out_file=Path("out-file.txt") + script: + "r-script.R" diff --git a/tests/test_converting_path_for_r_script/expected-results/.github_touch b/tests/test_converting_path_for_r_script/expected-results/.github_touch new file mode 100644 index 000000000..e69de29bb diff --git a/tests/test_converting_path_for_r_script/r-script.R b/tests/test_converting_path_for_r_script/r-script.R new file mode 100644 index 000000000..23ae87960 --- /dev/null +++ b/tests/test_converting_path_for_r_script/r-script.R @@ -0,0 +1,9 @@ + +infile <- snakemake@input[["text_file"]] + +# Check the read value is as expected in R. +param_dir <- snakemake@params[["param_dir"]] +stopifnot(param_dir == "dir") + +outfile <- snakemake@output[["out_file"]] +file.create(outfile) diff --git a/tests/test_converting_path_for_r_script/text-file.txt b/tests/test_converting_path_for_r_script/text-file.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tests/tests.py b/tests/tests.py index 0fbea1540..a86f06ce6 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -1340,5 +1340,9 @@ def test_github_issue1158(): ) +def test_converting_path_for_r_script(): + run(dpath("test_converting_path_for_r_script"), cores=1) + + def test_ancient_dag(): run(dpath("test_ancient_dag"))