1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
|
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()
|