Skip to content

Commit

Permalink
revert tests
Browse files Browse the repository at this point in the history
  • Loading branch information
akash-akya committed Jan 3, 2025
1 parent faaa063 commit 7cba6ff
Showing 1 changed file with 46 additions and 144 deletions.
190 changes: 46 additions & 144 deletions test/vix/vips/image_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -72,45 +72,17 @@ defmodule Vix.Vips.ImageTest do
assert File.read!(img_buf_out_path) == File.read!(img_file_out_path)
end

describe "write_to_file" do
test "write_to_file", %{dir: dir} do
path = img_path("puppies.jpg")

{:ok, %Image{ref: ref} = im} = Image.new_from_file(path)
assert is_reference(ref)

out_path = Temp.path!(suffix: ".png", basedir: dir)
assert :ok == Image.write_to_file(im, out_path)

stat = File.stat!(out_path)
assert stat.size > 0 and stat.type == :regular
end

test "write_to_file supports optional arguments", %{dir: dir} do
{:ok, img} = Image.new_from_file(img_path("puppies.jpg"))

out_path1 = Temp.path!(suffix: ".png", basedir: dir)
assert :ok = Image.write_to_file(img, out_path1, compression: 0)

out_path2 = Temp.path!(suffix: ".png", basedir: dir)
assert :ok = Image.write_to_file(img, out_path2, compression: 9)

# currently I only found this option to be verifiable easily!
assert File.stat!(out_path1).size > File.stat!(out_path2).size
end

test "write_to_file supports optional options suffix", %{dir: dir} do
{:ok, img} = Image.new_from_file(img_path("puppies.jpg"))
test "write_to_file", %{dir: dir} do
path = img_path("puppies.jpg")

out_path1 = Temp.path!(suffix: ".png", basedir: dir)
assert :ok = Image.write_to_file(img, out_path1 <> "[compression=0]")
{:ok, %Image{ref: ref} = im} = Image.new_from_file(path)
assert is_reference(ref)

out_path2 = Temp.path!(suffix: ".png", basedir: dir)
assert :ok = Image.write_to_file(img, out_path2 <> "[compression=9]")
out_path = Temp.path!(suffix: ".png", basedir: dir)
assert :ok == Image.write_to_file(im, out_path)

# currently I only found this option to be verifiable easily!
assert File.stat!(out_path1).size > File.stat!(out_path2).size
end
stat = File.stat!(out_path)
assert stat.size > 0 and stat.type == :regular
end

test "new_matrix_from_array", %{dir: _dir} do
Expand Down Expand Up @@ -260,31 +232,9 @@ defmodule Vix.Vips.ImageTest do
assert 2 == Image.n_pages(im)
end

describe "write_to_buffer" do
test "write image to buffer", %{dir: _dir} do
{:ok, im} = Image.new_from_file(img_path("puppies.jpg"))
{:ok, _bin} = Image.write_to_buffer(im, ".jpg[Q=90]")
end

test "write_to_buffer supports optional arguments" do
{:ok, img} = Image.new_from_file(img_path("puppies.jpg"))

assert {:ok, bin1} = Image.write_to_buffer(img, ".png", compression: 0)
assert {:ok, bin2} = Image.write_to_buffer(img, ".png", compression: 9)

# currently I only found this option to be verifiable easily!
assert byte_size(bin1) > byte_size(bin2)
end

test "write_to_buffer supports optional options suffix" do
{:ok, img} = Image.new_from_file(img_path("puppies.jpg"))

assert {:ok, bin1} = Image.write_to_buffer(img, ".png[compression=0]")
assert {:ok, bin2} = Image.write_to_buffer(img, ".png[compression=9]")

# currently I only found this option to be verifiable easily!
assert byte_size(bin1) > byte_size(bin2)
end
test "write image to buffer", %{dir: _dir} do
{:ok, im} = Image.new_from_file(img_path("puppies.jpg"))
{:ok, _bin} = Image.write_to_buffer(im, ".jpg[Q=90]")
end

test "new image from other image", %{dir: _dir} do
Expand All @@ -304,101 +254,53 @@ defmodule Vix.Vips.ImageTest do
assert Image.has_alpha?(im)
end

describe "new_from_enum" do
test "new_from_enum", %{dir: dir} do
{:ok, image} =
File.stream!(img_path("puppies.jpg"), [], 1024)
|> Image.new_from_enum("")

out_path = Temp.path!(suffix: ".png", basedir: dir)
:ok = Image.write_to_file(image, out_path)

stat = File.stat!(out_path)
assert stat.size > 0 and stat.type == :regular
end

@tag capture_log: true
test "new_from_enum invalid data write" do
{:error, "Failed to find loader for the source"} = Image.new_from_enum(1..100)
end

test "premature end of new_from_enum" do
{:error, "Failed to create image from VipsSource"} =
File.stream!(img_path("puppies.jpg"), [], 100)
|> Stream.take(1)
|> Image.new_from_enum("")
end

test "passing options as keyword" do
{:ok, img1} = Image.new_from_file(img_path("puppies.jpg"))

{:ok, img2} =
File.stream!(img_path("puppies.jpg"), [], 1024)
|> Image.new_from_enum(shrink: 2)
test "new_from_enum", %{dir: dir} do
{:ok, image} =
File.stream!(img_path("puppies.jpg"), [], 1024)
|> Image.new_from_enum("")

assert Image.width(img1) == 2 * Image.width(img2)
end

test "passing options as string" do
{:ok, img1} = Image.new_from_file(img_path("puppies.jpg"))

{:ok, img2} =
File.stream!(img_path("puppies.jpg"), [], 1024)
|> Image.new_from_enum("[shrink=2]")
out_path = Temp.path!(suffix: ".png", basedir: dir)
:ok = Image.write_to_file(image, out_path)

assert Image.width(img1) == 2 * Image.width(img2)
end
stat = File.stat!(out_path)
assert stat.size > 0 and stat.type == :regular
end

describe "write_to_stream" do
test "write_to_stream", %{dir: dir} do
{:ok, im} = Image.new_from_file(img_path("puppies.jpg"))

out_path = Temp.path!(suffix: ".png", basedir: dir)

:ok =
Image.write_to_stream(im, ".png")
|> Stream.into(File.stream!(out_path))
|> Stream.run()

stat = File.stat!(out_path)
assert stat.size > 0 and stat.type == :regular
end

test "write_to_stream with invalid suffix", %{dir: dir} do
{:ok, im} = Image.new_from_file(img_path("puppies.jpg"))

out_path = Temp.path!(suffix: ".png", basedir: dir)

assert_raise Vix.Vips.Image.Error, fn ->
Image.write_to_stream(im, ".invalid")
|> Stream.into(File.stream!(out_path))
|> Stream.run()
end
end
@tag capture_log: true
test "new_from_enum invalid data write" do
{:error, _} = Image.new_from_enum(1..100)
end

test "passing options as keyword" do
{:ok, im} = Image.new_from_file(img_path("puppies.jpg"))
test "premature end of new_from_enum" do
{:error, "Failed to create image from VipsSource"} =
File.stream!(img_path("puppies.jpg"), [], 100)
|> Stream.take(1)
|> Image.new_from_enum("")
end

buf1 =
Image.write_to_stream(im, ".png", compression: 0)
|> Enum.into([])
test "write_to_stream", %{dir: dir} do
{:ok, im} = Image.new_from_file(img_path("puppies.jpg"))

{:ok, buf2} = Image.write_to_buffer(im, ".png", compression: 9)
out_path = Temp.path!(suffix: ".png", basedir: dir)

assert IO.iodata_length(buf1) > byte_size(buf2)
end
:ok =
Image.write_to_stream(im, ".png")
|> Stream.into(File.stream!(out_path))
|> Stream.run()

test "passing options as string" do
{:ok, im} = Image.new_from_file(img_path("puppies.jpg"))
stat = File.stat!(out_path)
assert stat.size > 0 and stat.type == :regular
end

buf1 =
Image.write_to_stream(im, ".png[compression=0]")
|> Enum.into([])
test "write_to_stream with invalid suffix", %{dir: dir} do
{:ok, im} = Image.new_from_file(img_path("puppies.jpg"))

{:ok, buf2} = Image.write_to_buffer(im, ".png", compression: 9)
out_path = Temp.path!(suffix: ".png", basedir: dir)

assert IO.iodata_length(buf1) > byte_size(buf2)
assert_raise Vix.Vips.Image.Error, fn ->
Image.write_to_stream(im, ".invalid")
|> Stream.into(File.stream!(out_path))
|> Stream.run()
end
end

Expand Down

0 comments on commit 7cba6ff

Please sign in to comment.