Skip to content
Permalink
Browse files
fix: fix issue when generating unit tests for rules with directory ou…
…tput (#1385)

* fix: fix issue when generating unit tests for rules with directory output

* fix
  • Loading branch information
johanneskoester committed Feb 9, 2022
1 parent cccffc4 commit 7db614fa1753179d2cdc20095df17d5ac2885ad0
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 4 deletions.
@@ -54,6 +54,15 @@ def generate(dag, path, deploy=["conda", "singularity"], configfiles=None):
)

for rulename, jobs in groupby(dag.jobs, key=lambda job: job.rule.name):
jobs = list(jobs)
if jobs[0].rule.norun:
logger.info(
"Skipping rule {} because it does not execute anything.".format(
rulename
)
)
continue

testpath = path / "test_{}.py".format(rulename)

if testpath.exists():
@@ -79,12 +88,11 @@ def copy_files(files, content_type):
if parent.is_absolute():
root = str(f.parents[len(f.parents) - 1])
parent = str(parent)[len(root) :]
print(parent)
target = path / rulename / content_type / parent
os.makedirs(target, exist_ok=True)
if f.is_dir():
shutil.copytree(f, target)
shutil.copytree(f, target / f.name)
else:
os.makedirs(target, exist_ok=True)
shutil.copy(f, target)
if not files:
os.makedirs(path / rulename / content_type, exist_ok=True)
@@ -30,7 +30,7 @@ def test_{{ ruletest.name }}():
"-m",
"snakemake",
"{{ ruletest.target }}",
"-F",
"-f",
"-j1",
"--keep-target-files",
{% if configfiles %}
@@ -0,0 +1,20 @@
rule all:
input:
"results/checksum.txt"

rule foo:
output:
directory("results/dir")
shell:
"""
mkdir results/dir
echo hi >> results/dir/something
"""

rule bar:
input:
rules.foo.output
output:
"results/checksum.txt"
shell:
"ls {input}/* >> {output}"
Empty file.
@@ -1412,3 +1412,18 @@ def test_default_target():

def test_cache_multioutput():
run(dpath("test_cache_multioutput"), shouldfail=True)


@skip_on_windows
def test_github_issue1384():
try:
tmpdir = run(dpath("test_github_issue1384"), cleanup=False)
shell(
"""
cd {tmpdir}
python -m snakemake --generate-unit-tests
pytest -v .tests/unit
"""
)
finally:
shutil.rmtree(tmpdir)

0 comments on commit 7db614f

Please sign in to comment.