@@ -72,45 +72,17 @@ defmodule Vix.Vips.ImageTest do
72
72
assert File . read! ( img_buf_out_path ) == File . read! ( img_file_out_path )
73
73
end
74
74
75
- describe "write_to_file" do
76
- test "write_to_file" , % { dir: dir } do
77
- path = img_path ( "puppies.jpg" )
78
-
79
- { :ok , % Image { ref: ref } = im } = Image . new_from_file ( path )
80
- assert is_reference ( ref )
81
-
82
- out_path = Temp . path! ( suffix: ".png" , basedir: dir )
83
- assert :ok == Image . write_to_file ( im , out_path )
84
-
85
- stat = File . stat! ( out_path )
86
- assert stat . size > 0 and stat . type == :regular
87
- end
88
-
89
- test "write_to_file supports optional arguments" , % { dir: dir } do
90
- { :ok , img } = Image . new_from_file ( img_path ( "puppies.jpg" ) )
91
-
92
- out_path1 = Temp . path! ( suffix: ".png" , basedir: dir )
93
- assert :ok = Image . write_to_file ( img , out_path1 , compression: 0 )
94
-
95
- out_path2 = Temp . path! ( suffix: ".png" , basedir: dir )
96
- assert :ok = Image . write_to_file ( img , out_path2 , compression: 9 )
97
-
98
- # currently I only found this option to be verifiable easily!
99
- assert File . stat! ( out_path1 ) . size > File . stat! ( out_path2 ) . size
100
- end
101
-
102
- test "write_to_file supports optional options suffix" , % { dir: dir } do
103
- { :ok , img } = Image . new_from_file ( img_path ( "puppies.jpg" ) )
75
+ test "write_to_file" , % { dir: dir } do
76
+ path = img_path ( "puppies.jpg" )
104
77
105
- out_path1 = Temp . path! ( suffix: ".png" , basedir: dir )
106
- assert :ok = Image . write_to_file ( img , out_path1 <> "[compression=0]" )
78
+ { :ok , % Image { ref: ref } = im } = Image . new_from_file ( path )
79
+ assert is_reference ( ref )
107
80
108
- out_path2 = Temp . path! ( suffix: ".png" , basedir: dir )
109
- assert :ok = Image . write_to_file ( img , out_path2 <> "[compression=9]" )
81
+ out_path = Temp . path! ( suffix: ".png" , basedir: dir )
82
+ assert :ok == Image . write_to_file ( im , out_path )
110
83
111
- # currently I only found this option to be verifiable easily!
112
- assert File . stat! ( out_path1 ) . size > File . stat! ( out_path2 ) . size
113
- end
84
+ stat = File . stat! ( out_path )
85
+ assert stat . size > 0 and stat . type == :regular
114
86
end
115
87
116
88
test "new_matrix_from_array" , % { dir: _dir } do
@@ -260,31 +232,9 @@ defmodule Vix.Vips.ImageTest do
260
232
assert 2 == Image . n_pages ( im )
261
233
end
262
234
263
- describe "write_to_buffer" do
264
- test "write image to buffer" , % { dir: _dir } do
265
- { :ok , im } = Image . new_from_file ( img_path ( "puppies.jpg" ) )
266
- { :ok , _bin } = Image . write_to_buffer ( im , ".jpg[Q=90]" )
267
- end
268
-
269
- test "write_to_buffer supports optional arguments" do
270
- { :ok , img } = Image . new_from_file ( img_path ( "puppies.jpg" ) )
271
-
272
- assert { :ok , bin1 } = Image . write_to_buffer ( img , ".png" , compression: 0 )
273
- assert { :ok , bin2 } = Image . write_to_buffer ( img , ".png" , compression: 9 )
274
-
275
- # currently I only found this option to be verifiable easily!
276
- assert byte_size ( bin1 ) > byte_size ( bin2 )
277
- end
278
-
279
- test "write_to_buffer supports optional options suffix" do
280
- { :ok , img } = Image . new_from_file ( img_path ( "puppies.jpg" ) )
281
-
282
- assert { :ok , bin1 } = Image . write_to_buffer ( img , ".png[compression=0]" )
283
- assert { :ok , bin2 } = Image . write_to_buffer ( img , ".png[compression=9]" )
284
-
285
- # currently I only found this option to be verifiable easily!
286
- assert byte_size ( bin1 ) > byte_size ( bin2 )
287
- end
235
+ test "write image to buffer" , % { dir: _dir } do
236
+ { :ok , im } = Image . new_from_file ( img_path ( "puppies.jpg" ) )
237
+ { :ok , _bin } = Image . write_to_buffer ( im , ".jpg[Q=90]" )
288
238
end
289
239
290
240
test "new image from other image" , % { dir: _dir } do
@@ -304,101 +254,53 @@ defmodule Vix.Vips.ImageTest do
304
254
assert Image . has_alpha? ( im )
305
255
end
306
256
307
- describe "new_from_enum" do
308
- test "new_from_enum" , % { dir: dir } do
309
- { :ok , image } =
310
- File . stream! ( img_path ( "puppies.jpg" ) , [ ] , 1024 )
311
- |> Image . new_from_enum ( "" )
312
-
313
- out_path = Temp . path! ( suffix: ".png" , basedir: dir )
314
- :ok = Image . write_to_file ( image , out_path )
315
-
316
- stat = File . stat! ( out_path )
317
- assert stat . size > 0 and stat . type == :regular
318
- end
319
-
320
- @ tag capture_log: true
321
- test "new_from_enum invalid data write" do
322
- { :error , "Failed to find loader for the source" } = Image . new_from_enum ( 1 .. 100 )
323
- end
324
-
325
- test "premature end of new_from_enum" do
326
- { :error , "Failed to create image from VipsSource" } =
327
- File . stream! ( img_path ( "puppies.jpg" ) , [ ] , 100 )
328
- |> Stream . take ( 1 )
329
- |> Image . new_from_enum ( "" )
330
- end
331
-
332
- test "passing options as keyword" do
333
- { :ok , img1 } = Image . new_from_file ( img_path ( "puppies.jpg" ) )
334
-
335
- { :ok , img2 } =
336
- File . stream! ( img_path ( "puppies.jpg" ) , [ ] , 1024 )
337
- |> Image . new_from_enum ( shrink: 2 )
257
+ test "new_from_enum" , % { dir: dir } do
258
+ { :ok , image } =
259
+ File . stream! ( img_path ( "puppies.jpg" ) , [ ] , 1024 )
260
+ |> Image . new_from_enum ( "" )
338
261
339
- assert Image . width ( img1 ) == 2 * Image . width ( img2 )
340
- end
341
-
342
- test "passing options as string" do
343
- { :ok , img1 } = Image . new_from_file ( img_path ( "puppies.jpg" ) )
344
-
345
- { :ok , img2 } =
346
- File . stream! ( img_path ( "puppies.jpg" ) , [ ] , 1024 )
347
- |> Image . new_from_enum ( "[shrink=2]" )
262
+ out_path = Temp . path! ( suffix: ".png" , basedir: dir )
263
+ :ok = Image . write_to_file ( image , out_path )
348
264
349
- assert Image . width ( img1 ) == 2 * Image . width ( img2 )
350
- end
265
+ stat = File . stat! ( out_path )
266
+ assert stat . size > 0 and stat . type == :regular
351
267
end
352
268
353
- describe "write_to_stream" do
354
- test "write_to_stream" , % { dir: dir } do
355
- { :ok , im } = Image . new_from_file ( img_path ( "puppies.jpg" ) )
356
-
357
- out_path = Temp . path! ( suffix: ".png" , basedir: dir )
358
-
359
- :ok =
360
- Image . write_to_stream ( im , ".png" )
361
- |> Stream . into ( File . stream! ( out_path ) )
362
- |> Stream . run ( )
363
-
364
- stat = File . stat! ( out_path )
365
- assert stat . size > 0 and stat . type == :regular
366
- end
367
-
368
- test "write_to_stream with invalid suffix" , % { dir: dir } do
369
- { :ok , im } = Image . new_from_file ( img_path ( "puppies.jpg" ) )
370
-
371
- out_path = Temp . path! ( suffix: ".png" , basedir: dir )
372
-
373
- assert_raise Vix.Vips.Image.Error , fn ->
374
- Image . write_to_stream ( im , ".invalid" )
375
- |> Stream . into ( File . stream! ( out_path ) )
376
- |> Stream . run ( )
377
- end
378
- end
269
+ @ tag capture_log: true
270
+ test "new_from_enum invalid data write" do
271
+ { :error , "Failed to create image from VipsSource" } = Image . new_from_enum ( 1 .. 100 )
272
+ end
379
273
380
- test "passing options as keyword" do
381
- { :ok , im } = Image . new_from_file ( img_path ( "puppies.jpg" ) )
274
+ test "premature end of new_from_enum" do
275
+ { :error , "Failed to create image from VipsSource" } =
276
+ File . stream! ( img_path ( "puppies.jpg" ) , [ ] , 100 )
277
+ |> Stream . take ( 1 )
278
+ |> Image . new_from_enum ( "" )
279
+ end
382
280
383
- buf1 =
384
- Image . write_to_stream ( im , ".png" , compression: 0 )
385
- |> Enum . into ( [ ] )
281
+ test "write_to_stream" , % { dir: dir } do
282
+ { :ok , im } = Image . new_from_file ( img_path ( "puppies.jpg" ) )
386
283
387
- { :ok , buf2 } = Image . write_to_buffer ( im , ".png" , compression: 9 )
284
+ out_path = Temp . path! ( suffix: ".png" , basedir: dir )
388
285
389
- assert IO . iodata_length ( buf1 ) > byte_size ( buf2 )
390
- end
286
+ :ok =
287
+ Image . write_to_stream ( im , ".png" )
288
+ |> Stream . into ( File . stream! ( out_path ) )
289
+ |> Stream . run ( )
391
290
392
- test "passing options as string" do
393
- { :ok , im } = Image . new_from_file ( img_path ( "puppies.jpg" ) )
291
+ stat = File . stat! ( out_path )
292
+ assert stat . size > 0 and stat . type == :regular
293
+ end
394
294
395
- buf1 =
396
- Image . write_to_stream ( im , ".png[compression=0]" )
397
- |> Enum . into ( [ ] )
295
+ test "write_to_stream with invalid suffix" , % { dir: dir } do
296
+ { :ok , im } = Image . new_from_file ( img_path ( "puppies.jpg" ) )
398
297
399
- { :ok , buf2 } = Image . write_to_buffer ( im , ".png" , compression: 9 )
298
+ out_path = Temp . path! ( suffix: ".png" , basedir: dir )
400
299
401
- assert IO . iodata_length ( buf1 ) > byte_size ( buf2 )
300
+ assert_raise Vix.Vips.Image.Error , fn ->
301
+ Image . write_to_stream ( im , ".invalid" )
302
+ |> Stream . into ( File . stream! ( out_path ) )
303
+ |> Stream . run ( )
402
304
end
403
305
end
404
306
0 commit comments