Skip to content

Commit

Permalink
Siwtch to briefly
Browse files Browse the repository at this point in the history
  • Loading branch information
akash-akya committed Jan 3, 2025
1 parent faaa063 commit ee8d8db
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 73 deletions.
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ defmodule Vix.MixProject do
{:dialyxir, "~> 1.4", only: [:dev], runtime: false},
{:ex_doc, ">= 0.0.0", only: :dev},
{:excoveralls, "~> 0.15", only: :test},
{:temp, "~> 0.4", only: :test, runtime: false}
{:briefly, "~> 0.5.0", only: :test}
]
end

Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
%{
"briefly": {:hex, :briefly, "0.5.1", "ee10d48da7f79ed2aebdc3e536d5f9a0c3e36ff76c0ad0d4254653a152b13a8a", [:mix], [], "hexpm", "bd684aa92ad8b7b4e0d92c31200993c4bc1469fc68cd6d5f15144041bd15cb57"},
"bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
"castore": {:hex, :castore, "1.0.10", "43bbeeac820f16c89f79721af1b3e092399b3a1ecc8df1a472738fd853574911", [:mix], [], "hexpm", "1b0b7ea14d889d9ea21202c43a4fa015eb913021cb535e8ed91946f4b77a8848"},
"cc_precompiler": {:hex, :cc_precompiler, "0.1.10", "47c9c08d8869cf09b41da36538f62bc1abd3e19e41701c2cea2675b53c704258", [:mix], [{:elixir_make, "~> 0.7", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "f6e046254e53cd6b41c6bacd70ae728011aa82b2742a80d6e2214855c6e06b22"},
Expand All @@ -18,5 +19,4 @@
"makeup_erlang": {:hex, :makeup_erlang, "1.0.1", "c7f58c120b2b5aa5fd80d540a89fdf866ed42f1f3994e4fe189abebeab610839", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "8a89a1eeccc2d798d6ea15496a6e4870b75e014d1af514b1b71fa33134f57814"},
"nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"},
"table": {:hex, :table, "0.1.2", "87ad1125f5b70c5dea0307aa633194083eb5182ec537efc94e96af08937e14a8", [:mix], [], "hexpm", "7e99bc7efef806315c7e65640724bf165c3061cdc5d854060f74468367065029"},
"temp": {:hex, :temp, "0.4.9", "eb6355bfa7925a568b3d9eb3bb57e89aa6d2b78bfe8dfb6b698e090631b7f41f", [:mix], [], "hexpm", "bc8bf7b27d9105bef933ef4bf4ba37ac6b899dbeba329deaa88c60b62d6b4b6d"},
}
78 changes: 36 additions & 42 deletions test/vix/vips/image_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ defmodule Vix.Vips.ImageTest do

doctest Image

setup do
Temp.track!()
dir = Temp.mkdir!()
{:ok, %{dir: dir}}
end

test "new_from_file" do
assert {:error, :invalid_path} == Image.new_from_file("invalid.jpg", [])
assert {:error, "Failed to find load"} == Image.new_from_file(__ENV__.file, [])
Expand Down Expand Up @@ -56,64 +50,64 @@ defmodule Vix.Vips.ImageTest do
assert is_reference(ref)
end

test "new_from_buffer", %{dir: dir} do
test "new_from_buffer" do
assert {:error, "Failed to find load buffer"} == Image.new_from_buffer(<<>>)

path = img_path("puppies.jpg")

assert {:ok, img_from_buf} = Image.new_from_buffer(File.read!(path))
img_buf_out_path = Temp.path!(suffix: ".png", basedir: dir)
img_buf_out_path = Briefly.create!(extname: ".png")
assert :ok == Image.write_to_file(img_from_buf, img_buf_out_path)

{:ok, img_from_file} = Image.new_from_file(path)
img_file_out_path = Temp.path!(suffix: ".png", basedir: dir)
img_file_out_path = Briefly.create!(extname: ".png")
assert :ok == Image.write_to_file(img_from_file, img_file_out_path)

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
test "write_to_file" 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)
out_path = Briefly.create!(extname: ".png")
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
test "write_to_file supports optional arguments" do
{:ok, img} = Image.new_from_file(img_path("puppies.jpg"))

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

out_path2 = Temp.path!(suffix: ".png", basedir: dir)
out_path2 = Briefly.create!(extname: ".png")
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
test "write_to_file supports optional options suffix" do
{:ok, img} = Image.new_from_file(img_path("puppies.jpg"))

out_path1 = Temp.path!(suffix: ".png", basedir: dir)
out_path1 = Briefly.create!(extname: ".png")
assert :ok = Image.write_to_file(img, out_path1 <> "[compression=0]")

out_path2 = Temp.path!(suffix: ".png", basedir: dir)
out_path2 = Briefly.create!(extname: ".png")
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
end

test "new_matrix_from_array", %{dir: _dir} do
test "new_matrix_from_array" do
assert {:ok, img} =
Image.new_matrix_from_array(2, 2, [
[-1, -1],
Expand All @@ -130,7 +124,7 @@ defmodule Vix.Vips.ImageTest do
end

describe "new_from_list" do
test "when argument is range", %{dir: _dir} do
test "when argument is range" do
assert {:ok, img} = Image.new_from_list(0..2)

assert %{width: 3, height: 1} = Image.headers(img)
Expand All @@ -139,7 +133,7 @@ defmodule Vix.Vips.ImageTest do
Image.write_to_binary(img)
end

test "when argument is range within list", %{dir: _dir} do
test "when argument is range within list" do
assert {:ok, img} = Image.new_from_list([0..1, -1..0])

assert %{width: 2, height: 2} = Image.headers(img)
Expand All @@ -151,7 +145,7 @@ defmodule Vix.Vips.ImageTest do
>>} = Image.write_to_binary(img)
end

test "when list is 1D", %{dir: _dir} do
test "when list is 1D" do
assert {:ok, img} = Image.new_from_list([0, 1, 2])

assert %{width: 3, height: 1} = Image.headers(img)
Expand All @@ -160,7 +154,7 @@ defmodule Vix.Vips.ImageTest do
Image.write_to_binary(img)
end

test "when list is 2D", %{dir: _dir} do
test "when list is 2D" do
assert {:ok, img} =
Image.new_from_list([
[1, 2, 3],
Expand All @@ -177,7 +171,7 @@ defmodule Vix.Vips.ImageTest do
end
end

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

{:ok, updated_image} =
Expand All @@ -190,7 +184,7 @@ defmodule Vix.Vips.ImageTest do
assert {:ok, 0} = Image.header_value(updated_image, "new-field")
end

test "get_fields", %{dir: _dir} do
test "get_fields" do
{:ok, im} = Image.new_from_file(img_path("puppies.jpg"))
assert {:ok, fields} = Image.header_field_names(im)

Expand All @@ -210,12 +204,12 @@ defmodule Vix.Vips.ImageTest do
)
end

test "get_header", %{dir: _dir} do
test "get_header" do
{:ok, im} = Image.new_from_file(img_path("puppies.jpg"))
assert {:ok, 518} = Image.header_value(im, "width")
end

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

assert %{
Expand All @@ -239,19 +233,19 @@ defmodule Vix.Vips.ImageTest do
} = Image.headers(im)
end

test "get_header binary", %{dir: _dir} do
test "get_header binary" do
{:ok, im} = Image.new_from_file(img_path("puppies.jpg"))
assert {:ok, <<_::binary>>} = Image.header_value(im, "exif-data")
end

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

assert {:ok, "((VipsInterpretation) VIPS_INTERPRETATION_sRGB)"} =
Image.header_value_as_string(im, "interpretation")
end

test "macro generated function", %{dir: _dir} do
test "macro generated function" do
{:ok, im} = Image.new_from_file(img_path("puppies.jpg"))
assert 518 == Image.width(im)
assert :VIPS_INTERPRETATION_sRGB == Image.interpretation(im)
Expand All @@ -261,7 +255,7 @@ defmodule Vix.Vips.ImageTest do
end

describe "write_to_buffer" do
test "write image to buffer", %{dir: _dir} do
test "write image to buffer" do
{:ok, im} = Image.new_from_file(img_path("puppies.jpg"))
{:ok, _bin} = Image.write_to_buffer(im, ".jpg[Q=90]")
end
Expand All @@ -287,7 +281,7 @@ defmodule Vix.Vips.ImageTest do
end
end

test "new image from other image", %{dir: _dir} do
test "new image from other image" do
{:ok, im} = Image.new_from_file(img_path("puppies.jpg"))
{:ok, new_im} = Image.new_from_image(im, [250])

Expand All @@ -296,7 +290,7 @@ defmodule Vix.Vips.ImageTest do
assert Image.bands(new_im) == 1
end

test "image has an alpha band", %{dir: _dir} do
test "image has an alpha band" do
{:ok, im} = Image.new_from_file(img_path("puppies.jpg"))
refute Image.has_alpha?(im)

Expand All @@ -305,12 +299,12 @@ defmodule Vix.Vips.ImageTest do
end

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

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

stat = File.stat!(out_path)
Expand Down Expand Up @@ -351,10 +345,10 @@ defmodule Vix.Vips.ImageTest do
end

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

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

:ok =
Image.write_to_stream(im, ".png")
Expand All @@ -365,10 +359,10 @@ defmodule Vix.Vips.ImageTest do
assert stat.size > 0 and stat.type == :regular
end

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

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

assert_raise Vix.Vips.Image.Error, fn ->
Image.write_to_stream(im, ".invalid")
Expand Down Expand Up @@ -402,7 +396,7 @@ defmodule Vix.Vips.ImageTest do
end
end

test "new_from_binary", %{dir: dir} do
test "new_from_binary" do
{:ok, im} = Image.new_from_file(img_path("puppies.jpg"))
# same image in raw pixel format
bin = File.read!(img_path("puppies.raw"))
Expand All @@ -416,7 +410,7 @@ defmodule Vix.Vips.ImageTest do
Image.format(im)
)

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

stat = File.stat!(out_path)
Expand Down Expand Up @@ -469,7 +463,7 @@ defmodule Vix.Vips.ImageTest do
end
end

test "new_from_binary and write_to_binary endianness handling", %{dir: dir} do
test "new_from_binary and write_to_binary endianness handling" do
{width, height} = {125, 125}

# generate a test pixel data in native endianness
Expand All @@ -486,7 +480,7 @@ defmodule Vix.Vips.ImageTest do
{:ok, expected} = Image.new_from_file(img_path("gradient.png"))
assert_images_equal(expected, img)

out_path = Temp.path!(suffix: ".v", basedir: dir)
out_path = Briefly.create!(extname: ".v")
:ok = Image.write_to_file(img, out_path)

{:ok, vimg} = Image.new_from_file(out_path)
Expand Down
10 changes: 2 additions & 8 deletions test/vix/vips/operation/helper_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ defmodule Vix.Vips.Operation.HelperTest do

import Vix.Support.Images

setup do
Temp.track!()
dir = Temp.mkdir!()
{:ok, %{dir: dir}}
end

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

assert {:ok, out} =
Expand All @@ -22,7 +16,7 @@ defmodule Vix.Vips.Operation.HelperTest do
extend: :VIPS_EXTEND_COPY
)

out_path = Temp.path!(suffix: ".jpg", basedir: dir)
out_path = Briefly.create!(extname: ".jpg")
:ok = Image.write_to_file(out, out_path)

assert_files_equal(img_path("gravity_puppies.jpg"), out_path)
Expand Down
Loading

0 comments on commit ee8d8db

Please sign in to comment.