From: Michael R. Crusoe <crusoe@debian.org>
Subject: make test temporary directories not in the "test" folder
Forwarded: https://github.com/daler/pybedtools/pull/419

This prevented the execution of the tests post-installation
--- python-pybedtools.orig/pybedtools/test/test_1.py
+++ python-pybedtools/pybedtools/test/test_1.py
@@ -1,24 +1,19 @@
 import pybedtools
 import os, difflib, sys
-from pybedtools import featurefuncs
+import tempfile
+import shutil
+from pathlib import Path
+
+from pybedtools import featurefuncs, filenames
 import pytest
 
 import threading
 import warnings
-from .tfuncs import test_tempdir
 
 unwriteable = "unwriteable"
 
 
-def setup_module():
-    if not os.path.exists(test_tempdir):
-        os.system("mkdir -p %s" % test_tempdir)
-    pybedtools.set_tempdir(test_tempdir)
-
-
 def teardown_module():
-    if os.path.exists(test_tempdir):
-        os.system("rm -r %s" % test_tempdir)
     pybedtools.cleanup()
 
 
@@ -67,7 +62,8 @@
     """
     if os.path.exists(unwriteable):
         os.system("rm -rf %s" % unwriteable)
-    pybedtools.set_tempdir(test_tempdir)
+    tempfile.tempdir = None
+    pybedtools.set_tempdir(tempfile.gettempdir())
 
 
 def test_interval_index():
@@ -132,37 +128,24 @@
     assert x[0]["ID"] == "gene1"
 
 
-def test_tabix():
-    try:
-        a = pybedtools.example_bedtool("a.bed")
-        t = a.tabix(force=True)
-        assert t._tabixed()
-        results = t.tabix_intervals("chr1:99-200")
-        results = str(results)
-        print(results)
-        assert results == fix(
-            """
-        chr1	1	100	feature1	0	+
-        chr1	100	200	feature2	0	+
-        chr1	150	500	feature3	0	-"""
-        )
-
-        assert str(t.tabix_intervals(a[2])) == fix(
-            """
-        chr1	100	200	feature2	0	+
-        chr1	150	500	feature3	0	-"""
-        )
-
-    finally:
-        # clean up
-        fns = [
-            pybedtools.example_filename("a.bed.gz"),
-            pybedtools.example_filename("a.bed.gz.tbi"),
-        ]
-        for fn in fns:
-            if os.path.exists(fn):
-                os.unlink(fn)
+def test_tabix(tmp_path: Path) -> None:
+    shutil.copy(os.path.join(filenames.data_dir(), "a.bed"), tmp_path)
+    a = pybedtools.BedTool(tmp_path / "a.bed")
+    t = a.tabix(force=True)
+    assert t._tabixed()
+    results = t.tabix_intervals("chr1:99-200")
+    results = str(results)
+    print(results)
+    assert results == fix("""
+    chr1	1	100	feature1	0	+
+    chr1	100	200	feature2	0	+
+    chr1	150	500	feature3	0	-"""
+    )
 
+    assert str(t.tabix_intervals(a[2])) == fix("""
+    chr1	100	200	feature2	0	+
+    chr1	150	500	feature3	0	-"""
+    )
 
 def test_tabix_intervals():
     a = pybedtools.BedTool("chr1 25 30", from_string=True).tabix()
@@ -503,6 +486,7 @@
     For example, the first 100 bases of a chromosome are defined as
     chromStart=0, chromEnd=100, and span the bases numbered 0-99. """
 
+    test_tempdir = os.path.abspath(tempfile.gettempdir())
     fi = os.path.join(test_tempdir, "test.fasta")
 
     s = """
--- python-pybedtools.orig/pybedtools/test/test_cbedtools.py
+++ python-pybedtools/pybedtools/test/test_cbedtools.py
@@ -5,17 +5,8 @@
 from pybedtools import Interval, IntervalFile
 import pybedtools
 import pytest
-from .tfuncs import test_tempdir
-
-def setup_module():
-    if not os.path.exists(test_tempdir):
-        os.system("mkdir -p %s" % test_tempdir)
-    pybedtools.set_tempdir(test_tempdir)
-
 
 def teardown_module():
-    if os.path.exists(test_tempdir):
-        os.system("rm -r %s" % test_tempdir)
     pybedtools.cleanup()
 
 PATH = os.path.dirname(__file__)
--- python-pybedtools.orig/pybedtools/test/test_contrib.py
+++ python-pybedtools/pybedtools/test/test_contrib.py
@@ -7,7 +7,7 @@
 from pybedtools import Interval
 
 # from pybedtools.contrib import Classifier
-from .tfuncs import setup_module, teardown_module, testdir, test_tempdir, unwriteable
+from .tfuncs import teardown_module
 
 # model for gdc.
 # chr2L, starts at 1 and spacing is 10bp.
--- python-pybedtools.orig/pybedtools/test/test_gzip_support.py
+++ python-pybedtools/pybedtools/test/test_gzip_support.py
@@ -4,17 +4,9 @@
 
 import pybedtools
 import gzip
-from .tfuncs import test_tempdir
 
 
-def setup_module():
-    if not os.path.exists(test_tempdir):
-        os.system("mkdir -p %s" % test_tempdir)
-    pybedtools.set_tempdir(test_tempdir)
-
 def teardown_module():
-    if os.path.exists(test_tempdir):
-        os.system("rm -r %s" % test_tempdir)
     pybedtools.cleanup()
 
 def _make_temporary_gzip(bed_filename):
--- python-pybedtools.orig/pybedtools/test/test_helpers.py
+++ python-pybedtools/pybedtools/test/test_helpers.py
@@ -1,7 +1,8 @@
 import pybedtools
 import sys
 import os
-from .tfuncs import testdir, test_tempdir
+import tempfile
+from .tfuncs import testdir
 import pytest
 from pathlib import Path
 
@@ -41,6 +42,7 @@
 
     # make a fake tempfile, not created during this pybedtools session
     pybedtools.cleanup()
+    test_tempdir = os.path.abspath(tempfile.gettempdir())
     testfn = Path(test_tempdir) / "pybedtools.TESTING.tmp"
     testfn.parent.mkdir(parents=True, exist_ok=True)
     testfn.touch()
--- python-pybedtools.orig/pybedtools/test/test_issues.py
+++ python-pybedtools/pybedtools/test/test_issues.py
@@ -1,6 +1,7 @@
 import pybedtools
 import gzip
 import os
+import shutil
 import subprocess
 import sys
 from textwrap import dedent
@@ -8,21 +9,13 @@
 import pytest
 import psutil
 
+from pybedtools import filenames
 
 testdir = os.path.dirname(__file__)
-tempdir = os.path.join(os.path.abspath(testdir), "tmp")
 unwriteable = "unwriteable"
 
 
-def setup_module():
-    if not os.path.exists(tempdir):
-        os.system("mkdir -p %s" % tempdir)
-    pybedtools.set_tempdir(tempdir)
-
-
 def teardown_module():
-    if os.path.exists(tempdir):
-        os.system("rm -r %s" % tempdir)
     pybedtools.cleanup()
 
 
@@ -415,17 +408,19 @@
     assert str(y) == expected
 
 
-def test_issue_168():
+def test_issue_168(tmp_path: Path) -> None:
     # Regression test:
     # this would previously segfault in at least pysam 0.8.4
     #
-    x = pybedtools.example_bedtool("1000genomes-example.vcf")
+    shutil.copy(os.path.join(filenames.data_dir(), "1000genomes-example.vcf"), tmp_path)
+    x = pybedtools.BedTool(tmp_path / "1000genomes-example.vcf")
     fn = x.bgzip(is_sorted=True, force=True)
     y = pybedtools.BedTool(fn)
 
 
-def test_issue_169():
-    x = pybedtools.example_bedtool("1000genomes-example.vcf")
+def test_issue_169(tmp_path: Path) -> None:
+    shutil.copy(os.path.join(filenames.data_dir(), "1000genomes-example.vcf"), tmp_path)
+    x = pybedtools.BedTool(tmp_path / "1000genomes-example.vcf")
     fn = x.bgzip(is_sorted=False, force=True)
     line = gzip.open(fn, "rt").readline()
     assert str(line).startswith("#"), line
@@ -486,14 +481,16 @@
         pass
 
 
-def test_issue_180():
-    a = pybedtools.example_bedtool("a.bed")
+def test_issue_180(tmp_path: Path) -> None:
+    shutil.copy(os.path.join(filenames.data_dir(), "a.bed"), tmp_path)
+    a = pybedtools.BedTool(tmp_path / "a.bed")
     a = a.tabix(force=True)
     assert a.tabix_contigs() == ["chr1"]
 
 
-def test_issue_181():
-    a = pybedtools.example_bedtool("a.bed")
+def test_issue_181(tmp_path: Path) -> None:
+    shutil.copy(os.path.join(filenames.data_dir(), "a.bed"), tmp_path)
+    a = pybedtools.BedTool(tmp_path / "a.bed")
     a = a.tabix(force=True)
     a.tabix_intervals("none:1-5")
     with pytest.raises(ValueError):
@@ -812,10 +809,10 @@
     assert a == b == c == d == e
 
 
-def test_issue_319():
+def test_issue_319(tmp_path: Path) -> None:
     vrn_file = os.path.join(testdir, "data", "issue319.vcf.gz")
     spliceslop = os.path.join(testdir, "data", "issue319.bed")
-    output_bed = os.path.join(testdir, "data", "issue319.out.bed")
+    output_bed = tmp_path / "issue319.out.bed"
     bt = pybedtools.BedTool(vrn_file).intersect(spliceslop, wa=True, header=True, v=True).saveas(output_bed)
 
 
--- python-pybedtools.orig/pybedtools/test/test_iter.py
+++ python-pybedtools/pybedtools/test/test_iter.py
@@ -5,17 +5,8 @@
 import os
 import gzip
 import pybedtools
-from .tfuncs import test_tempdir
-
-def setup_module():
-    if not os.path.exists(test_tempdir):
-        os.system("mkdir -p %s" % test_tempdir)
-    pybedtools.set_tempdir(test_tempdir)
-
 
 def teardown_module():
-    if os.path.exists(test_tempdir):
-        os.system("rm -r %s" % test_tempdir)
     pybedtools.cleanup()
 
 yamltestdesc = ["test_cases.yaml"]
--- python-pybedtools.orig/pybedtools/test/tfuncs.py
+++ python-pybedtools/pybedtools/test/tfuncs.py
@@ -1,19 +1,9 @@
-import pytest
 import pybedtools
 import os
 
 testdir = os.path.dirname(__file__)
-test_tempdir = os.path.join(os.path.abspath(testdir), "tmp")
 unwriteable = os.path.join(os.path.abspath(testdir), "unwriteable")
 
 
-def setup_module():
-    if not os.path.exists(test_tempdir):
-        os.system("mkdir -p %s" % test_tempdir)
-    pybedtools.set_tempdir(test_tempdir)
-
-
 def teardown_module():
-    if os.path.exists(test_tempdir):
-        os.system("rm -r %s" % test_tempdir)
     pybedtools.cleanup()
