test_scripts.py 2.79 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
  tmp_output = tempfile.NamedTemporaryFile(prefix=__name__, suffix='.pdf')

  cmdline = [
      DEV_SCORES,
      TEST_SCORES,
      '--output=' + tmp_output.name,
Amir Mohammadi's avatar
lint  
Amir Mohammadi committed
43
  ]
44

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 50 51 52 53 54 55 56 57 58
def test_compute_perf_only_dev():

  # sanity checks
  assert os.path.exists(DEV_SCORES)

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

  cmdline = [
      DEV_SCORES,
      '--output=' + tmp_output.name,
Amir Mohammadi's avatar
lint  
Amir Mohammadi committed
59
  ]
60 61 62 63 64

  from .script.compute_perf import main
  nose.tools.eq_(main(cmdline), 0)


65
def test_eval_threshold():
André Anjos's avatar
André Anjos committed
66

67 68
  # sanity checks
  assert os.path.exists(DEV_SCORES)
André Anjos's avatar
André Anjos committed
69

70 71
  cmdline = [DEV_SCORES]

André Anjos's avatar
André Anjos committed
72
  from .script.eval_threshold import main
73 74
  nose.tools.eq_(main(cmdline), 0)

André Anjos's avatar
André Anjos committed
75

76
def test_apply_threshold():
André Anjos's avatar
André Anjos committed
77

78 79
  # sanity checks
  assert os.path.exists(TEST_SCORES)
André Anjos's avatar
André Anjos committed
80

81 82 83
  cmdline = [
      '0.5',
      TEST_SCORES,
Amir Mohammadi's avatar
lint  
Amir Mohammadi committed
84
  ]
85

André Anjos's avatar
André Anjos committed
86
  from .script.apply_threshold import main
87 88
  nose.tools.eq_(main(cmdline), 0)

André Anjos's avatar
André Anjos committed
89

90
def test_compute_perf_5col():
André Anjos's avatar
André Anjos committed
91

92 93 94
  # sanity checks
  assert os.path.exists(DEV_SCORES_5COL)
  assert os.path.exists(TEST_SCORES_5COL)
André Anjos's avatar
André Anjos committed
95

96 97 98 99 100 101
  tmp_output = tempfile.NamedTemporaryFile(prefix=__name__, suffix='.pdf')

  cmdline = [
      DEV_SCORES_5COL,
      TEST_SCORES_5COL,
      '--output=' + tmp_output.name,
Amir Mohammadi's avatar
lint  
Amir Mohammadi committed
102
  ]
103

André Anjos's avatar
André Anjos committed
104
  from .script.compute_perf import main
105 106
  nose.tools.eq_(main(cmdline), 0)

André Anjos's avatar
André Anjos committed
107

108
def test_compute_cmc():
André Anjos's avatar
André Anjos committed
109

110 111 112
  # sanity checks
  assert os.path.exists(SCORES_4COL_CMC)
  assert os.path.exists(SCORES_5COL_CMC)
113
  assert os.path.exists(SCORES_4COL_CMC_OS)
André Anjos's avatar
André Anjos committed
114

André Anjos's avatar
André Anjos committed
115
  from .script.plot_cmc import main
116 117 118 119

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

  nose.tools.eq_(main([
Amir Mohammadi's avatar
lint  
Amir Mohammadi committed
120 121 122 123
      SCORES_4COL_CMC,
      '--log-x-scale',
      '--output=%s' % tmp_output.name,
  ]), 0)
124 125 126 127

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

  nose.tools.eq_(main([
Amir Mohammadi's avatar
lint  
Amir Mohammadi committed
128 129 130
      SCORES_5COL_CMC,
      '--output=%s' % tmp_output.name,
  ]), 0)
131 132 133 134

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

  nose.tools.eq_(main([
Amir Mohammadi's avatar
lint  
Amir Mohammadi committed
135 136 137 138
      SCORES_4COL_CMC_OS,
      '--rank=1',
      '--output=%s' % tmp_output.name,
  ]), 0)