multi_exiftool 0.18.1 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog +4 -0
- data/examples/01_simple_reading.rb +13 -0
- data/examples/02_simple_writing.rb +19 -0
- data/examples/03_reading_using_groups.rb +28 -0
- data/examples/04_writing_using_groups.rb +33 -0
- data/examples/05_functional_api.rb +35 -0
- data/lib/multi_exiftool.rb +1 -1
- metadata +49 -49
- data/.aspell.pws +0 -35
- data/Gemfile +0 -3
- data/Rakefile +0 -31
- data/multi_exiftool.gemspec +0 -34
- data/regtest/read_all_tags.rb +0 -6
- data/regtest/read_all_tags.yml +0 -112
- data/regtest/test.jpg +0 -0
- data/test/data/a.jpg +0 -0
- data/test/data/b.jpg +0 -0
- data/test/data/c.jpg +0 -0
- data/test/data/example.config +0 -363
- data/test/helper.rb +0 -27
- data/test/test_batch.rb +0 -42
- data/test/test_executable.rb +0 -26
- data/test/test_exiftool_stuff.rb +0 -37
- data/test/test_functional_api.rb +0 -290
- data/test/test_reader.rb +0 -168
- data/test/test_values.rb +0 -202
- data/test/test_values_using_groups.rb +0 -63
- data/test/test_writer.rb +0 -132
- data/test/test_writer_groups.rb +0 -50
data/test/test_functional_api.rb
DELETED
@@ -1,290 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require_relative 'helper'
|
5
|
-
|
6
|
-
class TestFunctionalApi < Test::Unit::TestCase
|
7
|
-
|
8
|
-
context 'reading' do
|
9
|
-
|
10
|
-
setup do
|
11
|
-
@abc_authors = ['Jan Friedrich'] * 3
|
12
|
-
@abc_fnumbers = [5.6, 6.7, 8]
|
13
|
-
@abc_titles = 'Title A,Title B,Title C'.split(/,/)
|
14
|
-
end
|
15
|
-
|
16
|
-
test 'successful reading only filenames' do
|
17
|
-
run_in_temp_dir do
|
18
|
-
values, errors = MultiExiftool.read(%w(a.jpg b.jpg c.jpg))
|
19
|
-
assert_equal @abc_authors, values.map {|e| e['Author']}
|
20
|
-
assert_equal @abc_fnumbers, values.map {|e| e['FNumber']}
|
21
|
-
assert_equal @abc_titles, values.map {|e| e['Title']}
|
22
|
-
assert_equal [], errors
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
test 'successful reading with one tag' do
|
27
|
-
run_in_temp_dir do
|
28
|
-
values, errors = MultiExiftool.read(%w(a.jpg b.jpg c.jpg), tags: %w(title))
|
29
|
-
assert_equal @abc_titles, values.map {|e| e['Title']}
|
30
|
-
assert_equal [nil] * 3, values.map {|e| e['Author']}
|
31
|
-
assert_equal [], errors
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
test 'successful reading of hierarchical data' do
|
36
|
-
run_in_temp_dir do
|
37
|
-
values, errors = MultiExiftool.read(%w(a.jpg), group: 0)
|
38
|
-
res = values.first
|
39
|
-
assert_equal 'a.jpg', res.source_file
|
40
|
-
assert_equal 5.6, res.exif.fnumber
|
41
|
-
assert_equal [], errors
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
test 'successful reading with numerical option' do
|
46
|
-
run_in_temp_dir do
|
47
|
-
values, errors = MultiExiftool.read(%w[a.jpg b.jpg c.jpg], tags: %w[orientation], numerical: true)
|
48
|
-
assert_equal [1, 2, 3], values.map {|e| e.orientation}
|
49
|
-
assert_equal [], errors
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
test 'options with boolean argument' do
|
54
|
-
run_in_temp_dir do
|
55
|
-
values, errors = MultiExiftool.read('a.jpg')
|
56
|
-
assert_equal 5.6, values.first.aperture
|
57
|
-
values, errors = MultiExiftool.read('a.jpg', e: true)
|
58
|
-
assert_equal nil, values.first.aperture
|
59
|
-
assert_equal [], errors
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
test 'successful reading with user defined tags in config file' do
|
64
|
-
run_in_temp_dir do
|
65
|
-
values, errors = MultiExiftool.read(%w[a.jpg b.jpg c.jpg], tags: %w[mybasename fileextension])
|
66
|
-
assert_equal [nil, nil, nil], values.map(&:mybasename)
|
67
|
-
assert_equal [nil, nil, nil], values.map(&:file_extension)
|
68
|
-
assert_equal [], errors
|
69
|
-
values, errors = MultiExiftool.read(%w[a.jpg b.jpg c.jpg], config: 'example.config', tags: %w[mybasename fileextension])
|
70
|
-
assert_equal %w[a b c], values.map(&:mybasename)
|
71
|
-
assert_equal %w[jpg]*3, values.map(&:file_extension)
|
72
|
-
assert_equal [], errors
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
context 'writing' do
|
78
|
-
|
79
|
-
setup do
|
80
|
-
@filenames = %w(a.jpg b.jpg c.jpg)
|
81
|
-
end
|
82
|
-
|
83
|
-
test 'simple case' do
|
84
|
-
run_in_temp_dir do
|
85
|
-
values = {comment: 'foo'}
|
86
|
-
errors = MultiExiftool.write(@filenames, values)
|
87
|
-
assert errors.empty?
|
88
|
-
values, _errors = MultiExiftool.read(@filenames)
|
89
|
-
assert_equal %w(foo) * 3, values.map {|e| e.comment}
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
test 'tags with spaces in values' do
|
94
|
-
run_in_temp_dir do
|
95
|
-
values = {author: 'Mister X'}
|
96
|
-
errors = MultiExiftool.write(@filenames, values)
|
97
|
-
assert errors.empty?
|
98
|
-
values, _errors = MultiExiftool.read(@filenames)
|
99
|
-
assert_equal ['Mister X'] * 3, values.map {|e| e.author}
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
test 'tags with rational value' do
|
104
|
-
run_in_temp_dir do
|
105
|
-
values ={exposuretime: Rational(1, 125)}
|
106
|
-
errors = MultiExiftool.write(@filenames, values)
|
107
|
-
assert errors.empty?
|
108
|
-
values, _errors = MultiExiftool.read(@filenames)
|
109
|
-
assert_equal [Rational(1, 125)] * 3, values.map {|e| e.exposuretime}
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
test 'tags with array-like values' do
|
114
|
-
run_in_temp_dir do
|
115
|
-
keywords = ['one', 'two', 'and three']
|
116
|
-
values = {keywords: keywords}
|
117
|
-
errors = MultiExiftool.write('a.jpg', values)
|
118
|
-
assert errors.empty?
|
119
|
-
values, _errors = MultiExiftool.read('a.jpg')
|
120
|
-
assert_equal keywords, values.first.keywords
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
test 'options with boolean argument' do
|
125
|
-
run_in_temp_dir do
|
126
|
-
values = {comment: 'foo'}
|
127
|
-
options = {overwrite_original: true}
|
128
|
-
errors = MultiExiftool.write(@filenames, values, options)
|
129
|
-
assert errors.empty?
|
130
|
-
assert_equal [], Dir['*_original']
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
test 'numerical flag' do
|
135
|
-
run_in_temp_dir do
|
136
|
-
values = {orientation: 2}
|
137
|
-
errors = MultiExiftool.write(@filenames, values)
|
138
|
-
assert_equal ["Warning: Can't convert IFD0:Orientation (matches more than one PrintConv)"], errors
|
139
|
-
errors = MultiExiftool.write(@filenames, values, numerical: true)
|
140
|
-
assert errors.empty?
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
end
|
145
|
-
|
146
|
-
context 'deleting' do
|
147
|
-
|
148
|
-
setup do
|
149
|
-
@filenames = %w(a.jpg b.jpg c.jpg)
|
150
|
-
end
|
151
|
-
|
152
|
-
test 'delete all values' do
|
153
|
-
run_in_temp_dir do
|
154
|
-
errors = MultiExiftool.delete_values(@filenames)
|
155
|
-
assert_equal [], errors
|
156
|
-
values, errors = MultiExiftool.read(@filenames)
|
157
|
-
assert_equal [nil, nil, nil], values.map {|e| e['Author']}
|
158
|
-
assert_equal [nil, nil, nil], values.map {|e| e['FNumber']}
|
159
|
-
assert_equal [nil, nil, nil], values.map {|e| e['Title']}
|
160
|
-
assert_equal [], errors
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
test 'delete values for some tags' do
|
165
|
-
run_in_temp_dir do
|
166
|
-
errors = MultiExiftool.delete_values(@filenames, tags: %w(author title))
|
167
|
-
assert_equal [], errors
|
168
|
-
values, errors = MultiExiftool.read(@filenames)
|
169
|
-
assert_equal [nil, nil, nil], values.map {|e| e['Author']}
|
170
|
-
assert_equal [5.6, 6.7, 8], values.map {|e| e['FNumber']}
|
171
|
-
assert_equal [nil, nil, nil], values.map {|e| e['Title']}
|
172
|
-
assert_equal [], errors
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
test 'delete values for one tag' do
|
177
|
-
run_in_temp_dir do
|
178
|
-
errors = MultiExiftool.delete_values(@filenames, tags: :title)
|
179
|
-
assert_equal [], errors
|
180
|
-
values, errors = MultiExiftool.read(@filenames)
|
181
|
-
assert_equal ['Jan Friedrich'] * 3, values.map {|e| e['Author']}
|
182
|
-
assert_equal [5.6, 6.7, 8], values.map {|e| e['FNumber']}
|
183
|
-
assert_equal [nil, nil, nil], values.map {|e| e['Title']}
|
184
|
-
assert_equal [], errors
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
test 'error if tags do not exist' do
|
189
|
-
run_in_temp_dir do
|
190
|
-
errors = MultiExiftool.delete_values(@filenames, tags: %w[foo bar])
|
191
|
-
err1, err2 = errors
|
192
|
-
expected1 = /^Warning: Tag 'foo' is not defined$/
|
193
|
-
expected2 = /^Warning: Tag 'bar' is not defined$/
|
194
|
-
assert_match expected1, err1
|
195
|
-
assert_match expected2, err2
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
end
|
200
|
-
|
201
|
-
context 'batch' do
|
202
|
-
|
203
|
-
setup do
|
204
|
-
@filenames = %w(a.jpg b.jpg c.jpg)
|
205
|
-
@multiple_values = @filenames.map do |fn|
|
206
|
-
{author: 'Jan Friedrich', comment: "Comment for file #{fn}"}
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
context 'instance_exec' do
|
211
|
-
|
212
|
-
test 'only filenames and values' do
|
213
|
-
run_in_temp_dir do
|
214
|
-
filenames = @filenames
|
215
|
-
multiple_values = @multiple_values
|
216
|
-
errors = MultiExiftool.batch do
|
217
|
-
filenames.zip multiple_values do |filename, values|
|
218
|
-
write filename, values
|
219
|
-
end
|
220
|
-
end
|
221
|
-
assert_equal [], errors
|
222
|
-
values, errors = MultiExiftool.read(@filenames)
|
223
|
-
assert_equal ['Jan Friedrich'] * 3, values.map {|e| e['Author']}
|
224
|
-
assert_equal ['Comment for file a.jpg', 'Comment for file b.jpg', 'Comment for file c.jpg'], values.map {|e| e['Comment']}
|
225
|
-
assert_equal [], errors
|
226
|
-
assert_equal 3, Dir['*_original'].size
|
227
|
-
end
|
228
|
-
end
|
229
|
-
|
230
|
-
test 'options with boolean argument' do
|
231
|
-
run_in_temp_dir do
|
232
|
-
filenames = @filenames
|
233
|
-
multiple_values = @multiple_values
|
234
|
-
options = {overwrite_original: true}
|
235
|
-
errors = MultiExiftool.batch do
|
236
|
-
filenames.zip multiple_values do |filename, values|
|
237
|
-
write filename, values, options
|
238
|
-
end
|
239
|
-
end
|
240
|
-
assert_equal [], errors
|
241
|
-
values, errors = MultiExiftool.read(@filenames)
|
242
|
-
assert_equal ['Jan Friedrich'] * 3, values.map {|e| e['Author']}
|
243
|
-
assert_equal ['Comment for file a.jpg', 'Comment for file b.jpg', 'Comment for file c.jpg'], values.map {|e| e['Comment']}
|
244
|
-
assert_equal [], errors
|
245
|
-
assert_equal [], Dir['*_original']
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
end
|
250
|
-
|
251
|
-
context 'yield' do
|
252
|
-
|
253
|
-
test 'only filenames and values' do
|
254
|
-
run_in_temp_dir do
|
255
|
-
errors = MultiExiftool.batch do |batch|
|
256
|
-
@filenames.zip @multiple_values do |filename, values|
|
257
|
-
batch.write filename, values
|
258
|
-
end
|
259
|
-
end
|
260
|
-
assert_equal [], errors
|
261
|
-
values, errors = MultiExiftool.read(@filenames)
|
262
|
-
assert_equal ['Jan Friedrich'] * 3, values.map {|e| e['Author']}
|
263
|
-
assert_equal ['Comment for file a.jpg', 'Comment for file b.jpg', 'Comment for file c.jpg'], values.map {|e| e['Comment']}
|
264
|
-
assert_equal [], errors
|
265
|
-
assert_equal 3, Dir['*_original'].size
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
|
-
test 'options with boolean argument' do
|
270
|
-
run_in_temp_dir do
|
271
|
-
options = {overwrite_original: true}
|
272
|
-
errors = MultiExiftool.batch do |batch|
|
273
|
-
@filenames.zip @multiple_values do |filename, values|
|
274
|
-
batch.write filename, values, options
|
275
|
-
end
|
276
|
-
end
|
277
|
-
assert_equal [], errors
|
278
|
-
values, errors = MultiExiftool.read(@filenames)
|
279
|
-
assert_equal ['Jan Friedrich'] * 3, values.map {|e| e['Author']}
|
280
|
-
assert_equal ['Comment for file a.jpg', 'Comment for file b.jpg', 'Comment for file c.jpg'], values.map {|e| e['Comment']}
|
281
|
-
assert_equal [], errors
|
282
|
-
assert_equal [], Dir['*_original']
|
283
|
-
end
|
284
|
-
end
|
285
|
-
|
286
|
-
end
|
287
|
-
|
288
|
-
end
|
289
|
-
|
290
|
-
end
|
data/test/test_reader.rb
DELETED
@@ -1,168 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require_relative 'helper'
|
5
|
-
|
6
|
-
class TestReader < Test::Unit::TestCase
|
7
|
-
|
8
|
-
MANDATORY_ARGS = MultiExiftool::Reader.mandatory_args
|
9
|
-
|
10
|
-
setup do
|
11
|
-
@reader = MultiExiftool::Reader.new
|
12
|
-
end
|
13
|
-
|
14
|
-
context 'tags' do
|
15
|
-
|
16
|
-
test 'tags are initialized as array' do
|
17
|
-
assert_equal [], @reader.tags
|
18
|
-
end
|
19
|
-
|
20
|
-
test 'tags could be set as single value' do
|
21
|
-
@reader.tags = 'fnumber'
|
22
|
-
assert_equal ['fnumber'], @reader.tags
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'exiftool_args method' do
|
28
|
-
|
29
|
-
test 'simple case' do
|
30
|
-
@reader.filenames = %w(a.jpg b.jpg c.jpg)
|
31
|
-
exiftool_args = MANDATORY_ARGS + %w(a.jpg b.jpg c.jpg)
|
32
|
-
assert_equal exiftool_args, @reader.exiftool_args
|
33
|
-
end
|
34
|
-
|
35
|
-
test 'no filenames' do
|
36
|
-
assert_raises MultiExiftool::Error do
|
37
|
-
@reader.exiftool_args
|
38
|
-
end
|
39
|
-
@reader.filenames = []
|
40
|
-
assert_raises MultiExiftool::Error do
|
41
|
-
@reader.exiftool_args
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
test 'one filename as string' do
|
46
|
-
@reader.filenames = 'a.jpg'
|
47
|
-
exiftool_args = MANDATORY_ARGS + %w(a.jpg)
|
48
|
-
assert_equal exiftool_args, @reader.exiftool_args
|
49
|
-
end
|
50
|
-
|
51
|
-
test 'filenames with spaces' do
|
52
|
-
@reader.filenames = ['one file with spaces.jpg', 'another file with spaces.tif']
|
53
|
-
exiftool_args = MANDATORY_ARGS + ['one file with spaces.jpg', 'another file with spaces.tif']
|
54
|
-
assert_equal exiftool_args, @reader.exiftool_args
|
55
|
-
end
|
56
|
-
|
57
|
-
test 'tags' do
|
58
|
-
@reader.filenames = %w(a.jpg b.jpg c.jpg)
|
59
|
-
@reader.tags = %w(author fnumber)
|
60
|
-
exiftool_args = MANDATORY_ARGS + %w(-author -fnumber a.jpg b.jpg c.jpg)
|
61
|
-
assert_equal exiftool_args, @reader.exiftool_args
|
62
|
-
end
|
63
|
-
|
64
|
-
test 'options with boolean argument' do
|
65
|
-
@reader.filenames = %w(a.jpg b.jpg c.jpg)
|
66
|
-
@reader.options = {e: true}
|
67
|
-
exiftool_args = MANDATORY_ARGS + %w(-e a.jpg b.jpg c.jpg)
|
68
|
-
assert_equal exiftool_args, @reader.exiftool_args
|
69
|
-
end
|
70
|
-
|
71
|
-
test 'options with value argument' do
|
72
|
-
@reader.filenames = %w(a.jpg b.jpg c.jpg)
|
73
|
-
@reader.options = {lang: 'de'}
|
74
|
-
exiftool_args = MANDATORY_ARGS + %w(-lang de a.jpg b.jpg c.jpg)
|
75
|
-
assert_equal exiftool_args, @reader.exiftool_args
|
76
|
-
end
|
77
|
-
|
78
|
-
test 'numerical flag' do
|
79
|
-
@reader.filenames = %w(a.jpg b.jpg c.jpg)
|
80
|
-
@reader.numerical = true
|
81
|
-
exiftool_args = MANDATORY_ARGS + %w(-n a.jpg b.jpg c.jpg)
|
82
|
-
assert_equal exiftool_args, @reader.exiftool_args
|
83
|
-
end
|
84
|
-
|
85
|
-
test 'group flag' do
|
86
|
-
@reader.filenames = %w(a.jpg)
|
87
|
-
@reader.group = 0
|
88
|
-
exiftool_args = MANDATORY_ARGS + %w(-g0 a.jpg)
|
89
|
-
assert_equal exiftool_args, @reader.exiftool_args
|
90
|
-
@reader.group = 1
|
91
|
-
exiftool_args = MANDATORY_ARGS + %w(-g1 a.jpg)
|
92
|
-
assert_equal exiftool_args, @reader.exiftool_args
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|
96
|
-
|
97
|
-
context 'read method' do
|
98
|
-
|
99
|
-
test 'try to read a non-existing file' do
|
100
|
-
run_in_temp_dir do
|
101
|
-
@reader.filenames = %w(non_existing_file)
|
102
|
-
res = @reader.read
|
103
|
-
assert_equal [], res
|
104
|
-
assert_equal ['Error: File not found - non_existing_file'], @reader.errors
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
test 'read from an existing and a non-existing file' do
|
109
|
-
run_in_temp_dir do
|
110
|
-
@reader.filenames = %w(a.jpg xxx)
|
111
|
-
@reader.tags = %w(fnumber foo)
|
112
|
-
res = @reader.read
|
113
|
-
assert_equal [5.6], res.map {|e| e['FNumber']}
|
114
|
-
assert_equal ['Error: File not found - xxx'], @reader.errors
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
test 'successful reading with one tag' do
|
119
|
-
run_in_temp_dir do
|
120
|
-
@reader.filenames = %w(a.jpg b.jpg c.jpg)
|
121
|
-
@reader.tags = %w(fnumber)
|
122
|
-
res = @reader.read
|
123
|
-
assert_equal [5.6, 6.7, 8], res.map {|e| e['FNumber']}
|
124
|
-
assert_equal %w(SourceFile FNumber), res.first.tags
|
125
|
-
assert_equal [], @reader.errors
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
test 'successful reading with one tag as symbol' do
|
130
|
-
run_in_temp_dir do
|
131
|
-
@reader.filenames = %w(a.jpg b.jpg c.jpg)
|
132
|
-
@reader.tags = :fnumber
|
133
|
-
res = @reader.read
|
134
|
-
assert_equal [5.6, 6.7, 8], res.map {|e| e.fnumber}
|
135
|
-
assert_equal %w(SourceFile FNumber), res.first.tags
|
136
|
-
assert_equal [], @reader.errors
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
test 'successful reading of hierarichal data' do
|
141
|
-
run_in_temp_dir do
|
142
|
-
@reader.filenames = %w(a.jpg)
|
143
|
-
@reader.tags = %w(fnumber)
|
144
|
-
@reader.group = 0
|
145
|
-
res = @reader.read.first
|
146
|
-
assert_equal 'a.jpg', res.source_file
|
147
|
-
assert_equal 5.6, res.exif.fnumber
|
148
|
-
assert_equal [], @reader.errors
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
test 'successful reading with user defined tags in config file' do
|
153
|
-
run_in_temp_dir do
|
154
|
-
@reader.filenames = %w(a.jpg b.jpg c.jpg)
|
155
|
-
@reader.tags = %w[mybasename]
|
156
|
-
res = @reader.read
|
157
|
-
assert_equal [nil, nil, nil], res.map(&:mybasename)
|
158
|
-
assert_equal [], @reader.errors
|
159
|
-
@reader.config = 'example.config'
|
160
|
-
res = @reader.read
|
161
|
-
assert_equal %w[a b c], res.map(&:mybasename)
|
162
|
-
assert_equal [], @reader.errors
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
end
|
167
|
-
|
168
|
-
end
|
data/test/test_values.rb
DELETED
@@ -1,202 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require_relative 'helper'
|
5
|
-
require 'date'
|
6
|
-
|
7
|
-
class TestValues < Test::Unit::TestCase
|
8
|
-
|
9
|
-
context 'value access' do
|
10
|
-
|
11
|
-
setup do
|
12
|
-
hash = {'FNumber' => 8, 'Author' => 'janfri'}
|
13
|
-
@values = MultiExiftool::Values.new(hash)
|
14
|
-
end
|
15
|
-
|
16
|
-
test 'original spelling of tag name' do
|
17
|
-
assert_equal 8, @values['FNumber']
|
18
|
-
end
|
19
|
-
|
20
|
-
test 'variant spellings of tag names' do
|
21
|
-
assert_equal 8, @values['fnumber']
|
22
|
-
assert_equal 8, @values['f_number']
|
23
|
-
assert_equal 8, @values['f-number']
|
24
|
-
end
|
25
|
-
|
26
|
-
test 'tag access via methods' do
|
27
|
-
assert_equal 8, @values.fnumber
|
28
|
-
assert_equal 8, @values.f_number
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
context 'parsing of values' do
|
34
|
-
|
35
|
-
context 'timestamps' do
|
36
|
-
|
37
|
-
setup do
|
38
|
-
hash = {
|
39
|
-
'TimestampWithoutSeconds' => '2009:08:25 12:35',
|
40
|
-
'Timestamp' => '2009:08:25 12:35:42',
|
41
|
-
'TimestampWithFraction' => '2009:08:25 12:35:42.123',
|
42
|
-
'TimestampWithPositiveZone' => '2009:08:26 20:22:24+05:00',
|
43
|
-
'TimestampWithNegativeZone' => '2009:08:26 20:22:24-07:00',
|
44
|
-
'TimestampWithFractionAndZone' => '2016:07:23 15:40:55.123+02:00',
|
45
|
-
'TimestampWithZoneAndDST' => '2016:07:23 15:40:55+02:00 DST',
|
46
|
-
'TimestampWithZ' => '2017:04:08 17:57:27Z',
|
47
|
-
'TimestampWithFractionAndZ' => '2017:04:08 17:57:27.123Z'
|
48
|
-
}
|
49
|
-
@values = MultiExiftool::Values.new(hash)
|
50
|
-
end
|
51
|
-
|
52
|
-
test 'local Time object' do
|
53
|
-
time = Time.local(2009, 8, 25, 12, 35)
|
54
|
-
assert_equal time, @values['TimestampWithoutSeconds']
|
55
|
-
time = Time.local(2009, 8, 25, 12, 35, 42)
|
56
|
-
assert_equal time, @values['Timestamp']
|
57
|
-
time = Time.local(2009, 8, 25, 12, 35, 42.123)
|
58
|
-
assert_equal time, @values['TimestampWithFraction']
|
59
|
-
end
|
60
|
-
|
61
|
-
test 'Time object with given zone' do
|
62
|
-
time = Time.new(2009, 8, 26, 20, 22, 24, '+05:00')
|
63
|
-
values_time = @values['TimestampWithPositiveZone']
|
64
|
-
assert_equal time, values_time
|
65
|
-
assert_equal 5 * 3600, values_time.utc_offset
|
66
|
-
time = Time.new(2009, 8, 26, 20, 22, 24, '-07:00')
|
67
|
-
values_time = @values['TimestampWithNegativeZone']
|
68
|
-
assert_equal time, values_time
|
69
|
-
assert_equal -7 * 3600, values_time.utc_offset
|
70
|
-
time = Time.new(2016, 7, 23, 15, 40, 55.123,'+02:00')
|
71
|
-
values_time = @values['TimestampWithFractionAndZone']
|
72
|
-
assert_equal time, values_time
|
73
|
-
end
|
74
|
-
|
75
|
-
test 'Time object with zone and DST' do
|
76
|
-
time = Time.new(2016, 7, 23, 15, 40, 55,'+02:00')
|
77
|
-
values_time = @values['TimestampWithZoneAndDST']
|
78
|
-
assert_equal time, values_time
|
79
|
-
end
|
80
|
-
|
81
|
-
test 'Time object with UTC zone' do
|
82
|
-
time = Time.new(2017, 4, 8, 17, 57, 27, '+00:00')
|
83
|
-
values_time = @values['TimestampWithZ']
|
84
|
-
assert_equal time, values_time
|
85
|
-
assert_equal 0, values_time.utc_offset
|
86
|
-
time = Time.new(2017, 4, 8, 17, 57, 27.123, '+00:00')
|
87
|
-
values_time = @values['TimestampWithFractionAndZ']
|
88
|
-
assert_equal time, values_time
|
89
|
-
assert_equal 0, values_time.utc_offset
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|
93
|
-
|
94
|
-
context 'other values' do
|
95
|
-
|
96
|
-
setup do
|
97
|
-
hash = {
|
98
|
-
'ShutterSpeed' => '1/200',
|
99
|
-
'PartOfSet' => '1/2',
|
100
|
-
'Track' => '1/5'
|
101
|
-
}
|
102
|
-
@values = MultiExiftool::Values.new(hash)
|
103
|
-
end
|
104
|
-
|
105
|
-
test 'rational values' do
|
106
|
-
assert_equal Rational(1, 200), @values['ShutterSpeed']
|
107
|
-
end
|
108
|
-
|
109
|
-
test 'no rational conversion' do
|
110
|
-
assert_equal '1/2', @values['PartOfSet']
|
111
|
-
assert_equal '1/5', @values['Track']
|
112
|
-
end
|
113
|
-
|
114
|
-
end
|
115
|
-
|
116
|
-
context 'invalid values' do
|
117
|
-
|
118
|
-
test 'timestamp with only zeros' do
|
119
|
-
values = MultiExiftool::Values.new('TimeWithOnlyZeros' => '0000:00:00 00:00:00')
|
120
|
-
assert_nil values['TimeWithOnlyZeros']
|
121
|
-
end
|
122
|
-
|
123
|
-
test 'timestamp with invalid data' do
|
124
|
-
ts = '2022:25:01 16:25'
|
125
|
-
values = MultiExiftool::Values.new('InvalidTimestamp' => ts)
|
126
|
-
assert_equal ts, values['InvalidTimestamp']
|
127
|
-
end
|
128
|
-
|
129
|
-
test 'rational with denominator zero' do
|
130
|
-
values = MultiExiftool::Values.new('DenominatorZero' => '1/0')
|
131
|
-
assert_equal '1/0', values['DenominatorZero']
|
132
|
-
end
|
133
|
-
|
134
|
-
end
|
135
|
-
|
136
|
-
end
|
137
|
-
|
138
|
-
context 'has_tag?' do
|
139
|
-
setup do
|
140
|
-
@hash = {'FNumber' => 8, 'Author' => 'janfri', 'E-MailAddress' => 'janfri26@gmail.com', 'DateTimeOriginal' => '2018:08:22 11:50:00'}
|
141
|
-
@values = MultiExiftool::Values.new(@hash)
|
142
|
-
end
|
143
|
-
|
144
|
-
test 'different formats as string' do
|
145
|
-
@hash.keys.each do |k|
|
146
|
-
assert_equal true, @values.has_tag?(k)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
test 'different formats as symbol' do
|
151
|
-
@hash.keys.each do |k|
|
152
|
-
assert_equal true, @values.has_tag?(k.to_sym)
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
test 'non existent key' do
|
157
|
-
['iso', 'ISO', :iso, :ISO].each do |t|
|
158
|
-
assert_equal false, @values.has_tag?(t)
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
context 'tags and to_h' do
|
164
|
-
|
165
|
-
setup do
|
166
|
-
@hash = {'FNumber' => 8, 'Author' => 'janfri', 'E-MailAddress' => 'janfri26@gmail.com', 'DateTimeOriginal' => '2017:02:20 21:07:00'}
|
167
|
-
@values = MultiExiftool::Values.new(@hash)
|
168
|
-
end
|
169
|
-
|
170
|
-
test 'tags preserves the original tag names' do
|
171
|
-
assert_equal @hash.keys, @values.tags.to_a
|
172
|
-
end
|
173
|
-
|
174
|
-
test 'to_h preserves original tag names but uses converted values' do
|
175
|
-
dto = Time.new(2017, 2, 20, 21, 7, 0)
|
176
|
-
@hash['DateTimeOriginal'] = dto
|
177
|
-
assert_equal @hash, @values.to_h
|
178
|
-
end
|
179
|
-
|
180
|
-
end
|
181
|
-
|
182
|
-
context 'respond_to_missing?' do
|
183
|
-
|
184
|
-
setup do
|
185
|
-
hash = {'FNumber' => 8, 'Author' => 'janfri'}
|
186
|
-
@values = MultiExiftool::Values.new(hash)
|
187
|
-
end
|
188
|
-
|
189
|
-
test 'existing keys' do
|
190
|
-
[:fnumber, :f_number, :FNumber, 'fnumber', 'f_number', 'FNumber', :author, :Author, 'author', 'Author'].each do |t|
|
191
|
-
assert_equal true, @values.respond_to?(t)
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
test 'non existing key' do
|
196
|
-
['iso', 'ISO', :iso, :ISO].each do |t|
|
197
|
-
assert_equal false, @values.respond_to?(t)
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
end
|
202
|
-
end
|