test_script.py 7.59 KB
Newer Older
1 2
'''Tests for bob.measure scripts'''

3
import sys
4 5 6 7
import filecmp
import click
from click.testing import CliRunner
import bob.io.base.test_utils
8
from .script import commands
9 10 11 12

def test_metrics():
    dev1 = bob.io.base.test_utils.datafile('dev-1.txt', 'bob.measure')
    runner = CliRunner()
13
    result = runner.invoke(commands.metrics, ['--no-evaluation', dev1])
14 15 16 17
    with runner.isolated_filesystem():
        with open('tmp', 'w') as f:
            f.write(result.output)
        test_ref = bob.io.base.test_utils.datafile('test_m1.txt', 'bob.measure')
18
        assert result.exit_code == 0, (result.exit_code, result.output)
19 20 21 22 23 24

    dev2 = bob.io.base.test_utils.datafile('dev-2.txt', 'bob.measure')
    test1 = bob.io.base.test_utils.datafile('test-1.txt', 'bob.measure')
    test2 = bob.io.base.test_utils.datafile('test-2.txt', 'bob.measure')
    with runner.isolated_filesystem():
        result = runner.invoke(
25
            commands.metrics, [dev1, test1, dev2, test2]
26 27 28 29
        )
        with open('tmp', 'w') as f:
            f.write(result.output)
        test_ref = bob.io.base.test_utils.datafile('test_m2.txt', 'bob.measure')
30
        assert result.exit_code == 0
31 32
    with runner.isolated_filesystem():
        result = runner.invoke(
33
            commands.metrics, ['-l', 'tmp', dev1, test1, dev2, test2, '-Z',
34
                              'A,B']
35
        )
36 37
        assert result.exit_code == 0, (result.exit_code, result.output)

38 39
    with runner.isolated_filesystem():
        result = runner.invoke(
40
            commands.metrics, ['-l', 'tmp', '--no-evaluation', dev1, dev2]
41
        )
42
        assert result.exit_code == 0, (result.exit_code, result.output)
43 44 45 46 47

def test_roc():
    dev1 = bob.io.base.test_utils.datafile('dev-1.txt', 'bob.measure')
    runner = CliRunner()
    with runner.isolated_filesystem():
48 49
        result = runner.invoke(commands.roc, ['--no-evaluation', '--output',
                                              'test.pdf',dev1])
50 51 52 53 54 55 56
        if result.output:
            click.echo(result.output)
        assert result.exit_code == 0
    dev2 = bob.io.base.test_utils.datafile('dev-2.txt', 'bob.measure')
    test1 = bob.io.base.test_utils.datafile('test-1.txt', 'bob.measure')
    test2 = bob.io.base.test_utils.datafile('test-2.txt', 'bob.measure')
    with runner.isolated_filesystem():
57
        result = runner.invoke(commands.roc, ['--split', '--output',
58 59 60 61
                                              'test.pdf',
                                              dev1, test1, dev2, test2])
        if result.output:
            click.echo(result.output)
62
        assert result.exit_code == 0, (result.exit_code, result.output)
63

64
    with runner.isolated_filesystem():
65
        result = runner.invoke(commands.roc, ['--output',
66
                                              'test.pdf', '--legends', 'A,B', 
67 68 69
                                              dev1, test1, dev2, test2])
        if result.output:
            click.echo(result.output)
70
        assert result.exit_code == 0, (result.exit_code, result.output)
71 72


73 74 75 76
def test_det():
    dev1 = bob.io.base.test_utils.datafile('dev-1.txt', 'bob.measure')
    runner = CliRunner()
    with runner.isolated_filesystem():
77
        result = runner.invoke(commands.det, ['--no-evaluation', dev1])
78 79 80 81 82 83
        if result.output:
            click.echo(result.output)
        assert result.exit_code == 0
    dev2 = bob.io.base.test_utils.datafile('dev-2.txt', 'bob.measure')
    test1 = bob.io.base.test_utils.datafile('test-1.txt', 'bob.measure')
    test2 = bob.io.base.test_utils.datafile('test-2.txt', 'bob.measure')
84
    with runner.isolated_filesystem():
85
        result = runner.invoke(commands.det, ['--split', '--output',
86
                                              'test.pdf', '--legends', 'A,B',
87 88 89
                                              dev1, test1, dev2, test2])
        if result.output:
            click.echo(result.output)
90 91
        assert result.exit_code == 0, (result.exit_code, result.output)

92
    with runner.isolated_filesystem():
93
        result = runner.invoke(commands.det, ['--output',
94 95 96 97
                                              'test.pdf',
                                              dev1, test1, dev2, test2])
        if result.output:
            click.echo(result.output)
98
        assert result.exit_code == 0, (result.exit_code, result.output)
99 100 101 102 103 104

def test_epc():
    dev1 = bob.io.base.test_utils.datafile('dev-1.txt', 'bob.measure')
    test1 = bob.io.base.test_utils.datafile('test-1.txt', 'bob.measure')
    runner = CliRunner()
    with runner.isolated_filesystem():
105
        result = runner.invoke(commands.epc, [dev1, test1])
106 107
        if result.output:
            click.echo(result.output)
108 109
        assert result.exit_code == 0, (result.exit_code, result.output)

110 111 112
    dev2 = bob.io.base.test_utils.datafile('dev-2.txt', 'bob.measure')
    test2 = bob.io.base.test_utils.datafile('test-2.txt', 'bob.measure')
    with runner.isolated_filesystem():
113
        result = runner.invoke(commands.epc, ['--output', 'test.pdf',
114
                                              '--legends', 'A,B',
115 116 117
                                              dev1, test1, dev2, test2])
        if result.output:
            click.echo(result.output)
118
        assert result.exit_code == 0, (result.exit_code, result.output)
119 120 121 122 123 124 125 126

def test_hist():
    dev1 = bob.io.base.test_utils.datafile('dev-1.txt', 'bob.measure')
    test1 = bob.io.base.test_utils.datafile('test-1.txt', 'bob.measure')
    dev2 = bob.io.base.test_utils.datafile('dev-2.txt', 'bob.measure')
    test2 = bob.io.base.test_utils.datafile('test-2.txt', 'bob.measure')
    runner = CliRunner()
    with runner.isolated_filesystem():
127
        result = runner.invoke(commands.hist, ['--no-evaluation', dev1])
128 129
        if result.output:
            click.echo(result.output)
130
        assert result.exit_code == 0, (result.exit_code, result.output)
131 132

    with runner.isolated_filesystem():
Theophile GENTILHOMME's avatar
Theophile GENTILHOMME committed
133
        result = runner.invoke(commands.hist, ['--no-evaluation', '--criterion', 'hter',
134
                                               '--output', 'HISTO.pdf',  '-b', 
135
                                               '30,100', dev1, dev2])
136 137
        if result.output:
            click.echo(result.output)
138
        assert result.exit_code == 0, (result.exit_code, result.output)
139 140

    with runner.isolated_filesystem():
Theophile GENTILHOMME's avatar
Theophile GENTILHOMME committed
141
        result = runner.invoke(commands.hist, ['--criterion', 'eer','--output',
142
                                               'HISTO.pdf',  '-b',  '30,20',
143
                                               '-sp', 221,
144 145 146
                                               dev1, test1, dev2, test2])
        if result.output:
            click.echo(result.output)
147
        assert result.exit_code == 0, (result.exit_code, result.output)
148 149 150 151 152 153 154 155 156


def test_evaluate():
    dev1 = bob.io.base.test_utils.datafile('dev-1.txt', 'bob.measure')
    test1 = bob.io.base.test_utils.datafile('test-1.txt', 'bob.measure')
    dev2 = bob.io.base.test_utils.datafile('dev-2.txt', 'bob.measure')
    test2 = bob.io.base.test_utils.datafile('test-2.txt', 'bob.measure')
    runner = CliRunner()
    with runner.isolated_filesystem():
157
        result = runner.invoke(commands.evaluate, ['--no-evaluation', dev1])
158
        assert result.exit_code == 0, (result.exit_code, result.output)
159 160 161

    with runner.isolated_filesystem():
        result = runner.invoke(
162
            commands.evaluate, ['--no-evaluation', '--output', 'my_plots.pdf', '-b',
163
                                '30,69', '-n', 300, dev1, dev2])
164
        assert result.exit_code == 0, (result.exit_code, result.output)
165 166 167

    with runner.isolated_filesystem():
        result = runner.invoke(
168
            commands.evaluate, [dev1, test1, dev2, test2])
169
        assert result.exit_code == 0, (result.exit_code, result.output)