Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove nose from tests #300

Merged
merged 2 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 22 additions & 20 deletions tests/test_download_cache.py
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"]
3 changes: 2 additions & 1 deletion tests/test_ensembl_object_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 1 addition & 2 deletions tests/test_gene_objects.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
19 changes: 10 additions & 9 deletions tests/test_id_length.py
Original file line number Diff line number Diff line change
@@ -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")
7 changes: 6 additions & 1 deletion tests/test_locus.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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, "+")
Expand All @@ -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, "+")
Expand All @@ -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
Expand Down Expand Up @@ -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, "+")
Expand Down
3 changes: 1 addition & 2 deletions tests/test_search.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
3 changes: 1 addition & 2 deletions tests/test_transcript_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading