Commit f73aa7a5 authored by Amir MOHAMMADI's avatar Amir MOHAMMADI

Merge branch 'pytest' into 'master'

Replace nose with pytest

See merge request !108
parents c50e1c52 90c10e19
Pipeline #49317 passed with stages
in 38 minutes and 12 seconds
...@@ -20,12 +20,8 @@ ...@@ -20,12 +20,8 @@
import bob.io.base import bob.io.base
import bob.ip.gabor import bob.ip.gabor
import unittest
import os
import numpy import numpy
import math import math
import tempfile
from nose.plugins.skip import SkipTest
import pkg_resources import pkg_resources
......
from bob.extension.config import load
import pkg_resources import pkg_resources
import numpy as np import numpy as np
from bob.pipelines import Sample, SampleSet, DelayedSample from bob.pipelines import Sample, SampleSet, DelayedSample
...@@ -12,7 +11,7 @@ import os ...@@ -12,7 +11,7 @@ import os
import bob.io.base import bob.io.base
import functools import functools
import copy import copy
from nose.plugins.attrib import attr import pytest
from bob.bio.base.test.utils import is_library_available from bob.bio.base.test.utils import is_library_available
...@@ -107,37 +106,37 @@ def run_baseline(baseline, samples_for_training=[]): ...@@ -107,37 +106,37 @@ def run_baseline(baseline, samples_for_training=[]):
assert "scores" in dirs assert "scores" in dirs
@attr('slow') @pytest.mark.slow
@is_library_available("tensorflow") @is_library_available("tensorflow")
def test_facenet_baseline(): def test_facenet_baseline():
run_baseline("facenet-sanderberg") run_baseline("facenet-sanderberg")
@attr('slow') @pytest.mark.slow
@is_library_available("tensorflow") @is_library_available("tensorflow")
def test_inception_resnetv2_msceleb(): def test_inception_resnetv2_msceleb():
run_baseline("inception-resnetv2-msceleb") run_baseline("inception-resnetv2-msceleb")
@attr('slow') @pytest.mark.slow
@is_library_available("tensorflow") @is_library_available("tensorflow")
def test_inception_resnetv2_casiawebface(): def test_inception_resnetv2_casiawebface():
run_baseline("inception-resnetv2-casiawebface") run_baseline("inception-resnetv2-casiawebface")
@attr('slow') @pytest.mark.slow
@is_library_available("tensorflow") @is_library_available("tensorflow")
def test_inception_resnetv1_msceleb(): def test_inception_resnetv1_msceleb():
run_baseline("inception-resnetv1-msceleb") run_baseline("inception-resnetv1-msceleb")
@attr('slow') @pytest.mark.slow
@is_library_available("tensorflow") @is_library_available("tensorflow")
def test_inception_resnetv1_casiawebface(): def test_inception_resnetv1_casiawebface():
run_baseline("inception-resnetv1-casiawebface") run_baseline("inception-resnetv1-casiawebface")
@attr('slow') @pytest.mark.slow
@is_library_available("mxnet") @is_library_available("mxnet")
def test_arcface_insightface(): def test_arcface_insightface():
run_baseline("arcface-insightface") run_baseline("arcface-insightface")
......
...@@ -18,13 +18,13 @@ ...@@ -18,13 +18,13 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from nose.plugins.skip import SkipTest import pytest
import os
import bob.bio.base import bob.bio.base
from bob.bio.base.test.utils import db_available from bob.bio.base.test.utils import db_available
from bob.bio.base.test.test_database_implementations import ( from bob.bio.base.test.test_database_implementations import (
check_database, check_database,
check_database_zt,
) )
import bob.core import bob.core
from bob.extension.download import get_file from bob.extension.download import get_file
...@@ -72,14 +72,14 @@ def test_arface(): ...@@ -72,14 +72,14 @@ def test_arface():
try: try:
check_database(database, groups=("dev", "eval")) check_database(database, groups=("dev", "eval"))
except IOError as e: except IOError as e:
raise SkipTest( pytest.skip("The database could not queried; probably the db.sql3 file is missing. Here is the error: '%s'"
"The database could not queried; probably the db.sql3 file is missing. Here is the error: '%s'"
% e % e
) )
try: try:
_check_annotations(database) _check_annotations(database)
except IOError as e: except IOError as e:
raise SkipTest( pytest.skip(
"The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'" "The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'"
% e % e
) )
...@@ -93,7 +93,7 @@ def test_atnt(): ...@@ -93,7 +93,7 @@ def test_atnt():
try: try:
check_database(database) check_database(database)
except IOError as e: except IOError as e:
raise SkipTest( pytest.skip(
"The database could not queried; probably the db.sql3 file is missing. Here is the error: '%s'" "The database could not queried; probably the db.sql3 file is missing. Here is the error: '%s'"
% e % e
) )
...@@ -109,14 +109,14 @@ def test_gbu(): ...@@ -109,14 +109,14 @@ def test_gbu():
check_database(database, protocol="Bad", models_depend=True) check_database(database, protocol="Bad", models_depend=True)
check_database(database, protocol="Ugly", models_depend=True) check_database(database, protocol="Ugly", models_depend=True)
except IOError as e: except IOError as e:
raise SkipTest( pytest.skip(
"The database could not queried; probably the db.sql3 file is missing. Here is the error: '%s'" "The database could not queried; probably the db.sql3 file is missing. Here is the error: '%s'"
% e % e
) )
try: try:
_check_annotations(database, limit_files=1000) _check_annotations(database, limit_files=1000)
except IOError as e: except IOError as e:
raise SkipTest( pytest.skip(
"The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'" "The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'"
% e % e
) )
...@@ -144,14 +144,14 @@ def test_lfw(): ...@@ -144,14 +144,14 @@ def test_lfw():
models_depend=True, models_depend=True,
) )
except IOError as e: except IOError as e:
raise SkipTest( pytest.skip(
"The database could not queried; probably the db.sql3 file is missing. Here is the error: '%s'" "The database could not queried; probably the db.sql3 file is missing. Here is the error: '%s'"
% e % e
) )
try: try:
_check_annotations(database, limit_files=1000) _check_annotations(database, limit_files=1000)
except IOError as e: except IOError as e:
raise SkipTest( pytest.skip(
"The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'" "The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'"
% e % e
) )
...@@ -167,7 +167,7 @@ def test_mobio(): ...@@ -167,7 +167,7 @@ def test_mobio():
# Removing the file before the test # Removing the file before the test
try: try:
os.remove(filename) os.remove(filename)
except: except Exception:
pass pass
protocols = MobioDatabase.protocols() protocols = MobioDatabase.protocols()
...@@ -206,7 +206,7 @@ def test_multipie(): ...@@ -206,7 +206,7 @@ def test_multipie():
# Removing the file before the test # Removing the file before the test
try: try:
os.remove(filename) os.remove(filename)
except: except Exception:
pass pass
protocols = MultipieDatabase.protocols() protocols = MultipieDatabase.protocols()
...@@ -239,14 +239,14 @@ def test_replay_licit(): ...@@ -239,14 +239,14 @@ def test_replay_licit():
try: try:
check_database(database, groups=("dev", "eval")) check_database(database, groups=("dev", "eval"))
except IOError as e: except IOError as e:
raise SkipTest( pytest.skip(
"The database could not be queried; probably the db.sql3 file is missing. Here is the error: '%s'" "The database could not be queried; probably the db.sql3 file is missing. Here is the error: '%s'"
% e % e
) )
try: try:
_check_annotations(database, topleft=True) _check_annotations(database, topleft=True)
except IOError as e: except IOError as e:
raise SkipTest( pytest.skip(
"The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'" "The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'"
% e % e
) )
...@@ -260,14 +260,14 @@ def test_replay_spoof(): ...@@ -260,14 +260,14 @@ def test_replay_spoof():
try: try:
check_database(database, groups=("dev", "eval")) check_database(database, groups=("dev", "eval"))
except IOError as e: except IOError as e:
raise SkipTest( pytest.skip(
"The database could not be queried; probably the db.sql3 file is missing. Here is the error: '%s'" "The database could not be queried; probably the db.sql3 file is missing. Here is the error: '%s'"
% e % e
) )
try: try:
_check_annotations(database, topleft=True) _check_annotations(database, topleft=True)
except IOError as e: except IOError as e:
raise SkipTest( pytest.skip(
"The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'" "The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'"
% e % e
) )
...@@ -281,14 +281,14 @@ def test_replaymobile_licit(): ...@@ -281,14 +281,14 @@ def test_replaymobile_licit():
try: try:
check_database(database, groups=("dev", "eval")) check_database(database, groups=("dev", "eval"))
except IOError as e: except IOError as e:
raise SkipTest( pytest.skip(
"The database could not be queried; probably the db.sql3 file is missing. Here is the error: '%s'" "The database could not be queried; probably the db.sql3 file is missing. Here is the error: '%s'"
% e % e
) )
try: try:
_check_annotations(database, topleft=True, limit_files=20) _check_annotations(database, topleft=True, limit_files=20)
except IOError as e: except IOError as e:
raise SkipTest( pytest.skip(
"The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'" "The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'"
% e % e
) )
...@@ -302,14 +302,14 @@ def test_replaymobile_spoof(): ...@@ -302,14 +302,14 @@ def test_replaymobile_spoof():
try: try:
check_database(database, groups=("dev", "eval")) check_database(database, groups=("dev", "eval"))
except IOError as e: except IOError as e:
raise SkipTest( pytest.skip(
"The database could not be queried; probably the db.sql3 file is missing. Here is the error: '%s'" "The database could not be queried; probably the db.sql3 file is missing. Here is the error: '%s'"
% e % e
) )
try: try:
_check_annotations(database, topleft=True, limit_files=20) _check_annotations(database, topleft=True, limit_files=20)
except IOError as e: except IOError as e:
raise SkipTest( pytest.skip(
"The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'" "The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'"
% e % e
) )
...@@ -323,11 +323,11 @@ def test_ijbc(): ...@@ -323,11 +323,11 @@ def test_ijbc():
try: try:
check_database(database, models_depend=True, training_depends=True) check_database(database, models_depend=True, training_depends=True)
except IOError as e: except IOError as e:
raise SkipTest("The database could not queried; Here is the error: '%s'" % e) pytest.skip("The database could not queried; Here is the error: '%s'" % e)
try: try:
_check_annotations(database, topleft=True, limit_files=1000) _check_annotations(database, topleft=True, limit_files=1000)
except IOError as e: except IOError as e:
raise SkipTest( pytest.skip(
"The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'" "The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'"
% e % e
) )
...@@ -341,7 +341,7 @@ def test_fargo(): ...@@ -341,7 +341,7 @@ def test_fargo():
try: try:
check_database(database) check_database(database)
except IOError as e: except IOError as e:
raise SkipTest("The database could not queried; Here is the error: '%s'" % e) pytest.skip("The database could not queried; Here is the error: '%s'" % e)
def test_meds(): def test_meds():
...@@ -355,7 +355,7 @@ def test_meds(): ...@@ -355,7 +355,7 @@ def test_meds():
# Removing the file before the test # Removing the file before the test
try: try:
os.remove(filename) os.remove(filename)
except: except Exception:
pass pass
database = MEDSDatabase("verification_fold1") database = MEDSDatabase("verification_fold1")
...@@ -382,7 +382,7 @@ def test_morph(): ...@@ -382,7 +382,7 @@ def test_morph():
# Removing the file before the test # Removing the file before the test
try: try:
os.remove(filename) os.remove(filename)
except: except Exception:
pass pass
database = MorphDatabase("verification_fold1") database = MorphDatabase("verification_fold1")
......
...@@ -4,10 +4,10 @@ import numpy as np ...@@ -4,10 +4,10 @@ import numpy as np
from bob.pipelines import Sample, wrap from bob.pipelines import Sample, wrap
import pkg_resources import pkg_resources
from bob.bio.base.test.utils import is_library_available from bob.bio.base.test.utils import is_library_available
from nose.plugins.attrib import attr import pytest
@attr('slow') @pytest.mark.slow
@is_library_available("tensorflow") @is_library_available("tensorflow")
def test_idiap_inceptionv2_msceleb(): def test_idiap_inceptionv2_msceleb():
from bob.bio.face.embeddings.tf2_inception_resnet import ( from bob.bio.face.embeddings.tf2_inception_resnet import (
...@@ -34,7 +34,7 @@ def test_idiap_inceptionv2_msceleb(): ...@@ -34,7 +34,7 @@ def test_idiap_inceptionv2_msceleb():
assert output.size == 128, output.shape assert output.size == 128, output.shape
@attr('slow') @pytest.mark.slow
@is_library_available("tensorflow") @is_library_available("tensorflow")
def test_idiap_inceptionv2_msceleb_memory_demanding(): def test_idiap_inceptionv2_msceleb_memory_demanding():
from bob.bio.face.embeddings.tf2_inception_resnet import ( from bob.bio.face.embeddings.tf2_inception_resnet import (
...@@ -62,7 +62,7 @@ def test_idiap_inceptionv2_msceleb_memory_demanding(): ...@@ -62,7 +62,7 @@ def test_idiap_inceptionv2_msceleb_memory_demanding():
assert output.size == 128, output.shape assert output.size == 128, output.shape
@attr('slow') @pytest.mark.slow
@is_library_available("tensorflow") @is_library_available("tensorflow")
def test_idiap_inceptionv2_casia(): def test_idiap_inceptionv2_casia():
from bob.bio.face.embeddings.tf2_inception_resnet import ( from bob.bio.face.embeddings.tf2_inception_resnet import (
...@@ -89,7 +89,7 @@ def test_idiap_inceptionv2_casia(): ...@@ -89,7 +89,7 @@ def test_idiap_inceptionv2_casia():
assert output.size == 128, output.shape assert output.size == 128, output.shape
@attr('slow') @pytest.mark.slow
@is_library_available("tensorflow") @is_library_available("tensorflow")
def test_idiap_inceptionv1_msceleb(): def test_idiap_inceptionv1_msceleb():
from bob.bio.face.embeddings.tf2_inception_resnet import ( from bob.bio.face.embeddings.tf2_inception_resnet import (
...@@ -116,7 +116,7 @@ def test_idiap_inceptionv1_msceleb(): ...@@ -116,7 +116,7 @@ def test_idiap_inceptionv1_msceleb():
assert output.size == 128, output.shape assert output.size == 128, output.shape
@attr('slow') @pytest.mark.slow
@is_library_available("tensorflow") @is_library_available("tensorflow")
def test_idiap_inceptionv1_casia(): def test_idiap_inceptionv1_casia():
from bob.bio.face.embeddings.tf2_inception_resnet import ( from bob.bio.face.embeddings.tf2_inception_resnet import (
...@@ -143,7 +143,7 @@ def test_idiap_inceptionv1_casia(): ...@@ -143,7 +143,7 @@ def test_idiap_inceptionv1_casia():
assert output.size == 128, output.shape assert output.size == 128, output.shape
@attr('slow') @pytest.mark.slow
@is_library_available("tensorflow") @is_library_available("tensorflow")
def test_facenet_sanderberg(): def test_facenet_sanderberg():
from bob.bio.face.embeddings.tf2_inception_resnet import ( from bob.bio.face.embeddings.tf2_inception_resnet import (
...@@ -170,7 +170,7 @@ def test_facenet_sanderberg(): ...@@ -170,7 +170,7 @@ def test_facenet_sanderberg():
assert output.size == 128, output.shape assert output.size == 128, output.shape
@attr('slow') @pytest.mark.slow
@is_library_available("mxnet") @is_library_available("mxnet")
def test_arcface_insight_face(): def test_arcface_insight_face():
from bob.bio.face.embeddings.mxnet_models import ArcFaceInsightFace from bob.bio.face.embeddings.mxnet_models import ArcFaceInsightFace
......
...@@ -20,14 +20,10 @@ ...@@ -20,14 +20,10 @@
import bob.bio.base import bob.bio.base
import bob.bio.face import bob.bio.face
import unittest
import os
import numpy import numpy
import math import math
from nose.plugins.skip import SkipTest
import bob.io.base.test_utils import bob.io.base.test_utils
from bob.bio.base.test import utils
import pkg_resources import pkg_resources
......
...@@ -2,7 +2,6 @@ import bob.bio.face ...@@ -2,7 +2,6 @@ import bob.bio.face
import bob.bio.base import bob.bio.base
import numpy as np import numpy as np
import pickle import pickle
import nose
import bob.ip.base import bob.ip.base
import bob.ip.flandmark import bob.ip.flandmark
...@@ -41,13 +40,13 @@ def assert_picklable_with_exceptions(obj): ...@@ -41,13 +40,13 @@ def assert_picklable_with_exceptions(obj):
obj = obj.__dict__ obj = obj.__dict__
new_obj = new_obj.__dict__ new_obj = new_obj.__dict__
assert len(obj) == len(new_obj) assert len(obj) == len(new_obj)
nose.tools.assert_equal(sorted(list(obj.keys())), sorted(list(new_obj.keys()))) assert sorted(list(obj.keys())) == sorted(list(new_obj.keys()))
for k, v in obj.items(): for k, v in obj.items():
if isinstance(v, np.ndarray): if isinstance(v, np.ndarray):
np.testing.assert_equal(v, new_obj[k]) np.testing.assert_equal(v, new_obj[k])
else: else:
if type(v) not in exception_list: if type(v) not in exception_list:
nose.tools.assert_equal(v, new_obj[k]) assert v == new_obj[k]
return True return True
......
from bob.extension.config import load
import pkg_resources
import numpy as np import numpy as np
from bob.pipelines import Sample, SampleSet from bob.pipelines import Sample
from bob.bio.base import load_resource from bob.bio.base import load_resource
from bob.bio.base.test.utils import is_library_available from bob.bio.base.test.utils import is_library_available
from nose.plugins.attrib import attr import pytest
def get_fake_sample(face_size=(160, 160), eyes={"leye": (46, 107), "reye": (46, 53)}): def get_fake_sample(face_size=(160, 160), eyes={"leye": (46, 107), "reye": (46, 53)}):
...@@ -14,7 +12,7 @@ def get_fake_sample(face_size=(160, 160), eyes={"leye": (46, 107), "reye": (46, ...@@ -14,7 +12,7 @@ def get_fake_sample(face_size=(160, 160), eyes={"leye": (46, 107), "reye": (46,
return Sample(data, key="1", annotations=annotations) return Sample(data, key="1", annotations=annotations)
@attr('slow') @pytest.mark.slow
@is_library_available("tensorflow") @is_library_available("tensorflow")
def test_facenet_sanderberg(): def test_facenet_sanderberg():
transformer = load_resource("facenet-sanderberg", "transformer") transformer = load_resource("facenet-sanderberg", "transformer")
...@@ -26,7 +24,7 @@ def test_facenet_sanderberg(): ...@@ -26,7 +24,7 @@ def test_facenet_sanderberg():
assert transformed_sample.data.size == 128 assert transformed_sample.data.size == 128
@attr('slow') @pytest.mark.slow
@is_library_available("tensorflow") @is_library_available("tensorflow")
def test_inception_resnetv2_msceleb(): def test_inception_resnetv2_msceleb():
transformer = load_resource("inception-resnetv2-msceleb", "transformer") transformer = load_resource("inception-resnetv2-msceleb", "transformer")
...@@ -38,7 +36,7 @@ def test_inception_resnetv2_msceleb(): ...@@ -38,7 +36,7 @@ def test_inception_resnetv2_msceleb():
assert transformed_sample.data.size == 128 assert transformed_sample.data.size == 128
@attr('slow') @pytest.mark.slow
@is_library_available("tensorflow") @is_library_available("tensorflow")
def test_inception_resnetv2_casiawebface(): def test_inception_resnetv2_casiawebface():
transformer = load_resource("inception-resnetv2-casiawebface", "transformer") transformer = load_resource("inception-resnetv2-casiawebface", "transformer")
...@@ -50,7 +48,7 @@ def test_inception_resnetv2_casiawebface(): ...@@ -50,7 +48,7 @@ def test_inception_resnetv2_casiawebface():
assert transformed_sample.data.size == 128 assert transformed_sample.data.size == 128
@attr('slow') @pytest.mark.slow
@is_library_available("tensorflow") @is_library_available("tensorflow")
def test_inception_resnetv1_msceleb(): def test_inception_resnetv1_msceleb():
transformer = load_resource("inception-resnetv1-msceleb", "transformer") transformer = load_resource("inception-resnetv1-msceleb", "transformer")
...@@ -62,7 +60,7 @@ def test_inception_resnetv1_msceleb(): ...@@ -62,7 +60,7 @@ def test_inception_resnetv1_msceleb():
assert transformed_sample.data.size == 128 assert transformed_sample.data.size == 128
@attr('slow') @pytest.mark.slow
@is_library_available("tensorflow") @is_library_available("tensorflow")
def test_inception_resnetv1_casiawebface(): def test_inception_resnetv1_casiawebface():
transformer = load_resource("inception-resnetv1-casiawebface", "transformer") transformer = load_resource("inception-resnetv1-casiawebface", "transformer")
......
...@@ -59,7 +59,9 @@ test: ...@@ -59,7 +59,9 @@ test:
- {{ name }} - {{ name }}
commands: commands:
- bob bio display-face-annotations --help - bob bio display-face-annotations --help
- nosetests --with-coverage --cover-package={{ name }} -sv {{ name }} # runs tests for package only, report only what is in the package
# creates html and xml reports and place them in specific directories
- pytest --verbose --cov {{ name }} --cov-report term-missing --cov-report html:{{ project_dir }}/sphinx/coverage --cov-report xml:{{ project_dir }}/coverage.xml --pyargs {{ name }}
- sphinx-build -aEW {{ project_dir }}/doc {{ project_dir }}/sphinx - sphinx-build -aEW {{ project_dir }}/doc {{ project_dir }}/sphinx
- sphinx-build -aEb doctest {{ project_dir }}/doc sphinx - sphinx-build -aEb doctest {{ project_dir }}/doc sphinx
- conda inspect linkages -p $PREFIX {{ name }} # [not win] - conda inspect linkages -p $PREFIX {{ name }} # [not win]
...@@ -67,6 +69,8 @@ test: ...@@ -67,6 +69,8 @@ test:
requires: requires:
- bob-devel {{ bob_devel }}.* - bob-devel {{ bob_devel }}.*
- nose - nose
- pytest
- pytest-cov
- coverage - coverage
- sphinx - sphinx
- sphinx_rtd_theme - sphinx_rtd_theme
......
[build-system] [build-system]
requires = ["setuptools", "wheel", "bob.extension"] requires = ["setuptools", "wheel", "bob.extension"]
build-backend = "setuptools.build_meta" build-backend = "setuptools.build_meta"
[tool.pytest.ini_options]
markers = ["slow: marks tests as slow (deselect with '-m \"not slow\"')"]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment