test_scripts.py 2.23 KB
Newer Older
André Anjos's avatar
André Anjos committed
1 2 3 4 5 6 7
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# Andre Anjos <andre.anjos@idiap.ch>
# Tue 21 Aug 2012 12:14:43 CEST
#
# Copyright (C) 2011-2013 Idiap Research Institute, Martigny, Switzerland

André Anjos's avatar
André Anjos committed
8
"""Script tests for bob.measure
André Anjos's avatar
André Anjos committed
9 10 11
"""

import os
12
import nose.tools
André Anjos's avatar
André Anjos committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
import pkg_resources

def F(f):
  """Returns the test file on the "data" subdirectory"""
  return pkg_resources.resource_filename(__name__, os.path.join('data', f))

DEV_SCORES = F('dev-4col.txt')
TEST_SCORES = F('test-4col.txt')

DEV_SCORES_5COL = F('dev-5col.txt')
TEST_SCORES_5COL = F('test-5col.txt')

SCORES_4COL_CMC = F('scores-cmc-4col.txt')
SCORES_5COL_CMC = F('scores-cmc-5col.txt')

28 29
SCORES_4COL_CMC_OS = F('scores-cmc-4col-open-set.txt')

30
def test_compute_perf():
André Anjos's avatar
André Anjos committed
31

32 33 34
  # sanity checks
  assert os.path.exists(DEV_SCORES)
  assert os.path.exists(TEST_SCORES)
André Anjos's avatar
André Anjos committed
35

André Anjos's avatar
André Anjos committed
36
  from .script.compute_perf import main
37 38
  cmdline = '--devel=%s --test=%s --self-test' % (DEV_SCORES, TEST_SCORES)
  nose.tools.eq_(main(cmdline.split()), 0)
André Anjos's avatar
André Anjos committed
39

40
def test_eval_threshold():
André Anjos's avatar
André Anjos committed
41

42 43
  # sanity checks
  assert os.path.exists(DEV_SCORES)
André Anjos's avatar
André Anjos committed
44

André Anjos's avatar
André Anjos committed
45
  from .script.eval_threshold import main
46 47
  cmdline = '--scores=%s --self-test' % (DEV_SCORES,)
  nose.tools.eq_(main(cmdline.split()), 0)
André Anjos's avatar
André Anjos committed
48

49
def test_apply_threshold():
André Anjos's avatar
André Anjos committed
50

51 52
  # sanity checks
  assert os.path.exists(TEST_SCORES)
André Anjos's avatar
André Anjos committed
53

André Anjos's avatar
André Anjos committed
54
  from .script.apply_threshold import main
55 56
  cmdline = '--scores=%s --self-test' % (TEST_SCORES,)
  nose.tools.eq_(main(cmdline.split()), 0)
André Anjos's avatar
André Anjos committed
57

58
def test_compute_perf_5col():
André Anjos's avatar
André Anjos committed
59

60 61 62
  # sanity checks
  assert os.path.exists(DEV_SCORES_5COL)
  assert os.path.exists(TEST_SCORES_5COL)
André Anjos's avatar
André Anjos committed
63

André Anjos's avatar
André Anjos committed
64
  from .script.compute_perf import main
André Anjos's avatar
André Anjos committed
65
  cmdline = '--devel=%s --test=%s --parser=bob.measure.load.split_five_column --self-test' % (DEV_SCORES_5COL, TEST_SCORES_5COL)
66
  nose.tools.eq_(main(cmdline.split()), 0)
André Anjos's avatar
André Anjos committed
67

68
def test_compute_cmc():
André Anjos's avatar
André Anjos committed
69

70 71 72
  # sanity checks
  assert os.path.exists(SCORES_4COL_CMC)
  assert os.path.exists(SCORES_5COL_CMC)
73
  assert os.path.exists(SCORES_4COL_CMC_OS)
André Anjos's avatar
André Anjos committed
74

André Anjos's avatar
André Anjos committed
75
  from .script.plot_cmc import main
76 77
  nose.tools.eq_(main(['--self-test', '--score-file', SCORES_4COL_CMC, '--log-x-scale']), 0)
  nose.tools.eq_(main(['--self-test', '--score-file', SCORES_5COL_CMC, '--parser', '5column']), 0)
78
  nose.tools.eq_(main(['--self-test', '--score-file', SCORES_4COL_CMC_OS, '--rank', '1']), 0)