test.py 24.7 KB
Newer Older
Pedro TOME's avatar
Pedro TOME committed
1 2 3 4 5 6
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :

"""A few checks at the UTFVP database.
"""

André Anjos's avatar
André Anjos committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
import os
import numpy
import nose.tools
from nose.plugins.skip import SkipTest

from . import Database


# base directories where the UTFVP files sit
DATABASE_PATH = "/idiap/resource/database/UTFVP/data"


def sql3_available(test):
  """Decorator for detecting if the sql3 file is available"""

  from bob.io.base.test_utils import datafile
  from nose.plugins.skip import SkipTest
  import functools
25

André Anjos's avatar
André Anjos committed
26 27 28 29 30 31
  @functools.wraps(test)
  def wrapper(*args, **kwargs):
    dbfile = datafile("db.sql3", __name__, None)
    if os.path.exists(dbfile):
      return test(*args, **kwargs)
    else:
32
      raise SkipTest("The interface SQL file (%s) is not available; did you forget to run 'bob_dbmanage.py %s create' ?" % (dbfile, 'utfvp'))
André Anjos's avatar
André Anjos committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

  return wrapper


def db_available(test):
  """Decorator for detecting if the database files are available"""

  from bob.io.base.test_utils import datafile
  from nose.plugins.skip import SkipTest
  import functools

  @functools.wraps(test)
  def wrapper(*args, **kwargs):
    if os.path.exists(DATABASE_PATH):
      return test(*args, **kwargs)
    else:
      raise SkipTest("The database path (%s) is not available" % (DATABASE_PATH))

  return wrapper


@sql3_available
def test_clients():

  # test whether the correct number of clients is returned
  db = Database()

  nose.tools.eq_(len(db.groups()), 3)
61 62
  nose.tools.eq_(len(db.protocols()), 9)
  nose.tools.eq_(len(db.protocol_names()), 9)
André Anjos's avatar
André Anjos committed
63 64 65 66 67 68 69 70 71 72 73
  nose.tools.eq_(len(db.purposes()), 3)

  nose.tools.eq_(len(db.clients()), 360)
  nose.tools.eq_(len(db.clients(protocol='1vsall')), 360)
  nose.tools.eq_(len(db.clients(protocol='nom')), 360)
  nose.tools.eq_(len(db.clients(protocol='nomLeftRing')), 60)
  nose.tools.eq_(len(db.clients(protocol='nomLeftMiddle')), 60)
  nose.tools.eq_(len(db.clients(protocol='nomLeftIndex')), 60)
  nose.tools.eq_(len(db.clients(protocol='nomRightIndex')), 60)
  nose.tools.eq_(len(db.clients(protocol='nomRightMiddle')), 60)
  nose.tools.eq_(len(db.clients(protocol='nomRightRing')), 60)
74
  nose.tools.eq_(len(db.clients(protocol='full')), 360)
André Anjos's avatar
André Anjos committed
75 76 77 78 79 80 81 82 83 84

  nose.tools.eq_(len(db.client_ids()), 360)
  nose.tools.eq_(len(db.client_ids(protocol='1vsall')), 360)
  nose.tools.eq_(len(db.client_ids(protocol='nom')), 360)
  nose.tools.eq_(len(db.client_ids(protocol='nomLeftRing')), 60)
  nose.tools.eq_(len(db.client_ids(protocol='nomLeftMiddle')), 60)
  nose.tools.eq_(len(db.client_ids(protocol='nomLeftIndex')), 60)
  nose.tools.eq_(len(db.client_ids(protocol='nomRightIndex')), 60)
  nose.tools.eq_(len(db.client_ids(protocol='nomRightMiddle')), 60)
  nose.tools.eq_(len(db.client_ids(protocol='nomRightRing')), 60)
85
  nose.tools.eq_(len(db.client_ids(protocol='full')), 360)
André Anjos's avatar
André Anjos committed
86 87

  nose.tools.eq_(len(db.models()), 1900) #1300 + 300 + 50 * 6
88 89 90 91 92 93 94 95 96
  nose.tools.eq_(len(db.models(protocol='1vsall')), 1300) # (35 clients * 5 fingers per client * 4 samples per finger) + (25 clients * 6 fingers per client * 4 samples per finger)
  nose.tools.eq_(len(db.models(protocol='nom')), 300) # (1 model per finger * 6 fingers per client) * (18 "dev" clients + 32 "eval" clients)
  nose.tools.eq_(len(db.models(protocol='nomLeftRing')), 50) # 1 model per client * (18 "dev" clients + 32 "eval" clients)
  nose.tools.eq_(len(db.models(protocol='nomLeftMiddle')), 50) # 1 model per client * (18 "dev" clients + 32 "eval" clients)
  nose.tools.eq_(len(db.models(protocol='nomLeftIndex')), 50) # 1 model per client * (18 "dev" clients + 32 "eval" clients)
  nose.tools.eq_(len(db.models(protocol='nomRightIndex')), 50) # 1 model per client * (18 "dev" clients + 32 "eval" clients)
  nose.tools.eq_(len(db.models(protocol='nomRightMiddle')), 50) # 1 model per client * (18 "dev" clients + 32 "eval" clients)
  nose.tools.eq_(len(db.models(protocol='nomRightRing')), 50) # 1 model per client * (18 "dev" clients + 32 "eval" clients)
  nose.tools.eq_(len(db.models(protocol='full')), 1440) # 60 clients * 6 fingers per client * 4 samples per finger
André Anjos's avatar
André Anjos committed
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127

  nose.tools.eq_(len(db.model_ids()), 1900) #1300 + 300 + 50 * 6
  nose.tools.eq_(len(db.model_ids(protocol='1vsall')), 1300)
  nose.tools.eq_(len(db.model_ids(protocol='nom')), 300)
  nose.tools.eq_(len(db.model_ids(protocol='nom', groups='dev')), 108) #18 subjects *6 fingers
  nose.tools.eq_(len(db.model_ids(protocol='nom', groups='eval')), 192) #32 subjects *6 fingers

  nose.tools.eq_(len(db.model_ids(protocol='nomLeftRing')), 50)
  nose.tools.eq_(len(db.model_ids(protocol='nomLeftRing', groups='dev')), 18)
  nose.tools.eq_(len(db.model_ids(protocol='nomLeftRing', groups='eval')), 32)

  nose.tools.eq_(len(db.model_ids(protocol='nomLeftMiddle')), 50)
  nose.tools.eq_(len(db.model_ids(protocol='nomLeftMiddle', groups='dev')), 18)
  nose.tools.eq_(len(db.model_ids(protocol='nomLeftMiddle', groups='eval')), 32)

  nose.tools.eq_(len(db.model_ids(protocol='nomLeftIndex')), 50)
  nose.tools.eq_(len(db.model_ids(protocol='nomLeftIndex', groups='dev')), 18)
  nose.tools.eq_(len(db.model_ids(protocol='nomLeftIndex', groups='eval')), 32)

  nose.tools.eq_(len(db.model_ids(protocol='nomRightIndex')), 50)
  nose.tools.eq_(len(db.model_ids(protocol='nomRightIndex', groups='dev')), 18)
  nose.tools.eq_(len(db.model_ids(protocol='nomRightIndex', groups='eval')), 32)

  nose.tools.eq_(len(db.model_ids(protocol='nomRightMiddle')), 50)
  nose.tools.eq_(len(db.model_ids(protocol='nomRightMiddle', groups='dev')), 18)
  nose.tools.eq_(len(db.model_ids(protocol='nomRightMiddle', groups='eval')), 32)

  nose.tools.eq_(len(db.model_ids(protocol='nomRightRing')), 50)
  nose.tools.eq_(len(db.model_ids(protocol='nomRightRing', groups='dev')), 18)
  nose.tools.eq_(len(db.model_ids(protocol='nomRightRing', groups='eval')), 32)

128 129
  nose.tools.eq_(len(db.model_ids(protocol='full')), 1440)

André Anjos's avatar
André Anjos committed
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362

@sql3_available
def test_objects():

  # tests if the right number of File objects is returned
  db = Database()

  # Protocol '1vsall'
  nose.tools.eq_(len(db.objects(protocol='1vsall')), 1440) #1440 - 60 users * 6 fingers * 4 acq

  # World group
  nose.tools.eq_(len(db.objects(protocol='1vsall', groups='world')), 140) #35 fingers * 4 acq
  nose.tools.eq_(len(db.objects(protocol='1vsall', groups='world', purposes='train')), 140) #35 fingers * 4 acq

  # Dev group
  nose.tools.eq_(len(db.objects(protocol='1vsall', groups='dev')), 1300) #(1440-140)
  nose.tools.eq_(len(db.objects(protocol='1vsall', groups='dev', model_ids=('1_2_3',))), 1300)
  nose.tools.eq_(len(db.objects(protocol='1vsall', groups='dev', purposes='enroll')), 1300)
  nose.tools.eq_(len(db.objects(protocol='1vsall', groups='dev', model_ids=('1_2_3',), purposes='enroll')), 1)
  nose.tools.eq_(len(db.objects(protocol='1vsall', groups='dev', model_ids=('1_2_3',), purposes='probe')), 1299)
  nose.tools.eq_(len(db.objects(protocol='1vsall', groups='dev', purposes='probe', classes='impostor')), 1300)
  nose.tools.eq_(len(db.objects(protocol='1vsall', groups='dev', model_ids=('1_2_3',), purposes='probe', classes='client')), 3) # 4 acq - 1
  nose.tools.eq_(len(db.objects(protocol='1vsall', groups='dev', model_ids=('1_2_3',), purposes='probe', classes='impostor')), 1296) #1300 - 4 acq


@sql3_available
def test_objects_2():

  # tests if the right number of File objects is returned
  db = Database()


  #####################################################
  # Protocol 'nom'
  nose.tools.eq_(len(db.objects(protocol='nom')), 1440) #1440 - 60 subjects * 6 fingers * 4 acq

  # World group
  nose.tools.eq_(len(db.objects(protocol='nom', groups='world')), 240) #10 users * 6 fingers * 4 acq
  nose.tools.eq_(len(db.objects(protocol='nom', groups='world', purposes='train')), 240) #10 users * 6 fingers * 4 acq

  # Dev group
  nose.tools.eq_(len(db.objects(protocol='nom', groups='dev')), 432) #18 users * 6 fingers * 4 acq
  nose.tools.eq_(len(db.objects(protocol='nom', groups='dev', model_ids=('11_2',))), 218) #18 users * 6 fingers * 2 acq + 2
  nose.tools.eq_(len(db.objects(protocol='nom', groups='dev', purposes='enroll')), 216) #18 users * 6 fingers * 2 acq
  nose.tools.eq_(len(db.objects(protocol='nom', groups='dev', model_ids=('11_2',), purposes='enroll')), 2)
  nose.tools.eq_(len(db.objects(protocol='nom', groups='dev', model_ids=('11_2',), purposes='probe')), 216) #18 users * 6 fingers * 2 acq
  nose.tools.eq_(len(db.objects(protocol='nom', groups='dev', model_ids=('11_2',), purposes='probe', classes='client')), 2)
  nose.tools.eq_(len(db.objects(protocol='nom', groups='dev', model_ids=('11_2',), purposes='probe', classes='impostor')), 214) #384 - 2

  # Eval group
  nose.tools.eq_(len(db.objects(protocol='nom', groups='eval')), 768) #32 users * 6 fingers * 4 acq
  nose.tools.eq_(len(db.objects(protocol='nom', groups='eval', model_ids=('30_2',))), 386) #32 users * 6 fingers * 2 acq + 2
  nose.tools.eq_(len(db.objects(protocol='nom', groups='eval', purposes='enroll')), 384) #18 users * 6 fingers * 2 acq
  nose.tools.eq_(len(db.objects(protocol='nom', groups='eval', model_ids=('30_2',), purposes='enroll')), 2)
  nose.tools.eq_(len(db.objects(protocol='nom', groups='eval', model_ids=('30_2',), purposes='probe')), 384) #18 users * 6 fingers * 2 acq
  nose.tools.eq_(len(db.objects(protocol='nom', groups='eval', model_ids=('30_2',), purposes='probe', classes='client')), 2)
  nose.tools.eq_(len(db.objects(protocol='nom', groups='eval', model_ids=('30_2',), purposes='probe', classes='impostor')), 382) #384 - 2


@sql3_available
def test_objects_3():

  # tests if the right number of File objects is returned
  db = Database()

  #####################################################
  # Protocol 'nomLeftRing'
  nose.tools.eq_(len(db.objects(protocol='nomLeftRing')), 240) #1440 - 60 subjects * 1 fingers * 4 acq

  # World group
  nose.tools.eq_(len(db.objects(protocol='nomLeftRing', groups='world')), 40) #10 users * 1 fingers * 4 acq
  nose.tools.eq_(len(db.objects(protocol='nomLeftRing', groups='world', purposes='train')), 40) #10 users * 1 fingers * 4 acq

  # Dev group
  nose.tools.eq_(len(db.objects(protocol='nomLeftRing', groups='dev')), 72) #18 users * 1 fingers * 4 acq
  nose.tools.eq_(len(db.objects(protocol='nomLeftRing', groups='dev', model_ids=('11_1',))), 38) #18 users * 1 fingers * 2 acq + 2
  nose.tools.eq_(len(db.objects(protocol='nomLeftRing', groups='dev', purposes='enroll')), 36) #18 users * 1 fingers * 2 acq
  nose.tools.eq_(len(db.objects(protocol='nomLeftRing', groups='dev', model_ids=('11_1',), purposes='enroll')), 2)
  nose.tools.eq_(len(db.objects(protocol='nomLeftRing', groups='dev', model_ids=('11_1',), purposes='probe')), 36) #18 users * 1 fingers * 2 acq
  nose.tools.eq_(len(db.objects(protocol='nomLeftRing', groups='dev', model_ids=('11_1',), purposes='probe', classes='client')), 2)
  nose.tools.eq_(len(db.objects(protocol='nomLeftRing', groups='dev', model_ids=('11_1',), purposes='probe', classes='impostor')), 34) #36 - 2

  # Eval group
  nose.tools.eq_(len(db.objects(protocol='nomLeftRing', groups='eval')), 128) #32 users * 1 fingers * 4 acq
  nose.tools.eq_(len(db.objects(protocol='nomLeftRing', groups='eval', model_ids=('30_1',))), 66) #32 users * 1 fingers * 2 acq + 2
  nose.tools.eq_(len(db.objects(protocol='nomLeftRing', groups='eval', purposes='enroll')), 64) #32 users * 1 fingers * 2 acq
  nose.tools.eq_(len(db.objects(protocol='nomLeftRing', groups='eval', model_ids=('30_1',), purposes='enroll')), 2)
  nose.tools.eq_(len(db.objects(protocol='nomLeftRing', groups='eval', model_ids=('30_1',), purposes='probe')), 64) #32 users * 1 fingers * 2 acq
  nose.tools.eq_(len(db.objects(protocol='nomLeftRing', groups='eval', model_ids=('30_1',), purposes='probe', classes='client')), 2)
  nose.tools.eq_(len(db.objects(protocol='nomLeftRing', groups='eval', model_ids=('30_1',), purposes='probe', classes='impostor')), 62) #64 - 2


  #####################################################
  # Protocol 'nomLeftMiddle'
  nose.tools.eq_(len(db.objects(protocol='nomLeftMiddle')), 240) #1440 - 60 subjects * 1 fingers * 4 acq

  # World group
  nose.tools.eq_(len(db.objects(protocol='nomLeftMiddle', groups='world')), 40) #10 users * 1 fingers * 4 acq
  nose.tools.eq_(len(db.objects(protocol='nomLeftMiddle', groups='world', purposes='train')), 40) #10 users * 1 fingers * 4 acq

  # Dev group
  nose.tools.eq_(len(db.objects(protocol='nomLeftMiddle', groups='dev')), 72) #18 users * 1 fingers * 4 acq
  nose.tools.eq_(len(db.objects(protocol='nomLeftMiddle', groups='dev', model_ids=('11_2',))), 38) #18 users * 1 fingers * 2 acq + 2
  nose.tools.eq_(len(db.objects(protocol='nomLeftMiddle', groups='dev', purposes='enroll')), 36) #18 users * 1 fingers * 2 acq
  nose.tools.eq_(len(db.objects(protocol='nomLeftMiddle', groups='dev', model_ids=('11_2',), purposes='enroll')), 2)
  nose.tools.eq_(len(db.objects(protocol='nomLeftMiddle', groups='dev', model_ids=('11_2',), purposes='probe')), 36) #18 users * 1 fingers * 2 acq
  nose.tools.eq_(len(db.objects(protocol='nomLeftMiddle', groups='dev', model_ids=('11_2',), purposes='probe', classes='client')), 2)
  nose.tools.eq_(len(db.objects(protocol='nomLeftMiddle', groups='dev', model_ids=('11_2',), purposes='probe', classes='impostor')), 34) #36 - 2

  # Eval group
  nose.tools.eq_(len(db.objects(protocol='nomLeftMiddle', groups='eval')), 128) #32 users * 1 fingers * 4 acq
  nose.tools.eq_(len(db.objects(protocol='nomLeftMiddle', groups='eval', model_ids=('30_2',))), 66) #32 users * 1 fingers * 2 acq + 2
  nose.tools.eq_(len(db.objects(protocol='nomLeftMiddle', groups='eval', purposes='enroll')), 64) #32 users * 1 fingers * 2 acq
  nose.tools.eq_(len(db.objects(protocol='nomLeftMiddle', groups='eval', model_ids=('30_2',), purposes='enroll')), 2)
  nose.tools.eq_(len(db.objects(protocol='nomLeftMiddle', groups='eval', model_ids=('30_2',), purposes='probe')), 64) #32 users * 1 fingers * 2 acq
  nose.tools.eq_(len(db.objects(protocol='nomLeftMiddle', groups='eval', model_ids=('30_2',), purposes='probe', classes='client')), 2)
  nose.tools.eq_(len(db.objects(protocol='nomLeftMiddle', groups='eval', model_ids=('30_2',), purposes='probe', classes='impostor')), 62) #64 - 2


  #####################################################
  # Protocol 'nomLeftIndex'
  nose.tools.eq_(len(db.objects(protocol='nomLeftIndex')), 240) #1440 - 60 subjects * 1 fingers * 4 acq

  # World group
  nose.tools.eq_(len(db.objects(protocol='nomLeftIndex', groups='world')), 40) #10 users * 1 fingers * 4 acq
  nose.tools.eq_(len(db.objects(protocol='nomLeftIndex', groups='world', purposes='train')), 40) #10 users * 1 fingers * 4 acq

  # Dev group
  nose.tools.eq_(len(db.objects(protocol='nomLeftIndex', groups='dev')), 72) #18 users * 1 fingers * 4 acq
  nose.tools.eq_(len(db.objects(protocol='nomLeftIndex', groups='dev', model_ids=('11_3',))), 38) #18 users * 1 fingers * 2 acq + 2
  nose.tools.eq_(len(db.objects(protocol='nomLeftIndex', groups='dev', purposes='enroll')), 36) #18 users * 1 fingers * 2 acq
  nose.tools.eq_(len(db.objects(protocol='nomLeftIndex', groups='dev', model_ids=('11_3',), purposes='enroll')), 2)
  nose.tools.eq_(len(db.objects(protocol='nomLeftIndex', groups='dev', model_ids=('11_3',), purposes='probe')), 36) #18 users * 1 fingers * 2 acq
  nose.tools.eq_(len(db.objects(protocol='nomLeftIndex', groups='dev', model_ids=('11_3',), purposes='probe', classes='client')), 2)
  nose.tools.eq_(len(db.objects(protocol='nomLeftIndex', groups='dev', model_ids=('11_3',), purposes='probe', classes='impostor')), 34) #36 - 2

  # Eval group
  nose.tools.eq_(len(db.objects(protocol='nomLeftIndex', groups='eval')), 128) #32 users * 1 fingers * 4 acq
  nose.tools.eq_(len(db.objects(protocol='nomLeftIndex', groups='eval', model_ids=('30_3',))), 66) #32 users * 1 fingers * 2 acq + 2
  nose.tools.eq_(len(db.objects(protocol='nomLeftIndex', groups='eval', purposes='enroll')), 64) #32 users * 1 fingers * 2 acq
  nose.tools.eq_(len(db.objects(protocol='nomLeftIndex', groups='eval', model_ids=('30_3',), purposes='enroll')), 2)
  nose.tools.eq_(len(db.objects(protocol='nomLeftIndex', groups='eval', model_ids=('30_3',), purposes='probe')), 64) #32 users * 1 fingers * 2 acq
  nose.tools.eq_(len(db.objects(protocol='nomLeftIndex', groups='eval', model_ids=('30_3',), purposes='probe', classes='client')), 2)
  nose.tools.eq_(len(db.objects(protocol='nomLeftIndex', groups='eval', model_ids=('30_3',), purposes='probe', classes='impostor')), 62) #64 - 2


@sql3_available
def test_objects_4():

  # tests if the right number of File objects is returned
  db = Database()

  #####################################################
  # Protocol 'nomRightIndex'
  nose.tools.eq_(len(db.objects(protocol='nomRightIndex')), 240) #1440 - 60 subjects * 1 fingers * 4 acq

  # World group
  nose.tools.eq_(len(db.objects(protocol='nomRightIndex', groups='world')), 40) #10 users * 1 fingers * 4 acq
  nose.tools.eq_(len(db.objects(protocol='nomRightIndex', groups='world', purposes='train')), 40) #10 users * 1 fingers * 4 acq

  # Dev group
  nose.tools.eq_(len(db.objects(protocol='nomRightIndex', groups='dev')), 72) #18 users * 1 fingers * 4 acq
  nose.tools.eq_(len(db.objects(protocol='nomRightIndex', groups='dev', model_ids=('11_4',))), 38) #18 users * 1 fingers * 2 acq + 2
  nose.tools.eq_(len(db.objects(protocol='nomRightIndex', groups='dev', purposes='enroll')), 36) #18 users * 1 fingers * 2 acq
  nose.tools.eq_(len(db.objects(protocol='nomRightIndex', groups='dev', model_ids=('11_4',), purposes='enroll')), 2)
  nose.tools.eq_(len(db.objects(protocol='nomRightIndex', groups='dev', model_ids=('11_4',), purposes='probe')), 36) #18 users * 1 fingers * 2 acq
  nose.tools.eq_(len(db.objects(protocol='nomRightIndex', groups='dev', model_ids=('11_4',), purposes='probe', classes='client')), 2)
  nose.tools.eq_(len(db.objects(protocol='nomRightIndex', groups='dev', model_ids=('11_4',), purposes='probe', classes='impostor')), 34) #36 - 2

  # Eval group
  nose.tools.eq_(len(db.objects(protocol='nomRightIndex', groups='eval')), 128) #32 users * 1 fingers * 4 acq
  nose.tools.eq_(len(db.objects(protocol='nomRightIndex', groups='eval', model_ids=('30_4',))), 66) #32 users * 1 fingers * 2 acq + 2
  nose.tools.eq_(len(db.objects(protocol='nomRightIndex', groups='eval', purposes='enroll')), 64) #32 users * 1 fingers * 2 acq
  nose.tools.eq_(len(db.objects(protocol='nomRightIndex', groups='eval', model_ids=('30_4',), purposes='enroll')), 2)
  nose.tools.eq_(len(db.objects(protocol='nomRightIndex', groups='eval', model_ids=('30_4',), purposes='probe')), 64) #32 users * 1 fingers * 2 acq
  nose.tools.eq_(len(db.objects(protocol='nomRightIndex', groups='eval', model_ids=('30_4',), purposes='probe', classes='client')), 2)
  nose.tools.eq_(len(db.objects(protocol='nomRightIndex', groups='eval', model_ids=('30_4',), purposes='probe', classes='impostor')), 62) #64 - 2


  #####################################################
  # Protocol 'nomRightMiddle'
  nose.tools.eq_(len(db.objects(protocol='nomRightMiddle')), 240) #1440 - 60 subjects * 1 fingers * 4 acq

  # World group
  nose.tools.eq_(len(db.objects(protocol='nomRightMiddle', groups='world')), 40) #10 users * 1 fingers * 4 acq
  nose.tools.eq_(len(db.objects(protocol='nomRightMiddle', groups='world', purposes='train')), 40) #10 users * 1 fingers * 4 acq

  # Dev group
  nose.tools.eq_(len(db.objects(protocol='nomRightMiddle', groups='dev')), 72) #18 users * 1 fingers * 4 acq
  nose.tools.eq_(len(db.objects(protocol='nomRightMiddle', groups='dev', model_ids=('11_5',))), 38) #18 users * 1 fingers * 2 acq + 2
  nose.tools.eq_(len(db.objects(protocol='nomRightMiddle', groups='dev', purposes='enroll')), 36) #18 users * 1 fingers * 2 acq
  nose.tools.eq_(len(db.objects(protocol='nomRightMiddle', groups='dev', model_ids=('11_5',), purposes='enroll')), 2)
  nose.tools.eq_(len(db.objects(protocol='nomRightMiddle', groups='dev', model_ids=('11_5',), purposes='probe')), 36) #18 users * 1 fingers * 2 acq
  nose.tools.eq_(len(db.objects(protocol='nomRightMiddle', groups='dev', model_ids=('11_5',), purposes='probe', classes='client')), 2)
  nose.tools.eq_(len(db.objects(protocol='nomRightMiddle', groups='dev', model_ids=('11_5',), purposes='probe', classes='impostor')), 34) #36 - 2

  # Eval group
  nose.tools.eq_(len(db.objects(protocol='nomRightMiddle', groups='eval')), 128) #32 users * 1 fingers * 4 acq
  nose.tools.eq_(len(db.objects(protocol='nomRightMiddle', groups='eval', model_ids=('30_5',))), 66) #32 users * 1 fingers * 2 acq + 2
  nose.tools.eq_(len(db.objects(protocol='nomRightMiddle', groups='eval', purposes='enroll')), 64) #32 users * 1 fingers * 2 acq
  nose.tools.eq_(len(db.objects(protocol='nomRightMiddle', groups='eval', model_ids=('30_5',), purposes='enroll')), 2)
  nose.tools.eq_(len(db.objects(protocol='nomRightMiddle', groups='eval', model_ids=('30_5',), purposes='probe')), 64) #32 users * 1 fingers * 2 acq
  nose.tools.eq_(len(db.objects(protocol='nomRightMiddle', groups='eval', model_ids=('30_5',), purposes='probe', classes='client')), 2)
  nose.tools.eq_(len(db.objects(protocol='nomRightMiddle', groups='eval', model_ids=('30_5',), purposes='probe', classes='impostor')), 62) #64 - 2


  #####################################################
  # Protocol 'nomRightRing'
  nose.tools.eq_(len(db.objects(protocol='nomRightRing')), 240) #1440 - 60 subjects * 1 fingers * 4 acq

  # World group
  nose.tools.eq_(len(db.objects(protocol='nomRightRing', groups='world')), 40) #10 users * 1 fingers * 4 acq
  nose.tools.eq_(len(db.objects(protocol='nomRightRing', groups='world', purposes='train')), 40) #10 users * 1 fingers * 4 acq

  # Dev group
  nose.tools.eq_(len(db.objects(protocol='nomRightRing', groups='dev')), 72) #18 users * 1 fingers * 4 acq
  nose.tools.eq_(len(db.objects(protocol='nomRightRing', groups='dev', model_ids=('11_6',))), 38) #18 users * 1 fingers * 2 acq + 2
  nose.tools.eq_(len(db.objects(protocol='nomRightRing', groups='dev', purposes='enroll')), 36) #18 users * 1 fingers * 2 acq
  nose.tools.eq_(len(db.objects(protocol='nomRightRing', groups='dev', model_ids=('11_6',), purposes='enroll')), 2)
  nose.tools.eq_(len(db.objects(protocol='nomRightRing', groups='dev', model_ids=('11_6',), purposes='probe')), 36) #18 users * 1 fingers * 2 acq
  nose.tools.eq_(len(db.objects(protocol='nomRightRing', groups='dev', model_ids=('11_6',), purposes='probe', classes='client')), 2)
  nose.tools.eq_(len(db.objects(protocol='nomRightRing', groups='dev', model_ids=('11_6',), purposes='probe', classes='impostor')), 34) #36 - 2

  # Eval group
  nose.tools.eq_(len(db.objects(protocol='nomRightRing', groups='eval')), 128) #32 users * 1 fingers * 4 acq
  nose.tools.eq_(len(db.objects(protocol='nomRightRing', groups='eval', model_ids=('30_6',))), 66) #32 users * 1 fingers * 2 acq + 2
  nose.tools.eq_(len(db.objects(protocol='nomRightRing', groups='eval', purposes='enroll')), 64) #32 users * 1 fingers * 2 acq
  nose.tools.eq_(len(db.objects(protocol='nomRightRing', groups='eval', model_ids=('30_6',), purposes='enroll')), 2)
  nose.tools.eq_(len(db.objects(protocol='nomRightRing', groups='eval', model_ids=('30_6',), purposes='probe')), 64) #32 users * 1 fingers * 2 acq
  nose.tools.eq_(len(db.objects(protocol='nomRightRing', groups='eval', model_ids=('30_6',), purposes='probe', classes='client')), 2)
  nose.tools.eq_(len(db.objects(protocol='nomRightRing', groups='eval', model_ids=('30_6',), purposes='probe', classes='impostor')), 62) #64 - 2


363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
@sql3_available
def test_objects_5():

  # tests if the right number of File objects is returned
  db = Database()

  # Protocol 'full'
  nose.tools.eq_(len(db.objects(protocol='full')), 1440) # 60 clients * 6 fingers per client * 4 samples per finger

  # Dev group
  nose.tools.eq_(len(db.objects(protocol='full', groups='dev')), 1440) 
  nose.tools.eq_(len(db.objects(protocol='full', groups='dev', model_ids=('1_2_3',))), 1440)
  nose.tools.eq_(len(db.objects(protocol='full', groups='dev', purposes='enroll')), 1440)
  nose.tools.eq_(len(db.objects(protocol='full', groups='dev', model_ids=('1_2_3',), purposes='enroll')), 1)
  nose.tools.eq_(len(db.objects(protocol='full', groups='dev', model_ids=('1_2_3',), purposes='probe')), 1439)
  nose.tools.eq_(len(db.objects(protocol='full', groups='dev', purposes='probe', classes='impostor')), 1440)
  nose.tools.eq_(len(db.objects(protocol='full', groups='dev', model_ids=('1_2_3',), purposes='probe', classes='client')), 3) # 3 genuine comparisons per sample
  nose.tools.eq_(len(db.objects(protocol='full', groups='dev', model_ids=('1_2_3',), purposes='probe', classes='impostor')), 1436) # 1440 total samples - 4 genuine samples


André Anjos's avatar
André Anjos committed
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
@sql3_available
def test_driver_api():

  from bob.db.base.script.dbmanage import main

  nose.tools.eq_(main('utfvp dumplist --self-test'.split()), 0)
  nose.tools.eq_(main('utfvp dumplist --protocol=1vsall --class=client --group=dev --purpose=enroll --model=1_2_3 --self-test'.split()), 0)
  nose.tools.eq_(main('utfvp checkfiles --self-test'.split()), 0)


@sql3_available
@db_available
def test_load():

  db = Database()

  for f in db.objects():

    # loads an image from the database
    image = f.load(DATABASE_PATH)
    assert isinstance(image, numpy.ndarray)
    nose.tools.eq_(len(image.shape), 2) #it is a 2D array
    nose.tools.eq_(image.dtype, numpy.uint8)
406