diff --git a/tests/common.py b/tests/common.py index ea1ecff..dede01c 100644 --- a/tests/common.py +++ b/tests/common.py @@ -46,6 +46,10 @@ def __exit__(self, type, value, traceback): return False +def ok_(b): + assert b + + def eq_(x, y, msg=None): if msg is None: assert x == y diff --git a/tests/test_download_cache.py b/tests/test_download_cache.py index 03c7da6..c92df97 100644 --- a/tests/test_download_cache.py +++ b/tests/test_download_cache.py @@ -1,33 +1,37 @@ -from nose.tools import assert_raises, ok_ -from pyensembl.download_cache import ( - DownloadCache, - MissingLocalFile, - MissingRemoteFile -) - import os import tempfile +from pytest import raises as assert_raises +from pyensembl.download_cache import DownloadCache, MissingLocalFile, MissingRemoteFile + + from .data import data_path +from .common import ok_ download_cache = DownloadCache( reference_name="__test_reference", annotation_name="__test_annotation", - copy_local_files_to_cache=False) + copy_local_files_to_cache=False, +) + def test_download_cache_missing_local_file(): # clear the cache download_cache.delete_cache_directory() with assert_raises(MissingLocalFile): download_cache.download_or_copy_if_necessary( - path_or_url="test_file_doesn_not_exist.file") + path_or_url="test_file_doesn_not_exist.file" + ) + def test_download_cache_missing_remote_file(): # clear the cache download_cache.delete_cache_directory() with assert_raises(MissingRemoteFile): download_cache.download_or_copy_if_necessary( - path_or_url="ftp://NOTAURL.NOTAURL.NOTAURL") + path_or_url="ftp://NOTAURL.NOTAURL.NOTAURL" + ) + def test_download_cache_custom_location(): test_file = "refseq.ucsc.small.gtf" @@ -36,29 +40,27 @@ def test_download_cache_custom_location(): print("DIR: %s" % tmp_dir) assert tmp_dir is not None - os.environ['PYENSEMBL_CACHE_DIR'] = tmp_dir + os.environ["PYENSEMBL_CACHE_DIR"] = tmp_dir # We need another instance of DownloadCache # that copies files over to cache folder download_cache = DownloadCache( reference_name="test_reference", annotation_name="test_annotation", - copy_local_files_to_cache=True) + copy_local_files_to_cache=True, + ) # clean up download_cache.delete_cache_directory() download_cache.download_or_copy_if_necessary( - download_if_missing=True, - path_or_url=data_path(test_file)) + download_if_missing=True, path_or_url=data_path(test_file) + ) full_path = os.path.join( - tmp_dir, - "pyensembl", - "test_reference", - "test_annotation", - test_file) + tmp_dir, "pyensembl", "test_reference", "test_annotation", test_file + ) print("FULL PATH: %s" % full_path) assert len(full_path) > 0 ok_(os.path.exists(full_path)) - del os.environ['PYENSEMBL_CACHE_DIR'] + del os.environ["PYENSEMBL_CACHE_DIR"] diff --git a/tests/test_ensembl_object_properties.py b/tests/test_ensembl_object_properties.py index ff90dcf..8aded92 100644 --- a/tests/test_ensembl_object_properties.py +++ b/tests/test_ensembl_object_properties.py @@ -5,9 +5,10 @@ from __future__ import absolute_import -from nose.tools import eq_ +from .common import eq_ from pyensembl import EnsemblRelease, MAX_ENSEMBL_RELEASE + def test_human_reference_name(): eq_(EnsemblRelease(release=54).reference_name, "NCBI36") eq_(EnsemblRelease(release=74).reference_name, "GRCh37") diff --git a/tests/test_gene_objects.py b/tests/test_gene_objects.py index e66f639..5689bf4 100644 --- a/tests/test_gene_objects.py +++ b/tests/test_gene_objects.py @@ -1,5 +1,4 @@ -from nose.tools import eq_ - +from .common import eq_ from .common import run_multiple_genomes from .data import TP53_gene_id diff --git a/tests/test_id_length.py b/tests/test_id_length.py index 7371cd4..2e8d7e3 100644 --- a/tests/test_id_length.py +++ b/tests/test_id_length.py @@ -1,24 +1,25 @@ from .common import major_releases -from nose.tools import nottest -@nottest def check_id_length(method_name): for release in major_releases: method = getattr(release, method_name) # only load chromosome Y to speed up tests idents = method(contig="Y") assert len(idents) > 0, "No values returned by %s" % method_name - assert all(len(ident) == 15 for ident in idents), \ - "Invalid IDs for %s: %s" % ( - method_name, - [ident for ident in idents if len(ident) != 15]) + assert all(len(ident) == 15 for ident in idents), "Invalid IDs for %s: %s" % ( + method_name, + [ident for ident in idents if len(ident) != 15], + ) + def test_gene_id_length(): - check_id_length('gene_ids') + check_id_length("gene_ids") + def test_transcript_id_length(): - check_id_length('transcript_ids') + check_id_length("transcript_ids") + def test_protein_id_length(): - check_id_length('protein_ids') + check_id_length("protein_ids") diff --git a/tests/test_locus.py b/tests/test_locus.py index a1af6fd..f83026b 100644 --- a/tests/test_locus.py +++ b/tests/test_locus.py @@ -1,7 +1,8 @@ from pyensembl.locus import Locus from pyensembl.normalization import normalize_chromosome -from nose.tools import assert_raises +from pytest import raises as assert_raises + def test_normalize_chromosome(): assert normalize_chromosome("X") == "X" @@ -38,6 +39,7 @@ def test_normalize_chromosome(): with assert_raises(ValueError): normalize_chromosome(0) + def test_locus_overlaps(): locus = Locus("1", 10, 20, "+") assert locus.overlaps("1", 10, 20, "+") @@ -57,6 +59,7 @@ def test_locus_overlaps(): # wrong strand assert not locus.overlaps("1", 10, 20, "-") + def test_locus_contains(): locus = Locus("1", 10, 20, "+") assert locus.contains("1", 10, 20, "+") @@ -82,6 +85,7 @@ def test_locus_contains(): # wrong strand assert not locus.contains("1", 10, 20, "-") + def test_position_offset(): forward_locus = Locus("1", 10, 20, "+") assert forward_locus.offset(10) == 0 @@ -143,6 +147,7 @@ def test_range_offset(): with assert_raises(ValueError): negative_locus.offset_range(9, 10) + def test_locus_distance(): locus_chr1_10_20_pos = Locus("1", 10, 20, "+") locus_chr1_21_25_pos = Locus("1", 21, 25, "+") diff --git a/tests/test_search.py b/tests/test_search.py index f4aa8e3..3ccb9f4 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -1,6 +1,5 @@ -from nose.tools import eq_ - from pyensembl import find_nearest_locus +from .common import eq_ from .common import run_multiple_genomes diff --git a/tests/test_transcript_ids.py b/tests/test_transcript_ids.py index b806608..8cc6b4e 100644 --- a/tests/test_transcript_ids.py +++ b/tests/test_transcript_ids.py @@ -5,8 +5,7 @@ from __future__ import absolute_import from pyensembl import genome_for_reference_name -from nose.tools import eq_ - +from .common import eq_ from .common import run_multiple_genomes grch38 = genome_for_reference_name("GRCh38")