Skip to content

Commit

Permalink
Fix test, return status, job, graph on run
Browse files Browse the repository at this point in the history
  • Loading branch information
tehPlayer committed Mar 11, 2021
1 parent 7c0d405 commit 7217223
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ erl_crash.dump
imageflow_ex-*.tar

native/imageflow_ex/target/
priv/
2 changes: 2 additions & 0 deletions lib/imageflow/graph.ex
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ defmodule Imageflow.Graph do
GraphRunner.run(graph)
end

def get_results(job, graph), do: GraphRunner.get_results(job, graph)

defp add_input(%{io_count: io_count, inputs: inputs} = graph, io_id, value) do
%{graph | io_count: io_count + 1, inputs: Map.put(inputs, io_id, value)}
end
Expand Down
13 changes: 5 additions & 8 deletions lib/imageflow/graph_runner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Imageflow.GraphRunner do
:ok <- add_outputs(job, graph.outputs),
:ok <- send_task(job, graph),
:ok <- save_outputs(job, graph.outputs) do
{:ok, job}
{:ok, job, graph}
end
end

Expand Down Expand Up @@ -52,13 +52,10 @@ defmodule Imageflow.GraphRunner do
defp add_outputs(job, inputs) do
inputs
|> Enum.reduce_while(:ok, fn
{id, value}, :ok ->
case value do
{:file, _path} -> Native.add_output_buffer(job, id)
:bytes -> Native.add_output_buffer(job, id)
end
|> case do
:ok -> {:cont, :ok}
{id, _}, :ok ->
with :ok <- Native.add_output_buffer(job, id) do
{:cont, :ok}
else
{:error, _} = error -> {:halt, error}
end
end)
Expand Down
52 changes: 35 additions & 17 deletions test/integration/graph_test.exs
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
defmodule Imageflow.Integration.GraphTest do
use ExUnit.Case

alias Imageflow.{Graph, Native}
alias Imageflow.{Graph, Native, Result}

@input_path "test/fixtures/elixir-logo.jpg"
@output_path "/tmp/output.png"

test "can pipe multiple operations" do
assert :ok =
Graph.new()
|> Graph.decode_file(@input_path)
|> Graph.constrain(20, 20)
|> Graph.rotate_270()
|> Graph.transpose()
|> Graph.color_filter("invert")
|> Graph.encode_to_file(@output_path)
|> Graph.run()
run_result =
Graph.new()
|> Graph.decode_file(@input_path)
|> Graph.constrain(20, 20)
|> Graph.rotate_270()
|> Graph.transpose()
|> Graph.color_filter("invert")
|> Graph.encode_to_file(@output_path)
|> Graph.run()

assert match?({:ok, _job, _graph}, run_result)
end

test "can generate multiple images" do
Expand Down Expand Up @@ -47,12 +49,28 @@ defmodule Imageflow.Integration.GraphTest do
end

test "can handle multiple operations" do
assert :ok =
Graph.new()
|> Graph.decode_file(@input_path)
|> Graph.flip_vertical()
|> Graph.transpose()
|> Graph.encode_to_file("/tmp/rotated.png")
|> Graph.run()
run_result =
Graph.new()
|> Graph.decode_file(@input_path)
|> Graph.flip_vertical()
|> Graph.transpose()
|> Graph.encode_to_file("/tmp/rotated.png")
|> Graph.run()

assert match?({:ok, _job, _graph}, run_result)
end

test "can encode to file" do
{:ok, job, graph} =
Graph.new()
|> Graph.decode_file(@input_path)
|> Graph.flip_vertical()
|> Graph.transpose()
|> Graph.encode_to_string()
|> Graph.run()

{:ok, %Result{} = results} = Graph.get_results(job, graph)

assert is_bitstring(results.output)
end
end

0 comments on commit 7217223

Please sign in to comment.