test_commands.py 11.8 KB
Newer Older
1
2
3
4
import sys
import click
from click.testing import CliRunner
import pkg_resources
5
from ..script import (pad_commands, vuln_commands)
6
7


8
9
10
11
12
13
14
15

def test_det_pad():
    licit_dev = pkg_resources.resource_filename('bob.pad.base.test',
                                                'data/licit/scores-dev')
    licit_test = pkg_resources.resource_filename('bob.pad.base.test',
                                                 'data/licit/scores-eval')
    runner = CliRunner()
    with runner.isolated_filesystem():
16
        result = runner.invoke(pad_commands.det, ['--output',
17
18
19
20
21
22
23
                                                  'DET.pdf',
                                                  licit_dev, licit_test])
        assert result.exit_code == 0, (result.exit_code, result.output)



def test_det_vuln():
24
25
26
27
28
29
30
31
32
33
    licit_dev = pkg_resources.resource_filename('bob.pad.base.test',
                                                'data/licit/scores-dev')
    licit_test = pkg_resources.resource_filename('bob.pad.base.test',
                                                 'data/licit/scores-eval')
    spoof_dev = pkg_resources.resource_filename('bob.pad.base.test',
                                                'data/spoof/scores-dev')
    spoof_test = pkg_resources.resource_filename('bob.pad.base.test',
                                                 'data/spoof/scores-eval')
    runner = CliRunner()
    with runner.isolated_filesystem():
34
35
36
37
38
        result = runner.invoke(vuln_commands.det, ['-c', 'min-hter',
                                                   '--output',
                                                   'DET.pdf',
                                                   licit_dev, licit_test,
                                                   spoof_dev, spoof_test])
39
        assert result.exit_code == 0, (result.exit_code, result.output)
40

41
42
43


def test_fmr_iapmr_vuln():
Theophile GENTILHOMME's avatar
Theophile GENTILHOMME committed
44
45
46
47
48
49
50
51
52
53
    licit_dev = pkg_resources.resource_filename('bob.pad.base.test',
                                                'data/licit/scores-dev')
    licit_test = pkg_resources.resource_filename('bob.pad.base.test',
                                                 'data/licit/scores-eval')
    spoof_dev = pkg_resources.resource_filename('bob.pad.base.test',
                                                'data/spoof/scores-dev')
    spoof_test = pkg_resources.resource_filename('bob.pad.base.test',
                                                 'data/spoof/scores-eval')
    runner = CliRunner()
    with runner.isolated_filesystem():
54
        result = runner.invoke(vuln_commands.fmr_iapmr, [
Theophile GENTILHOMME's avatar
Theophile GENTILHOMME committed
55
56
57
58
59
            '--output', 'FMRIAPMR.pdf', licit_dev, licit_test, spoof_dev,
            spoof_test
        ])
        assert result.exit_code == 0, (result.exit_code, result.output)

60
        result = runner.invoke(vuln_commands.fmr_iapmr, [
Theophile GENTILHOMME's avatar
Theophile GENTILHOMME committed
61
62
63
64
65
66
            '--output', 'FMRIAPMR.pdf', licit_dev, licit_test, spoof_dev,
            spoof_test, '-G', '-L', '1e-7,1,0,1'
        ])
        assert result.exit_code == 0, (result.exit_code, result.output)


67
68

def test_hist_pad():
69
70
71
72
73
74
75
76
77
78
    licit_dev = pkg_resources.resource_filename('bob.pad.base.test',
                                                'data/licit/scores-dev')
    licit_test = pkg_resources.resource_filename('bob.pad.base.test',
                                                 'data/licit/scores-eval')
    spoof_dev = pkg_resources.resource_filename('bob.pad.base.test',
                                                'data/spoof/scores-dev')
    spoof_test = pkg_resources.resource_filename('bob.pad.base.test',
                                                 'data/spoof/scores-eval')
    runner = CliRunner()
    with runner.isolated_filesystem():
79
        result = runner.invoke(pad_commands.hist, ['--no-evaluation', licit_dev])
80
        assert result.exit_code == 0, (result.exit_code, result.output)
81
82

    with runner.isolated_filesystem():
83
84
85
86
87
        result = runner.invoke(pad_commands.hist, ['--criterion', 'min-hter',
                                                   '--output',
                                                   'HISTO.pdf', '-b',
                                                   '30,auto', '--no-evaluation',
                                                   licit_dev, spoof_dev])
88
        assert result.exit_code == 0, (result.exit_code, result.output)
89
90

    with runner.isolated_filesystem():
91
92
93
94
        result = runner.invoke(pad_commands.hist, ['--criterion', 'eer', '--output',
                                                   'HISTO.pdf', '-b', '30',
                                                   licit_dev, licit_test,
                                                   spoof_dev, spoof_test])
95
        assert result.exit_code == 0, (result.exit_code, result.output)
96

97
98
99


def test_hist_vuln():
100
101
102
103
104
105
106
107
108
109
    licit_dev = pkg_resources.resource_filename('bob.pad.base.test',
                                                'data/licit/scores-dev')
    licit_test = pkg_resources.resource_filename('bob.pad.base.test',
                                                 'data/licit/scores-eval')
    spoof_dev = pkg_resources.resource_filename('bob.pad.base.test',
                                                'data/spoof/scores-dev')
    spoof_test = pkg_resources.resource_filename('bob.pad.base.test',
                                                 'data/spoof/scores-eval')
    runner = CliRunner()
    with runner.isolated_filesystem():
110
111
112
113
114
        result = runner.invoke(vuln_commands.hist,
                               ['--criterion', 'eer', '--output',
                                'HISTO.pdf', '-b', '30',
                                licit_dev, licit_test,
                                spoof_dev, spoof_test])
115
        assert result.exit_code == 0, (result.exit_code, result.output)
Theophile GENTILHOMME's avatar
Bug fix    
Theophile GENTILHOMME committed
116

117
118
119


def test_metrics_vuln():
Theophile GENTILHOMME's avatar
Bug fix    
Theophile GENTILHOMME committed
120
121
122
123
124
125
126
127
128
129
130
    licit_dev = pkg_resources.resource_filename('bob.pad.base.test',
                                                'data/licit/scores-dev')
    licit_test = pkg_resources.resource_filename('bob.pad.base.test',
                                                 'data/licit/scores-eval')
    spoof_dev = pkg_resources.resource_filename('bob.pad.base.test',
                                                'data/spoof/scores-dev')
    spoof_test = pkg_resources.resource_filename('bob.pad.base.test',
                                                 'data/spoof/scores-eval')
    runner = CliRunner()
    with runner.isolated_filesystem():
        result = runner.invoke(
131
132
133
            vuln_commands.metrics,
            ['--criterion', 'eer', licit_dev, licit_test,
             spoof_dev, spoof_test]
Theophile GENTILHOMME's avatar
Bug fix    
Theophile GENTILHOMME committed
134
135
        )
        assert result.exit_code == 0, (result.exit_code, result.output)
136

137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154


def test_metrics_pad():
    licit_dev = pkg_resources.resource_filename('bob.pad.base.test',
                                                'data/licit/scores-dev')
    licit_test = pkg_resources.resource_filename('bob.pad.base.test',
                                                 'data/licit/scores-eval')
    runner = CliRunner()
    with runner.isolated_filesystem():
        result = runner.invoke(
            pad_commands.metrics,
            [licit_dev, licit_test]
        )
        assert result.exit_code == 0, (result.exit_code, result.output)



def test_epc_vuln():
155
156
157
158
159
160
161
162
163
164
    licit_dev = pkg_resources.resource_filename('bob.pad.base.test',
                                                'data/licit/scores-dev')
    licit_test = pkg_resources.resource_filename('bob.pad.base.test',
                                                 'data/licit/scores-eval')
    spoof_dev = pkg_resources.resource_filename('bob.pad.base.test',
                                                'data/spoof/scores-dev')
    spoof_test = pkg_resources.resource_filename('bob.pad.base.test',
                                                 'data/spoof/scores-eval')
    runner = CliRunner()
    with runner.isolated_filesystem():
165
166
167
168
        result = runner.invoke(vuln_commands.epc,
                               ['--output', 'epc.pdf',
                                licit_dev, licit_test,
                                spoof_dev, spoof_test])
169
        assert result.exit_code == 0, (result.exit_code, result.output)
170

171
172
173
174
        result = runner.invoke(vuln_commands.epc,
                               ['--output', 'epc.pdf', '-I',
                                licit_dev, licit_test,
                                spoof_dev, spoof_test])
175
        assert result.exit_code == 0, (result.exit_code, result.output)
176

177
178
179


def test_epsc_vuln():
180
181
182
183
184
185
186
187
188
189
    licit_dev = pkg_resources.resource_filename('bob.pad.base.test',
                                                'data/licit/scores-dev')
    licit_test = pkg_resources.resource_filename('bob.pad.base.test',
                                                 'data/licit/scores-eval')
    spoof_dev = pkg_resources.resource_filename('bob.pad.base.test',
                                                'data/spoof/scores-dev')
    spoof_test = pkg_resources.resource_filename('bob.pad.base.test',
                                                 'data/spoof/scores-eval')
    runner = CliRunner()
    with runner.isolated_filesystem():
190
191
192
193
194
195
196
197
198
199
        result = runner.invoke(vuln_commands.epsc,
                               ['--output', 'epsc.pdf',
                                licit_dev, licit_test,
                                spoof_dev, spoof_test])
        assert result.exit_code == 0, (result.exit_code, result.output)

        result = runner.invoke(vuln_commands.epsc,
                               ['--output', 'epsc.pdf', '-I',
                                licit_dev, licit_test,
                                spoof_dev, spoof_test])
200
        assert result.exit_code == 0, (result.exit_code, result.output)
201

202
203
204
205
        result = runner.invoke(vuln_commands.epsc,
                               ['--output', 'epsc.pdf', '-D',
                                licit_dev, licit_test,
                                spoof_dev, spoof_test])
206
        assert result.exit_code == 0, (result.exit_code, result.output)
207

208
209
210
211
212
        result = runner.invoke(vuln_commands.epsc,
                               ['--output', 'epsc.pdf', '-D',
                                '-I', '--no-wer',
                                licit_dev, licit_test,
                                spoof_dev, spoof_test])
213
        assert result.exit_code == 0, (result.exit_code, result.output)
214

215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246


def test_evaluate_vuln():
    licit_dev = pkg_resources.resource_filename('bob.pad.base.test',
                                                'data/licit/scores-dev')
    licit_test = pkg_resources.resource_filename('bob.pad.base.test',
                                                 'data/licit/scores-eval')
    spoof_dev = pkg_resources.resource_filename('bob.pad.base.test',
                                                'data/spoof/scores-dev')
    spoof_test = pkg_resources.resource_filename('bob.pad.base.test',
                                                 'data/spoof/scores-eval')
    runner = CliRunner()
    with runner.isolated_filesystem():
        result = runner.invoke(pad_commands.evaluate,
                               [licit_dev, licit_test, spoof_dev, spoof_test])
        assert result.exit_code == 0, (result.exit_code, result.output)



def test_evaluate_vuln():
    licit_dev = pkg_resources.resource_filename('bob.pad.base.test',
                                                'data/licit/scores-dev')
    licit_test = pkg_resources.resource_filename('bob.pad.base.test',
                                                 'data/licit/scores-eval')
    spoof_dev = pkg_resources.resource_filename('bob.pad.base.test',
                                                'data/spoof/scores-dev')
    spoof_test = pkg_resources.resource_filename('bob.pad.base.test',
                                                 'data/spoof/scores-eval')
    runner = CliRunner()
    with runner.isolated_filesystem():
        result = runner.invoke(vuln_commands.evaluate,
                               [licit_dev, licit_test, spoof_dev, spoof_test])
247
        assert result.exit_code == 0, (result.exit_code, result.output)