test_scripts.py 2.13 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
def test_compute_perf():
André Anjos's avatar
André Anjos committed
29

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

André Anjos's avatar
André Anjos committed
34
  from .script.compute_perf import main
35 36
  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
37

38
def test_eval_threshold():
André Anjos's avatar
André Anjos committed
39

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

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

47
def test_apply_threshold():
André Anjos's avatar
André Anjos committed
48

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

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

56
def test_compute_perf_5col():
André Anjos's avatar
André Anjos committed
57

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

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

66
def test_compute_cmc():
André Anjos's avatar
André Anjos committed
67

68 69 70
  # sanity checks
  assert os.path.exists(SCORES_4COL_CMC)
  assert os.path.exists(SCORES_5COL_CMC)
André Anjos's avatar
André Anjos committed
71

André Anjos's avatar
André Anjos committed
72
  from .script.plot_cmc import main
73 74
  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)
75
  nose.tools.eq_(main(['--self-test', '--score-file', SCORES_4COL_CMC, '--rank', '1']), 0)