annotate tests/test-json-destinations/test-json-destinations.sh @ 169:859d8ec60e06 jams

Add setNofM logic which the JSON writer can use to write a list when sending multiple files' worth to a single target
author Chris Cannam
date Wed, 15 Oct 2014 16:05:15 +0100
parents db83ea0e102d
children 4ef452f5fefc
rev   line source
Chris@0 1 #!/bin/bash
Chris@0 2
Chris@119 3 . ../include.sh
Chris@0 4
Chris@119 5 infile1=$audiopath/3clicks8.wav
Chris@119 6 infile2=$audiopath/6clicks8.wav
Chris@0 7
Chris@147 8 infile1dot=$audiopath/3.clicks.8.wav
Chris@0 9
Chris@150 10 outfile1=3clicks8.json
Chris@150 11 outfile2=6clicks8.json
Chris@44 12
Chris@150 13 outfile3=3clicks8_vamp_vamp-example-plugins_percussiononsets_onsets.json
Chris@150 14 outfile4=3clicks8_vamp_vamp-example-plugins_percussiononsets_detectionfunction.json
Chris@150 15 outfile5=6clicks8_vamp_vamp-example-plugins_percussiononsets_onsets.json
Chris@150 16 outfile6=6clicks8_vamp_vamp-example-plugins_percussiononsets_detectionfunction.json
Chris@147 17
Chris@150 18 outfile1dot=3.clicks.8.json
Chris@0 19
Chris@150 20 tmpjson=$mypath/tmp_1_$$.json
Chris@0 21
Chris@150 22 trap "rm -f $tmpjson $outfile1 $outfile2 $outfile3 $outfile4 $outfile5 $outfile6 $infile1dot $outfile1dot $audiopath/$outfile1 $audiopath/$outfile2 $audiopath/$outfile3 $audiopath/$outfile4 $audiopath/$outfile5 $audiopath/$outfile6 $audiopath/$outfile1dot" 0
Chris@0 23
Chris@119 24 transformdir=$mypath/transforms
Chris@0 25
Chris@169 26 failshow() {
Chris@169 27 echo "Test failed: $1"
Chris@169 28 if [ -n "$2" ]; then
Chris@169 29 echo "Output follows:"
Chris@169 30 echo "--"
Chris@169 31 cat $2
Chris@169 32 echo "--"
Chris@169 33 fi
Chris@169 34 exit 1
Chris@169 35 }
Chris@169 36
Chris@150 37 check_json() {
Chris@0 38 test -f $1 || \
Chris@0 39 fail "Fails to write output to expected location $1 for $2"
Chris@169 40 cat $1 | json_verify -q || \
Chris@169 41 failshow "Writes invalid JSON to location $1 for $2" $1
Chris@0 42 rm -f $1
Chris@0 43 }
Chris@0 44
Chris@0 45
Chris@150 46 ctx="onsets transform, one audio file, default JSON writer destination"
Chris@0 47
Chris@147 48 rm -f $audiopath/$outfile1
Chris@0 49
Chris@150 50 $r -t $transformdir/onsets.n3 -w json $infile1 2>/dev/null || \
Chris@0 51 fail "Fails to run with $ctx"
Chris@0 52
Chris@150 53 check_json $audiopath/$outfile1 "$ctx"
Chris@0 54
Chris@0 55
Chris@150 56 ctx="onsets transform, one audio file with dots in filename, default JSON writer destination"
Chris@44 57
Chris@147 58 rm -f $audiopath/$outfile1
Chris@44 59
Chris@44 60 cp $infile1 $infile1dot
Chris@44 61
Chris@150 62 $r -t $transformdir/onsets.n3 -w json $infile1dot 2>/dev/null || \
Chris@44 63 fail "Fails to run with $ctx"
Chris@44 64
Chris@150 65 check_json $audiopath/$outfile1dot "$ctx"
Chris@44 66
Chris@147 67 rm -f $infile1dot $audiopath/$outfile1dot
Chris@44 68
Chris@44 69
Chris@150 70 ctx="onsets and df transforms, one audio file, default JSON writer destination"
Chris@0 71
Chris@147 72 rm -f $audiopath/$outfile1
Chris@0 73
Chris@150 74 $r -t $transformdir/onsets.n3 -t $transformdir/detectionfunction.n3 -w json $infile1 2>/dev/null || \
Chris@0 75 fail "Fails to run with $ctx"
Chris@0 76
Chris@150 77 check_json $audiopath/$outfile1 "$ctx"
Chris@0 78
Chris@0 79
Chris@150 80 ctx="onsets transform, two audio files, default JSON writer destination"
Chris@0 81
Chris@147 82 rm -f $audiopath/$outfile1
Chris@147 83 rm -f $audiopath/$outfile2
Chris@0 84
Chris@150 85 $r -t $transformdir/onsets.n3 -w json $infile1 $infile2 2>/dev/null || \
Chris@0 86 fail "Fails to run with $ctx"
Chris@0 87
Chris@150 88 check_json $audiopath/$outfile1 "$ctx"
Chris@150 89 check_json $audiopath/$outfile2 "$ctx"
Chris@0 90
Chris@0 91
Chris@150 92 ctx="onsets transform, two audio files, one-file JSON writer"
Chris@0 93
Chris@152 94 $r -t $transformdir/onsets.n3 -w json --json-one-file $tmpjson $infile1 $infile2 2>/dev/null || \
Chris@152 95 fail "Fails to run with $ctx"
Chris@150 96
Chris@152 97 check_json $tmpjson "$ctx"
Chris@150 98
Chris@150 99
Chris@150 100 ctx="onsets transform, two audio files, stdout JSON writer"
Chris@150 101
Chris@150 102 $r -t $transformdir/onsets.n3 -w json --json-stdout $infile1 $infile2 2>/dev/null >$tmpjson || \
Chris@0 103 fail "Fails to run with $ctx"
Chris@0 104
Chris@150 105 check_json $tmpjson "$ctx"
Chris@0 106
Chris@0 107
Chris@150 108 ctx="onsets transform, one audio file, many-files JSON writer"
Chris@0 109
Chris@147 110 rm -f $audiopath/$outfile3
Chris@0 111
Chris@150 112 $r -t $transformdir/onsets.n3 -w json --json-many-files $infile1 2>/dev/null || \
Chris@0 113 fail "Fails to run with $ctx"
Chris@0 114
Chris@150 115 check_json $audiopath/$outfile3 "$ctx"
Chris@0 116
Chris@0 117
Chris@150 118 ctx="onsets transform, two audio files, many-files JSON writer"
Chris@0 119
Chris@147 120 rm -f $audiopath/$outfile3
Chris@147 121 rm -f $audiopath/$outfile5
Chris@0 122
Chris@150 123 $r -t $transformdir/onsets.n3 -w json --json-many-files $infile1 $infile2 2>/dev/null || \
Chris@0 124 fail "Fails to run with $ctx"
Chris@0 125
Chris@150 126 check_json $audiopath/$outfile3 "$ctx"
Chris@150 127 check_json $audiopath/$outfile5 "$ctx"
Chris@0 128
Chris@0 129
Chris@150 130 ctx="onsets and df transforms, two audio files, many-files JSON writer"
Chris@0 131
Chris@147 132 rm -f $audiopath/$outfile3
Chris@147 133 rm -f $audiopath/$outfile4
Chris@147 134 rm -f $audiopath/$outfile5
Chris@147 135 rm -f $audiopath/$outfile6
Chris@0 136
Chris@150 137 $r -t $transformdir/onsets.n3 -t $transformdir/detectionfunction.n3 -w json --json-many-files $infile1 $infile2 2>/dev/null || \
Chris@0 138 fail "Fails to run with $ctx"
Chris@0 139
Chris@150 140 check_json $audiopath/$outfile3 "$ctx"
Chris@150 141 check_json $audiopath/$outfile4 "$ctx"
Chris@150 142 check_json $audiopath/$outfile5 "$ctx"
Chris@150 143 check_json $audiopath/$outfile6 "$ctx"
Chris@147 144
Chris@147 145
Chris@147 146 ctx="output base directory"
Chris@147 147
Chris@147 148 rm -f ./$outfile1
Chris@147 149
Chris@150 150 $r -t $transformdir/onsets.n3 -t $transformdir/detectionfunction.n3 -w json --json-basedir . $infile1 2>/dev/null || \
Chris@147 151 fail "Fails to run with $ctx"
Chris@147 152
Chris@150 153 check_json ./$outfile1 "$ctx"
Chris@147 154
Chris@147 155
Chris@147 156 ctx="output base directory and many-files"
Chris@147 157
Chris@147 158 rm -f ./$outfile3
Chris@147 159 rm -f ./$outfile5
Chris@147 160
Chris@150 161 $r -t $transformdir/onsets.n3 -w json --json-basedir . --json-many-files $infile1 $infile2 2>/dev/null || \
Chris@147 162 fail "Fails to run with $ctx"
Chris@147 163
Chris@150 164 check_json ./$outfile3 "$ctx"
Chris@150 165 check_json ./$outfile5 "$ctx"
Chris@147 166
Chris@147 167
Chris@147 168 ctx="nonexistent output base directory"
Chris@147 169
Chris@150 170 $r -t $transformdir/onsets.n3 -w json --json-basedir ./DOES_NOT_EXIST $infile1 2>/dev/null && \
Chris@147 171 fail "Fails with $ctx by completing successfully (should refuse and bail out)"
Chris@0 172
Chris@0 173
Chris@150 174 ctx="existing output file and no --json-force"
Chris@0 175
Chris@147 176 touch $audiopath/$outfile1
Chris@0 177
Chris@150 178 $r -t $transformdir/onsets.n3 -w json $infile1 2>/dev/null && \
Chris@0 179 fail "Fails by completing successfully when output file already exists (should refuse and bail out)"
Chris@0 180
Chris@0 181
Chris@150 182 ctx="existing output file and --json-force"
Chris@0 183
Chris@147 184 touch $audiopath/$outfile1
Chris@0 185
Chris@150 186 $r -t $transformdir/onsets.n3 -w json --json-force $infile1 2>/dev/null || \
Chris@0 187 fail "Fails to run with $ctx"
Chris@0 188
Chris@150 189 check_json $audiopath/$outfile1 "$ctx"
Chris@0 190
Chris@0 191
Chris@0 192 exit 0