Skip to content
Snippets Groups Projects

Propagated the option --allow-missing-files .....

Merged Tiago de Freitas Pereira requested to merge issue-96 into master
Files
2
@@ -119,45 +119,83 @@ def test_io_vstack():
@@ -119,45 +119,83 @@ def test_io_vstack():
def reader_wrong_size(path):
def reader_wrong_size(path):
return numpy.arange(2 * path).reshape(2, path)
return numpy.arange(2 * path).reshape(2, path)
# test C and F readers
# when same_size is False
numpy.all(bob.bio.base.vstack_features(reader_different_size_C,
for reader in [
paths, False) ==
reader_different_size_C,
oracle(reader_different_size_C, paths))
reader_different_size_F,
numpy.all(bob.bio.base.vstack_features(reader_different_size_F,
reader_same_size_C,
paths, False) ==
reader_same_size_F,
oracle(reader_different_size_F, paths))
reader_different_size_C2,
reader_different_size_F2,
numpy.all(bob.bio.base.vstack_features(reader_same_size_C, paths, False) ==
reader_same_size_C2,
oracle(reader_same_size_C, paths))
reader_same_size_F2,
numpy.all(bob.bio.base.vstack_features(reader_same_size_F, paths, False) ==
]:
oracle(reader_same_size_F, paths))
numpy.all(bob.bio.base.vstack_features(reader, paths) ==
oracle(reader, paths))
numpy.all(bob.bio.base.vstack_features(reader_same_size_C, paths, True) ==
oracle(reader_same_size_C, paths))
# when same_size is True
numpy.all(bob.bio.base.vstack_features(reader_same_size_F, paths, True) ==
for reader in [
oracle(reader_same_size_F, paths))
reader_same_size_C,
reader_same_size_F,
# test 3 dimensional readers
reader_same_size_C2,
numpy.all(bob.bio.base.vstack_features(reader_different_size_C2,
reader_same_size_F2,
paths, False) ==
]:
oracle(reader_different_size_C2, paths))
numpy.all(bob.bio.base.vstack_features(reader, paths, True) ==
numpy.all(bob.bio.base.vstack_features(reader_different_size_F2,
oracle(reader, paths))
paths, False) ==
oracle(reader_different_size_F2, paths))
numpy.all(bob.bio.base.vstack_features(reader_same_size_C2, paths, False) ==
oracle(reader_same_size_C2, paths))
numpy.all(bob.bio.base.vstack_features(reader_same_size_F2, paths, False) ==
oracle(reader_same_size_F2, paths))
numpy.all(bob.bio.base.vstack_features(reader_same_size_C2, paths, True) ==
oracle(reader_same_size_C2, paths))
numpy.all(bob.bio.base.vstack_features(reader_same_size_F2, paths, True) ==
oracle(reader_same_size_F2, paths))
with nose.tools.assert_raises(AssertionError):
with nose.tools.assert_raises(AssertionError):
bob.bio.base.vstack_features(reader_wrong_size, paths)
bob.bio.base.vstack_features(reader_wrong_size, paths)
 
# test actual files
 
paths = [bob.io.base.test_utils.temporary_filename(),
 
bob.io.base.test_utils.temporary_filename(),
 
bob.io.base.test_utils.temporary_filename()]
 
try:
 
# try different readers:
 
for reader in [
 
reader_different_size_C,
 
reader_different_size_F,
 
reader_same_size_C,
 
reader_same_size_F,
 
reader_different_size_C2,
 
reader_different_size_F2,
 
reader_same_size_C2,
 
reader_same_size_F2,
 
]:
 
# save some data in files
 
for i, path in enumerate(paths):
 
bob.bio.base.save(reader(i + 1), path)
 
# test when all data is present
 
reference = oracle(bob.bio.base.load, paths)
 
numpy.all(bob.bio.base.vstack_features(bob.bio.base.load, paths) ==
 
reference)
 
# delete the first one
 
os.remove(paths[0])
 
reference = oracle(bob.bio.base.load, paths[1:])
 
target = bob.bio.base.vstack_features(bob.bio.base.load, paths, False,
 
True)
 
numpy.all(target == reference)
 
# save back first one and delete second one
 
bob.bio.base.save(reader(1), paths[0])
 
os.remove(paths[1])
 
reference = oracle(bob.bio.base.load, paths[:1] + paths[2:])
 
target = bob.bio.base.vstack_features(bob.bio.base.load, paths, False,
 
True)
 
numpy.all(target == reference)
 
# Check if RuntimeError is raised when one of the files is missing and
 
# allow_missing_files if False
 
with nose.tools.assert_raises(RuntimeError):
 
bob.bio.base.vstack_features(bob.bio.base.load, paths)
 
# Check if ValueError is raised.
 
with nose.tools.assert_raises(ValueError):
 
bob.bio.base.vstack_features(bob.bio.base.load, paths, True, True)
 
finally:
 
try:
 
for path in paths:
 
os.remove(path)
 
except Exception:
 
pass
 
def test_sampling():
def test_sampling():
# test selection of elements
# test selection of elements
Loading