From d6c2445567860b7e0257fa531b4abb18f00c1a7e Mon Sep 17 00:00:00 2001 From: Ryan Dale Date: Tue, 20 Nov 2018 18:10:03 -0500 Subject: [PATCH] remove all vestiges of nosetesting --- dev-requirements.txt | 1 - pybedtools/test/regression_tests.py | 1 - pybedtools/test/test1.py | 91 +++++++++++++++------------- pybedtools/test/test_cbedtools.py | 5 +- pybedtools/test/test_gzip_support.py | 15 +++-- pybedtools/test/test_helpers.py | 32 +++++----- pybedtools/test/test_scripts.py | 21 ++++--- 7 files changed, 88 insertions(+), 78 deletions(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index 081c36a4..653e3c3b 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,6 +1,5 @@ cython matplotlib -nose numpydoc pandas pyyaml diff --git a/pybedtools/test/regression_tests.py b/pybedtools/test/regression_tests.py index 637e63ab..61a8626d 100644 --- a/pybedtools/test/regression_tests.py +++ b/pybedtools/test/regression_tests.py @@ -6,7 +6,6 @@ import pybedtools import pybedtools.featurefuncs import pybedtools.helpers -from nose.tools import assert_raises def test_midpoint(): """ diff --git a/pybedtools/test/test1.py b/pybedtools/test/test1.py index c6873858..08f5d433 100644 --- a/pybedtools/test/test1.py +++ b/pybedtools/test/test1.py @@ -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 @@ -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() @@ -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(): @@ -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 """ @@ -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(): """ @@ -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(): @@ -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(): """ @@ -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 @@ -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') @@ -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): @@ -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 @@ -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 = """ @@ -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) @@ -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(): @@ -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(): @@ -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: @@ -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') @@ -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 @@ -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): @@ -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)) @@ -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 @@ -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. @@ -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 diff --git a/pybedtools/test/test_cbedtools.py b/pybedtools/test/test_cbedtools.py index 70f5ee0b..89327ba9 100644 --- a/pybedtools/test/test_cbedtools.py +++ b/pybedtools/test/test_cbedtools.py @@ -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__) @@ -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() diff --git a/pybedtools/test/test_gzip_support.py b/pybedtools/test/test_gzip_support.py index 996a6790..1d7a54ce 100644 --- a/pybedtools/test/test_gzip_support.py +++ b/pybedtools/test/test_gzip_support.py @@ -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 @@ -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')) @@ -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') @@ -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') @@ -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) @@ -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) diff --git a/pybedtools/test/test_helpers.py b/pybedtools/test/test_helpers.py index 4e1cee6c..f2f7236e 100644 --- a/pybedtools/test/test_helpers.py +++ b/pybedtools/test/test_helpers.py @@ -1,9 +1,8 @@ import pybedtools import sys import os, difflib -from nose.tools import assert_raises -from nose.plugins.attrib import attr from .tfuncs import setup_module, teardown_module, testdir, test_tempdir, unwriteable +import pytest def fix(x): """ @@ -77,7 +76,8 @@ def test_cleanup(): def test_call(): tmp = os.path.join(pybedtools.get_tempdir(), 'test.output') from pybedtools.helpers import call_bedtools, BEDToolsError - assert_raises(BEDToolsError, call_bedtools, *(['intersectBe'], tmp)) + with pytest.raises(BEDToolsError): + call_bedtools(*(['intersectBe'], tmp)) a = pybedtools.example_bedtool('a.bed') @@ -85,21 +85,22 @@ def test_call(): # over the place when testing orig_stderr = sys.stderr sys.stderr = open(a._tmp(), 'w') - #assert_raises(BEDToolsError, a.intersect, a=a.fn, b=a.fn, z=True) sys.stderr = orig_stderr pybedtools.set_bedtools_path('nonexistent') a = pybedtools.example_bedtool('a.bed') - assert_raises(NotImplementedError, a.intersect, a) + with pytest.raises(NotImplementedError): + a.intersect(a) pybedtools.set_bedtools_path() a = pybedtools.example_bedtool('a.bed') assert a.intersect(a,u=True) == a -@attr('url') def test_chromsizes(): - assert_raises(OSError, pybedtools.get_chromsizes_from_ucsc, 'dm3', mysql='wrong path', fetchchromsizes='wrongtoo') - assert_raises(ValueError, pybedtools.get_chromsizes_from_ucsc, 'dm3', timeout=0) + with pytest.raises(OSError): + pybedtools.get_chromsizes_from_ucsc('dm3', mysql='wrong path', fetchchromsizes='wrongtoo') + with pytest.raises(ValueError): + pybedtools.get_chromsizes_from_ucsc('dm3', timeout=0) try: print(pybedtools.chromsizes('dm3')) @@ -123,9 +124,9 @@ def test_chromsizes(): print(results) assert expected == results - assert_raises(OSError, - pybedtools.get_chromsizes_from_ucsc, - **dict(genome='hg17', mysql='nonexistent', fetchchromsizes='missing')) + with pytest.raises(OSError): + pybedtools.get_chromsizes_from_ucsc( + **dict(genome='hg17', mysql='nonexistent', fetchchromsizes='missing')) os.unlink('hg17.genome') except OSError: @@ -152,9 +153,12 @@ def test_getting_example_beds(): assert a.fn == os.path.join(testdir, 'data', 'a.bed') # complain appropriately if nonexistent paths are asked for - assert_raises(ValueError, pybedtools.example_filename, 'nonexistent') - assert_raises(ValueError, pybedtools.example_bedtool, 'nonexistent') - assert_raises(ValueError, pybedtools.set_tempdir, 'nonexistent') + with pytest.raises(ValueError): + pybedtools.example_filename('nonexistent') + with pytest.raises(ValueError): + pybedtools.example_bedtool('nonexistent') + with pytest.raises(ValueError): + pybedtools.set_tempdir('nonexistent') def teardown(): diff --git a/pybedtools/test/test_scripts.py b/pybedtools/test/test_scripts.py index 9cd95491..d39454a4 100644 --- a/pybedtools/test/test_scripts.py +++ b/pybedtools/test/test_scripts.py @@ -2,9 +2,7 @@ from textwrap import dedent from .tfuncs import setup_module, teardown_module from pybedtools.scripts import annotate, venn_mpl, venn_gchart -from nose.tools import assert_raises, assert_equal -from nose.plugins.attrib import attr -from nose.plugins.skip import SkipTest +import pytest import subprocess as sp import os import sys @@ -14,7 +12,8 @@ def test_annotate_main(): # exits after printing help when sys.argv is not as it should be. orig_stderr = sys.stderr sys.stderr = open('annotmp','w') - assert_raises(SystemExit, annotate.main) + with pytest.raises(SystemExit): + annotate.main() sys.stderr = orig_stderr os.unlink('annotmp') @@ -100,12 +99,14 @@ def test_venn_gchart_data_is_correct(): for key in expected_data.keys(): e = expected_data[key] o = data[key] - assert_equal(e, o, 'Key:{!r}\nExpected:{!r}\nObserved:{!r}\n'.format(key, e, o)) + assert e == o +@pytest.mark.skip( + 'Small differences between fonts in PNG are sometimes produced and need to be accounted for' +) def test_venn_gchart_png_is_saved_correctly(): - from nose.plugins.skip import SkipTest - raise SkipTest('Small differences between fonts in PNG are sometimes produced and need to be accounted for') + here = os.path.dirname(__file__) expected = open(os.path.join(here, 'gchart-expected.png')).read() @@ -132,14 +133,16 @@ def test_venn_gchart_png_is_saved_correctly(): def test_venn_mpl_main(): orig_stderr = sys.stderr sys.stderr = open('mpltmp','w') - assert_raises(SystemExit, venn_mpl.main) + with pytest.raises(SystemExit): + venn_mpl.main() sys.stderr = orig_stderr os.unlink('mpltmp') def test_venn_gchart_main(): orig_stderr = sys.stderr sys.stderr = open('gcharttmp','w') - assert_raises(SystemExit, venn_gchart.main) + with pytest.raises(SystemExit): + venn_gchart.main() sys.stderr = orig_stderr os.unlink('gcharttmp')