Skip to content
Snippets Groups Projects
Verified Commit 5d0418bd authored by Yannick DAYER's avatar Yannick DAYER
Browse files

test(database): split the creation and the loading

Test the Database Interface creation and the Sample loading separately
to make the reason for skipping the tests more obvious.
parent 3f8ca2aa
No related branches found
No related tags found
1 merge request!146fix: harmonize all the Database Interface classes.
Pipeline #92852 passed
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# Thu May 24 10:41:42 CEST 2012
"""Test all the Database Interfaces for general function and sample loading if possible.
When the data samples are not available (e.g. on the CI runners), the ``loading`` tests
are skipped.
"""
from unittest import SkipTest
......@@ -9,7 +13,8 @@ import numpy as np
import bob.bio.base
def test_replay_attack():
def test_replay_attack_protocol():
"""Test the replay-attack database interface without loading samples."""
database = bob.bio.base.load_resource(
"replay-attack",
"database",
......@@ -42,6 +47,15 @@ def test_replay_attack():
== 1000
)
def test_replay_attack_loading():
"""Test the loading of samples of the replay-attack database."""
database = bob.bio.base.load_resource(
"replay-attack",
"database",
preferred_package="bob.pad.face",
package_prefix="bob.pad.",
)
sample = database.sort(database.samples())[0]
try:
annot = dict(sample.annotations["0"])
......@@ -61,7 +75,8 @@ def test_replay_attack():
raise SkipTest(e)
def test_replay_mobile():
def test_replay_mobile_protocol():
"""Test the replay-mobile database interface without loading samples."""
database = bob.bio.base.load_resource(
"replay-mobile",
"database",
......@@ -122,6 +137,18 @@ def test_replay_mobile():
"bottomright": [1111, 495],
}, annot
def test_replay_mobile_loading():
"""Test the loading of samples of the replay-mobile database."""
database = bob.bio.base.load_resource(
"replay-mobile",
"database",
preferred_package="bob.pad.face",
package_prefix="bob.pad.",
)
all_samples = database.sort(database.samples())
sample = all_samples[0]
sample2 = [s for s in all_samples if not s.should_flip][0]
try:
assert sample.data.shape == (20, 3, 1280, 720), sample.data.shape
np.testing.assert_equal(sample.data[0][:, 0, 0], [13, 13, 13])
......@@ -132,7 +159,8 @@ def test_replay_mobile():
# Test the mask_attack database
def test_mask_attack():
def test_mask_attack_protocol():
"""Test the mask-attack database interface without loading samples."""
mask_attack = bob.bio.base.load_resource(
"mask-attack",
"database",
......@@ -171,6 +199,16 @@ def test_mask_attack():
assert len(mask_attack.samples(groups=["dev"], purposes="attack")) == 25
assert len(mask_attack.samples(groups=["eval"], purposes="attack")) == 25
def test_mask_attack_loading():
"""Test the loading of samples of the mask-attack database."""
mask_attack = bob.bio.base.load_resource(
"mask-attack",
"database",
preferred_package="bob.pad.face",
package_prefix="bob.pad.",
)
sample = mask_attack.samples()[0]
try:
assert sample.data.shape == (20, 3, 480, 640)
......@@ -186,7 +224,8 @@ def test_mask_attack():
raise SkipTest(e)
def test_casia_fasd():
def test_casia_fasd_protocols():
"""Test the casia-fasd database interface without loading samples."""
casia_fasd = bob.bio.base.load_resource(
"casia-fasd",
"database",
......@@ -201,6 +240,16 @@ def test_casia_fasd():
assert len(casia_fasd.samples(groups="train")) == 180
assert len(casia_fasd.samples(groups="dev")) == 60
assert len(casia_fasd.samples(groups="eval")) == 360
def test_casia_fasd_loading():
"""Test the loading of samples of the casia-fasd database."""
casia_fasd = bob.bio.base.load_resource(
"casia-fasd",
"database",
preferred_package="bob.pad.face",
package_prefix="bob.pad.",
)
sample = casia_fasd.samples()[0]
try:
assert sample.data.shape == (20, 3, 480, 640)
......@@ -209,7 +258,12 @@ def test_casia_fasd():
raise SkipTest(e)
def test_casia_surf():
def test_casia_surf_protocol():
"""Test the casia-surf database interface without loading samples.
As the protocol definition files are shipped with the data, this test will also be
skipped when the original directory is not set.
"""
try:
casia_surf = bob.bio.base.load_resource(
"casia-surf",
......@@ -225,6 +279,19 @@ def test_casia_surf():
assert len(casia_surf.samples(groups="train")) == 29266
assert len(casia_surf.samples(groups="dev")) == 9608
assert len(casia_surf.samples(groups="eval")) == 57710
except FileNotFoundError as e:
raise SkipTest(e)
def test_casia_surf_loading():
"""Test the loading of samples of the casia-surf database."""
try:
casia_surf = bob.bio.base.load_resource(
"casia-surf",
"database",
preferred_package="bob.pad.face",
package_prefix="bob.pad.",
)
sample = casia_surf.samples()[0]
assert sample.data.shape == (1, 3, 279, 279)
np.testing.assert_equal(sample.data[0][:, 0, 0], [0, 0, 0])
......@@ -234,7 +301,8 @@ def test_casia_surf():
raise SkipTest(e)
def test_swan():
def test_swan_protocol():
"""Test the swan database interface without loading samples."""
database = bob.bio.base.load_resource(
"swan",
"database",
......@@ -264,6 +332,15 @@ def test_swan():
== 2502
)
def test_swan_loading():
"""Test the loading of samples of the swan database."""
database = bob.bio.base.load_resource(
"swan",
"database",
preferred_package="bob.pad.face",
package_prefix="bob.pad.",
)
sample = database.sort(database.samples())[0]
try:
annot = dict(sample.annotations["0"])
......@@ -283,7 +360,8 @@ def test_swan():
raise SkipTest(e)
def test_oulu_npu():
def test_oulu_npu_protocol():
"""Test the oulu-npu database interface without loading samples."""
database = bob.bio.base.load_resource(
"oulu-npu",
"database",
......@@ -327,6 +405,16 @@ def test_oulu_npu():
== 960 + 720 + 480
)
def test_oulu_npu_loading():
"""Test the loading of samples of the oulu-npu database."""
database = bob.bio.base.load_resource(
"oulu-npu",
"database",
preferred_package="bob.pad.face",
package_prefix="bob.pad.",
)
sample = database.sort(database.samples())[0]
try:
annot = dict(sample.annotations["0"])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment