Skip to content

Commit

Permalink
remove all vestiges of nosetesting
Browse files Browse the repository at this point in the history
  • Loading branch information
daler committed Nov 20, 2018
1 parent 5d16790 commit d6c2445
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 78 deletions.
1 change: 0 additions & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
cython
matplotlib
nose
numpydoc
pandas
pyyaml
Expand Down
1 change: 0 additions & 1 deletion pybedtools/test/regression_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import pybedtools
import pybedtools.featurefuncs
import pybedtools.helpers
from nose.tools import assert_raises

def test_midpoint():
"""
Expand Down
91 changes: 48 additions & 43 deletions pybedtools/test/test1.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,10 @@
import gzip
import os, difflib, sys
from textwrap import dedent
from nose import with_setup
from nose.tools import assert_raises, raises
from pybedtools.helpers import BEDToolsError
from pybedtools import featurefuncs
import six
import pysam
#from .tfuncs import setup_module, teardown_module, testdir, test_tempdir, unwriteable
from nose.plugins.attrib import attr
from nose.plugins.skip import SkipTest
from nose.tools import assert_equal
from six.moves import socketserver
from six.moves import BaseHTTPServer
import pytest
Expand Down Expand Up @@ -187,7 +181,8 @@ def test_stream():
# this should really not be written anywhere
d = a.intersect(b, stream=True)

assert_raises(NotImplementedError, c.__eq__, d)
with pytest.raises(NotImplementedError):
c.__eq__(d)
d = d.saveas()
d_contents = open(d.fn).read()
c_contents = open(c.fn).read()
Expand Down Expand Up @@ -222,7 +217,8 @@ def test_stream():

for row in a.cut([0, 1, 2, 5], stream=True):
row[0], row[1], row[2]
assert_raises(IndexError, row.__getitem__, 4)
with pytest.raises(IndexError):
row.__getitem__(4)
cleanup_unwriteable()

def test_stream_of_stream():
Expand Down Expand Up @@ -273,7 +269,6 @@ def test_stream_of_generator():
print(sb2)
assert sb1 == sb2

@attr('slow')
def test_many_files():
"""regression test to make sure many files can be created
"""
Expand Down Expand Up @@ -302,7 +297,8 @@ def test_malformed():
print(six.advance_iterator(a_i))

# but next one is not and should raise exception
assert_raises(pybedtools.MalformedBedLineError, a_i.__next__)
with pytest.raises(pybedtools.MalformedBedLineError):
a_i.__next__()

def test_remove_invalid():
"""
Expand All @@ -328,7 +324,8 @@ def test_remove_invalid():
chr1 100 200
chr1 100 200""", from_string=True)

assert_raises(NotImplementedError, b.__eq__, cleaned)
with pytest.raises(NotImplementedError):
b.__eq__(cleaned)
assert str(b) == str(cleaned)

def test_create_from_list_long_features():
Expand Down Expand Up @@ -388,7 +385,8 @@ def test_indexing():
assert a[0] == interval

# only slices and integers allowed....
assert_raises(ValueError, a.__getitem__, 'key')
with pytest.raises(ValueError):
a.__getitem__('key')

def test_repr_and_printing():
"""
Expand All @@ -404,7 +402,6 @@ def test_repr_and_printing():
assert 'MISSING FILE' in repr(c)
assert 'stream' in repr(d)

@attr('slow')
def test_file_type():
"""
Regression test on file_type checks
Expand Down Expand Up @@ -443,7 +440,8 @@ def test_slop():
a = pybedtools.example_bedtool('a.bed')

# Make sure it complains if no genome is set
assert_raises(ValueError, a.slop, **dict(l=100, r=1))
with pytest.raises(ValueError):
a.slop(**dict(l=100, r=1))

def test_closest():
a = pybedtools.example_bedtool('a.bed')
Expand Down Expand Up @@ -483,7 +481,8 @@ def test_sequence():
AAAAAAAAAAAAAAAAAAAAAAAAAAAATCT
"""
a = pybedtools.BedTool(s, from_string=True)
assert_raises(ValueError, a.save_seqs, ('none',))
with pytest.raises(ValueError):
a.save_seqs(('none',))

fout = open(fi,'w')
for line in fasta.splitlines(True):
Expand Down Expand Up @@ -590,13 +589,18 @@ def test_eq():
# Don't allow testing equality on streams
c = a.intersect(b, stream=True)
d = a.intersect(b)
assert_raises(NotImplementedError, c.__eq__, d)
assert_raises(NotImplementedError, d.__eq__, c)
with pytest.raises(NotImplementedError):
c == d
with pytest.raises(NotImplementedError):
d == c

# Test it on iterator, too....
e = pybedtools.BedTool((i for i in a))
assert_raises(NotImplementedError, e.__eq__, a)
assert_raises(NotImplementedError, a.__eq__, e)
with pytest.raises(NotImplementedError):
a == e
with pytest.raises(NotImplementedError):
e == a


# Make sure that if we force the iterator to be consumed, it is in fact
# equal
Expand Down Expand Up @@ -646,7 +650,8 @@ def test_bedtool_creation():
a = pybedtools.example_bedtool('a.bed')
b = pybedtools.BedTool(a)
assert b.fn == a.fn
assert_raises(ValueError, pybedtools.BedTool,'nonexistent.bed')
with pytest.raises(ValueError):
pybedtools.BedTool('nonexistend.bed')

# note that *s* has both tabs and spaces....
s = """
Expand Down Expand Up @@ -856,7 +861,8 @@ def test_history_step():
tag = c.history[0].result_tag
assert pybedtools.find_tagged(tag) == c

assert_raises(ValueError, pybedtools.find_tagged, 'nonexistent')
with pytest.raises(ValueError):
pybedtools.find_tagged('nonexistent')


print(d.history)
Expand Down Expand Up @@ -1049,12 +1055,10 @@ def test_bam_to_sam_to_bam2():
assert e.file_type == 'bam'

# everybody should be the same
assert_equal_with_pretty_message = lambda expected, actual: assert_equal(expected, actual,
'{0!r} != {1!r}\nExpected:\n{0}\n\nActual:\n{1}'.format(expected, actual))
assert_equal_with_pretty_message(a, b)
assert_equal_with_pretty_message(a, c)
assert_equal_with_pretty_message(a, d)
assert_equal_with_pretty_message(a, e)
assert a == b
assert a == c
assert a == d
assert a == e


def test_bam_to_sam_to_bam():
Expand Down Expand Up @@ -1487,9 +1491,8 @@ def test_reldist():

def test_remote_bam_raises_exception_when_file_doesnt_exist():
"from #134"
def f():
with pytest.raises(ValueError):
pybedtools.BedTool('ftp://ftp-trace.ncbi.nih.gov/this/url/clearly/does/not/exist.bam', remote=True)
assert_raises(ValueError, f)


def test_issue_131():
Expand All @@ -1498,17 +1501,16 @@ def test_issue_131():
"""
from itertools import groupby

x = pybedtools.BedTool([('chr1', 12, 13, 'N', 1000, '+'),
('chr1', 12, 13, 'N', 1000, '-'),
('chr1', 12, 13, 'N', 1000, '-'),
x = pybedtools.BedTool([('chr1', 12, 13, 'N', 1000, '+'),
('chr1', 12, 13, 'N', 1000, '-'),
('chr1', 12, 13, 'N', 1000, '-'),
('chr1', 115, 116, 'N', 1000, '+')])

for key, group_ in groupby(x, key=lambda r: (r.chrom, r.start, r.end)):
print(key, map(lambda r: r.strand, group_))

@attr('url')
@pytest.mark.xfail(reason="Known failure: no support in BEDTools for remote BAM")
def test_remote_bam():
raise SkipTest("Known failure: no support in BEDTools for remote BAM")
url = 'http://genome.ucsc.edu/goldenPath/help/examples/bamExample.bam'
x = pybedtools.BedTool(url, remote=True)
#for i in x:
Expand Down Expand Up @@ -1622,8 +1624,7 @@ def fix_dataframe(df):
try:
import pandas
except ImportError:
from nose.plugins.skip import SkipTest
raise SkipTest("pandas not installed; skipping test")
pytest.xfail("pandas not installed; skipping test")

a = pybedtools.example_bedtool('a.bed')

Expand Down Expand Up @@ -1817,7 +1818,8 @@ def test_issue_141():

# "adding" a malformed file raises MalformedBedLineError
# (an uncaught exception raised when trying to intersect)
assert_raises(pybedtools.MalformedBedLineError, a.__add__, malformed)
with pytest.raises(pybedtools.MalformedBedLineError):
a + malformed

x = pybedtools.example_bedtool('x.bam')
x + a
Expand Down Expand Up @@ -1854,7 +1856,8 @@ def test_issue_145():

# trying to print causes pybedtools to interpret as a BED file, but it's
# a histogram so line 2 raises error
assert_raises(pybedtools.MalformedBedLineError, print, y)
with pytest.raises(pybedtools.MalformedBedLineError):
print(y)

# solution is to iterate over lines of file; make sure this works
for line in open(y.fn):
Expand Down Expand Up @@ -1979,8 +1982,7 @@ def test_issue_157():
try:
import pandas
except ImportError:
from nose.plugins.skip import SkipTest
raise SkipTest("pandas not installed; skipping test")
pytest.xfail("pandas not installed; skipping test")
vcf = pybedtools.example_bedtool('1000genomes-example.vcf')
bed = pybedtools.BedTool('20\t14300\t17000', from_string=True)
non_dataframe = str(vcf.intersect(bed))
Expand Down Expand Up @@ -2008,7 +2010,8 @@ def test_issue_162():
a = pybedtools.BedTool("", from_string=True)
b = pybedtools.example_bedtool("b.bed")
c = pybedtools.BedTool()
assert_raises(ValueError, b.cat, c)
with pytest.raises(ValueError):
b.cat(c)
assert str(b.cat(a)) == fix(
"""
chr1 155 200
Expand Down Expand Up @@ -2131,7 +2134,8 @@ def test_issue_218():

# Calling BEDTools with non-existent path, but the docstring should not
# have been changed.
assert_raises(OSError, x.sort)
with pytest.raises(OSError):
x.sort()
assert "Original BEDTools help" in x.sort.__doc__

# The class's docstring should have been reset though.
Expand All @@ -2141,7 +2145,8 @@ def test_issue_218():
# should detect that, adding a method that raises
# NotImplementedError...
y = constructor('x.bed')
assert_raises(NotImplementedError, y.sort)
with pytest.raises(NotImplementedError):
y.sort()

# ...and correspondingly no docstring
assert y.sort.__doc__ is None
Expand Down
5 changes: 3 additions & 2 deletions pybedtools/test/test_cbedtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import os
from pybedtools import Interval, IntervalFile
import pybedtools
from nose.tools import assert_raises, raises
from .tfuncs import setup_module, teardown_module
import pytest


PATH = os.path.dirname(__file__)
Expand Down Expand Up @@ -376,7 +376,8 @@ def test_missing_files():
def crashes():
list(iter(a))

assert_raises(BedToolsFileError, crashes)
with pytest.raises(BedToolsFileError):
crashes()

if __name__ == "__main__":
unittest.main()
Expand Down
15 changes: 7 additions & 8 deletions pybedtools/test/test_gzip_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from __future__ import print_function
from __future__ import unicode_literals
import os
from nose.tools import assert_equal, assert_list_equal
import tempfile
import pybedtools.test.tfuncs as tfuncs

Expand Down Expand Up @@ -32,7 +31,7 @@ def test_gzipped_file_types_are_bed():
agz = _make_temporary_gzip(pybedtools.example_filename('a.bed'))

agz = pybedtools.BedTool(agz)
assert_equal('bed', agz.file_type)
assert 'bed' == agz.file_type

def test_gzipped_files_can_be_intersected():
agz = _make_temporary_gzip(pybedtools.example_filename('a.bed'))
Expand All @@ -51,19 +50,19 @@ def test_gzipped_files_are_iterable_as_normal():
a = pybedtools.example_bedtool('a.bed')
for i in agz:
print(i)
assert_list_equal(list(a), list(agz))
assert list(a) == list(agz)

def test_str_representation_of_gzipped_files_is_the_same_as_normal():
agz = _make_temporary_gzip(pybedtools.example_filename('a.bed'))
agz = pybedtools.BedTool(agz)
a = pybedtools.example_bedtool('a.bed')
assert_equal(str(a), str(agz))
assert str(a) == str(agz)

def test_head_of_gzipped_files_is_the_same_as_normal():
agz = _make_temporary_gzip(pybedtools.example_filename('a.bed'))
agz = pybedtools.BedTool(agz)
a = pybedtools.example_bedtool('a.bed')
assert_equal(agz.head(), a.head())
assert agz.head() == a.head()

def test_gzipped_output():
_filename = pybedtools.example_filename('a.bed')
Expand All @@ -76,7 +75,7 @@ def test_gzipped_output():
with open(_filename) as f:
original_content = f.read()

assert_equal(original_content, uncompressed_content)
assert original_content == uncompressed_content

def test_gzipping_is_default_when_extension_is_dot_gz():
_filename = pybedtools.example_filename('a.bed')
Expand All @@ -92,7 +91,7 @@ def test_gzipping_is_default_when_extension_is_dot_gz():
# gzip will fail next line if file is not gzipped
actual_content = gf.read()

assert_equal(expected_content, actual_content)
assert expected_content == actual_content
finally:
if os.path.isfile(temp_filename):
os.unlink(temp_filename)
Expand All @@ -111,7 +110,7 @@ def test_gzipping_can_be_turned_off_even_for_dot_gz():
# actual content will be jumbled if non_gz_f is unset
actual_content = non_gz_f.read()

assert_equal(expected_content, actual_content)
assert expected_content == actual_content
finally:
if os.path.isfile(temp_filename):
os.unlink(temp_filename)
Expand Down
Loading

0 comments on commit d6c2445

Please sign in to comment.