Skip to content

Commit

Permalink
fix: SameFileError #1153 (#1220)
Browse files Browse the repository at this point in the history
* Fixes #1153. Path.parent replaces target path when full paths are provided, matching file and target locations.

* Turn absolute path into relative one instead of avoiding file path altogether.

Co-authored-by: Benjamin Essigman <essigman@scailyte.com>
Co-authored-by: Johannes Köster <johannes.koester@uni-due.de>
Co-authored-by: Johannes Köster <johannes.koester@tu-dortmund.de>
  • Loading branch information
4 people committed Nov 27, 2021
1 parent 426d92f commit ede313d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
7 changes: 6 additions & 1 deletion snakemake/unit_tests/__init__.py
Expand Up @@ -75,7 +75,12 @@ def generate(dag, path, deploy=["conda", "singularity"], configfiles=None):
def copy_files(files, content_type):
for f in files:
f = Path(f)
target = path / rulename / content_type / f.parent
parent = f.parent
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)
Expand Down
4 changes: 4 additions & 0 deletions tests/test_generate_unit_tests/Snakefile
@@ -1,8 +1,12 @@
import os

rule all:
input:
expand("test/{sample}.tsv", sample=range(3))

rule a:
input:
os.environ["UNIT_TEST_TMPFILE"]
output:
temp("test/{sample}.txt")
shell:
Expand Down
16 changes: 9 additions & 7 deletions tests/tests.py
Expand Up @@ -1192,13 +1192,15 @@ def test_github_issue640():

@skip_on_windows # TODO check whether this might be enabled later
def test_generate_unit_tests():
tmpdir = run(
dpath("test_generate_unit_tests"),
generate_unit_tests=".tests/unit",
check_md5=False,
cleanup=False,
)
sp.check_call(["pytest", ".tests", "-vs"], cwd=tmpdir)
with tempfile.NamedTemporaryFile() as tmpfile:
os.environ["UNIT_TEST_TMPFILE"] = tmpfile.name
tmpdir = run(
dpath("test_generate_unit_tests"),
generate_unit_tests=".tests/unit",
check_md5=False,
cleanup=False,
)
sp.check_call(["pytest", ".tests", "-vs"], cwd=tmpdir)


@skip_on_windows
Expand Down

0 comments on commit ede313d

Please sign in to comment.