test_scripts.py 2.49 KB
Newer Older
André Anjos's avatar
André Anjos committed
1 2 3 4
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# Tue 21 Aug 2012 12:14:43 CEST

André Anjos's avatar
André Anjos committed
5
"""Script tests for bob.measure
André Anjos's avatar
André Anjos committed
6 7 8
"""

import os
9 10
import tempfile

11
import nose.tools
André Anjos's avatar
André Anjos committed
12 13
import pkg_resources

14

André Anjos's avatar
André Anjos committed
15 16 17 18 19 20 21 22 23 24 25 26 27
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

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

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

37 38 39 40 41 42 43 44
  tmp_output = tempfile.NamedTemporaryFile(prefix=__name__, suffix='.pdf')

  cmdline = [
      DEV_SCORES,
      TEST_SCORES,
      '--output=' + tmp_output.name,
      ]

André Anjos's avatar
André Anjos committed
45
  from .script.compute_perf import main
46 47
  nose.tools.eq_(main(cmdline), 0)

André Anjos's avatar
André Anjos committed
48

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

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

54 55
  cmdline = [DEV_SCORES]

André Anjos's avatar
André Anjos committed
56
  from .script.eval_threshold import main
57 58
  nose.tools.eq_(main(cmdline), 0)

André Anjos's avatar
André Anjos committed
59

60
def test_apply_threshold():
André Anjos's avatar
André Anjos committed
61

62 63
  # sanity checks
  assert os.path.exists(TEST_SCORES)
André Anjos's avatar
André Anjos committed
64

65 66 67 68 69
  cmdline = [
      '0.5',
      TEST_SCORES,
      ]

André Anjos's avatar
André Anjos committed
70
  from .script.apply_threshold import main
71 72
  nose.tools.eq_(main(cmdline), 0)

André Anjos's avatar
André Anjos committed
73

74
def test_compute_perf_5col():
André Anjos's avatar
André Anjos committed
75

76 77 78
  # sanity checks
  assert os.path.exists(DEV_SCORES_5COL)
  assert os.path.exists(TEST_SCORES_5COL)
André Anjos's avatar
André Anjos committed
79

80 81 82 83 84 85 86 87
  tmp_output = tempfile.NamedTemporaryFile(prefix=__name__, suffix='.pdf')

  cmdline = [
      DEV_SCORES_5COL,
      TEST_SCORES_5COL,
      '--output=' + tmp_output.name,
      ]

André Anjos's avatar
André Anjos committed
88
  from .script.compute_perf import main
89 90
  nose.tools.eq_(main(cmdline), 0)

André Anjos's avatar
André Anjos committed
91

92
def test_compute_cmc():
André Anjos's avatar
André Anjos committed
93

94 95 96
  # sanity checks
  assert os.path.exists(SCORES_4COL_CMC)
  assert os.path.exists(SCORES_5COL_CMC)
97
  assert os.path.exists(SCORES_4COL_CMC_OS)
André Anjos's avatar
André Anjos committed
98

André Anjos's avatar
André Anjos committed
99
  from .script.plot_cmc import main
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122

  tmp_output = tempfile.NamedTemporaryFile(prefix=__name__, suffix='.pdf')

  nose.tools.eq_(main([
    SCORES_4COL_CMC,
    '--log-x-scale',
    '--output=%s' % tmp_output.name,
    ]), 0)

  tmp_output = tempfile.NamedTemporaryFile(prefix=__name__, suffix='.pdf')

  nose.tools.eq_(main([
    SCORES_5COL_CMC,
    '--output=%s' % tmp_output.name,
    ]), 0)

  tmp_output = tempfile.NamedTemporaryFile(prefix=__name__, suffix='.pdf')

  nose.tools.eq_(main([
    SCORES_4COL_CMC_OS,
    '--rank=1',
    '--output=%s' % tmp_output.name,
    ]), 0)