Skip to content

Commit

Permalink
all tests run with Utils.inspect.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Nov 7, 2024
1 parent 7aca5e1 commit 79570ed
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 40 deletions.
8 changes: 4 additions & 4 deletions test/activity_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ActivityTest < Minitest::Spec
signal, (options,) = activity.([{}], start_task: L)

assert_equal signal, activity.outputs[:success].signal
assert_equal options.inspect, %{{:L=>1}}
assert_equal CU.inspect(options), %{{:L=>1}}
end

it "exposes {#to_h}" do
Expand All @@ -22,12 +22,12 @@ class ActivityTest < Minitest::Spec
assert_equal hsh[:outputs].collect{ |output| output.to_h[:semantic] }.inspect, %{[:success, :failure]}
assert_equal hsh[:nodes].class, Trailblazer::Activity::Schema::Nodes
assert_equal hsh[:nodes].collect { |id, attrs| attrs.id }.inspect, %{["Start.default", :B, :C, "End.success", "End.failure"]}
assert_equal hsh[:config].inspect, "{:wrap_static=>{}}"
assert_equal CU.inspect(hsh[:config]), "{:wrap_static=>{}}"
end

# TODO: test {to_h} properly
it "exposes {:data} attributes in {#to_h}" do
assert_equal bc.to_h[:nodes].values[1][:data].inspect, %{{:additional=>true}}
assert_equal CU.inspect(bc.to_h[:nodes].values[1][:data]), %{{:additional=>true}}
end

it "{:activity}" do
Expand Down Expand Up @@ -122,7 +122,7 @@ module Step
elsif ruby_version >= Gem::Version.new("3.2.0") && ruby_version <= Gem::Version.new("3.2.6")
require "trailblazer/activity/circuit/ruby_with_unfixed_compaction"
Trailblazer::Activity::Circuit.prepend(Trailblazer::Activity::Circuit::RubyWithUnfixedCompaction)
elsif ruby_version >= Gem::Version.new("3.3.0") && ruby_version <= Gem::Version.new("3.3.6")
elsif ruby_version >= Gem::Version.new("3.3.0") #&& ruby_version <= Gem::Version.new("3.3.6")
require "trailblazer/activity/circuit/ruby_with_unfixed_compaction"
Trailblazer::Activity::Circuit.prepend(Trailblazer::Activity::Circuit::RubyWithUnfixedCompaction)
end
Expand Down
6 changes: 3 additions & 3 deletions test/circuit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CircuitTest < Minitest::Spec

last_signal, (ctx, i, j, *bla) = circuit.([ctx, 1, 2], task: Start)

assert_equal ctx.inspect, %{{:start=>1, :a=>2, :b=>3, :_end=>4}}
assert_equal CU.inspect(ctx), %{{:start=>1, :a=>2, :b=>3, :_end=>4}}
assert_equal last_signal, "the end"
assert_equal i, 1
assert_equal j, 2
Expand Down Expand Up @@ -76,7 +76,7 @@ class CircuitTest < Minitest::Spec

last_signal, (ctx, i, j, *bla) = outer.([ctx, {}, 2], task: Start)

assert_equal ctx.inspect, %{{:start=>1, :a=>2, :c=>6, :_end=>4, :b=>3}}
assert_equal CU.inspect(ctx), %{{:start=>1, :a=>2, :c=>6, :_end=>4, :b=>3}}
assert_equal last_signal, "the end"
assert_equal i,({})
assert_equal j, 2
Expand All @@ -89,7 +89,7 @@ class CircuitTest < Minitest::Spec

last_signal, (ctx, flow_options, j, *bla) = outer.([ctx, flow_options, 2], task: Start, runner: MyRunner)

assert_equal ctx.inspect, %{{:start=>1, :a=>2, :c=>6, :_end=>4, :b=>3}}
assert_equal CU.inspect(ctx), %{{:start=>1, :a=>2, :c=>6, :_end=>4, :b=>3}}
assert_equal last_signal, "the end"
assert_equal flow_options, { stack: [Start, A, nestable, Start, C, End, B, End], runner: MyRunner }
assert_equal j, 2
Expand Down
12 changes: 6 additions & 6 deletions test/intermediate_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ def self.b_task((ctx, flow_options), **)
#<End/:failure>
)

assert_equal schema[:outputs].inspect, %{[#<struct Trailblazer::Activity::Output signal=#<Trailblazer::Activity::End semantic=:success>, semantic=:success>, #<struct Trailblazer::Activity::Output signal=#<Trailblazer::Activity::End semantic=:failure>, semantic=:failure>]}
assert_equal CU.inspect(schema[:outputs]), %{[#<struct Trailblazer::Activity::Output signal=#<Trailblazer::Activity::End semantic=:success>, semantic=:success>, #<struct Trailblazer::Activity::Output signal=#<Trailblazer::Activity::End semantic=:failure>, semantic=:failure>]}

# :extension API
# test it works with and without [bla_ext], and more than one per line
assert_equal schema[:config].inspect, %{{:wrap_static=>{}, :b1=>false, :a1=>true, :a2=>:yo}}
assert_equal CU.inspect(schema[:config]), %{{:wrap_static=>{}, :b1=>false, :a1=>true, :a2=>:yo}}

assert_invoke Activity.new(schema), seq: "[:a, :b, :d]"
assert_invoke Activity.new(schema), b: false, seq: "[:a, :b, :c]", terminus: :failure
Expand Down Expand Up @@ -108,7 +108,7 @@ def call((ctx, flow_options), **)

schema = Inter::Compiler.(intermediate, implementation)

assert_equal schema[:outputs].inspect, %{[#<struct Trailblazer::Activity::Output signal=#<IntermediateTest::D::End semantic=:win>, semantic=:win>, #<struct Trailblazer::Activity::Output signal=#<Trailblazer::Activity::End semantic=:success>, semantic=:success>]}
assert_equal CU.inspect(schema[:outputs]), %{[#<struct Trailblazer::Activity::Output signal=#<IntermediateTest::D::End semantic=:win>, semantic=:win>, #<struct Trailblazer::Activity::Output signal=#<Trailblazer::Activity::End semantic=:success>, semantic=:success>]}

assert_circuit schema, %{
#<Start/:default>
Expand Down Expand Up @@ -164,21 +164,21 @@ def implementation(c_extensions)

schema = Inter::Compiler.(intermediate, implementation([ext_a, ext_b, ext_d, ext_e]))

assert_equal schema[:config].to_h.inspect, %{{:wrap_static=>{}, :a=>\"bla\", :b=>\"blubb\", :C=>1, :e=>2}}
assert_equal CU.inspect(schema[:config].to_h), %{{:wrap_static=>{}, :a=>\"bla\", :b=>\"blubb\", :C=>1, :e=>2}}
end

# {Implementation.call()} allows to pass {config} data
describe "{Implementation.call()}" do
it "accepts {config_merge:} data that is merged into {config}" do
schema = Inter::Compiler.(intermediate, implementation([]), config_merge: {beer: "yes"})

assert_equal schema[:config].to_h.inspect, %{{:wrap_static=>{}, :beer=>\"yes\"}}
assert_equal CU.inspect(schema[:config].to_h), %{{:wrap_static=>{}, :beer=>\"yes\"}}
end

it "{:config_merge} overrides values in {default_config}" do
schema = Inter::Compiler.(intermediate, implementation([]), config_merge: {beer: "yes", wrap_static: "yo"})

assert_equal schema[:config].to_h.inspect, %{{:wrap_static=>"yo", :beer=>\"yes\"}}
assert_equal CU.inspect(schema[:config].to_h), %{{:wrap_static=>"yo", :beer=>\"yes\"}}
end
end
end
Expand Down
20 changes: 10 additions & 10 deletions test/task_adapter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ def process_type(ctx, model:, **)
return_value, ctx = circuit_step.([ctx, flow_options], **circuit_options)

assert_nil return_value
assert_equal ctx.inspect, %{{:model=>nil}}
assert_equal CU.inspect(ctx), %{{:model=>nil}}


#@ execute step-option in a circuit-interface environment
circuit_step = Activity::Circuit.Step(step, option: true) # wrap step with Trailblazer::Option
return_value, ctx = circuit_step.([ctx, flow_options], **circuit_options, exec_context: self)
assert_nil return_value
assert_equal ctx.inspect, %{{:model=>nil}}
assert_equal CU.inspect(ctx), %{{:model=>nil}}

circuit_step = Activity::Circuit::Step(:process_type, option: true) # wrap step with Trailblazer::Option
return_value, ctx = circuit_step.([ctx, flow_options], **circuit_options, exec_context: Operation.new)
assert_nil return_value
assert_equal ctx.inspect, %{{:model=>nil}}
assert_equal CU.inspect(ctx), %{{:model=>nil}}

#@ circuit-interface Option-compatible Step that does a Binary signal decision
step = :process_type
Expand All @@ -53,21 +53,21 @@ def process_type(ctx, model:, **)
signal, (ctx, flow_options) = circuit_task.([ctx, flow_options], **circuit_options, exec_context: Operation.new)

assert_equal signal, Trailblazer::Activity::Left
assert_equal ctx.inspect, %{{:model=>nil}}
assert_equal CU.inspect(ctx), %{{:model=>nil}}
assert_equal flow_options.inspect, %{{}}

ctx = {model: Object}
signal, (ctx, flow_options) = circuit_task.([ctx, flow_options], **circuit_options, exec_context: Operation.new)

assert_equal signal, Trailblazer::Activity::Right
assert_equal ctx.inspect, %{{:model=>Object, :type=>Class}}
assert_equal CU.inspect(ctx), %{{:model=>Object, :type=>Class}}
assert_equal flow_options.inspect, %{{}}

ctx = {model: nil}
signal, (ctx, flow_options) = circuit_task.([ctx, flow_options], **circuit_options, exec_context: Operation.new)

assert_equal signal, Trailblazer::Activity::Left
assert_equal ctx.inspect, %{{:model=>nil}}
assert_equal CU.inspect(ctx), %{{:model=>nil}}
assert_equal flow_options.inspect, %{{}}

#@ pipeline-interface
Expand All @@ -80,7 +80,7 @@ def process_type(ctx, model:, **)
pipeline_task = Activity::TaskWrap::Pipeline::TaskAdapter.for_step(step) # Task receives circuit-interface but it's compatible with Pipeline interface
wrap_ctx, args = pipeline_task.(ctx, args) # that's how pipeline tasks are called in {TaskWrap::Pipeline}.

assert_equal wrap_ctx.inspect, %{{:model=>Object, :type=>Class}}
assert_equal CU.inspect(wrap_ctx), %{{:model=>Object, :type=>Class}}
assert_equal args, [1,2]
end

Expand All @@ -103,7 +103,7 @@ def process_type(ctx, model:, **)
signal, (ctx, flow_options) = task_adapter.([{model: Object}, {}], exec_context: Operation.new)

assert_equal signal, Trailblazer::Activity::Right
assert_equal ctx.inspect, %{{:model=>Object, :type=>Class}}
assert_equal CU.inspect(ctx), %{{:model=>Object, :type=>Class}}
assert_equal flow_options.inspect, %{{}}
end

Expand All @@ -124,14 +124,14 @@ def process_type(ctx, model:, **)
signal, (ctx, flow_options) = circuit_task.([ctx, {}], **{exec_context: nil})

assert_equal signal, Trailblazer::Activity::Right
assert_equal ctx.inspect, %{{:mode=>Object, :nested_activity=>Object}}
assert_equal CU.inspect(ctx), %{{:mode=>Object, :nested_activity=>Object}}

#@ returning false
ctx = {mode: false}
signal, (ctx, flow_options) = circuit_task.([ctx, {}], **{exec_context: nil})

assert_equal signal, Trailblazer::Activity::Left
assert_equal ctx.inspect, %{{:mode=>false, :nested_activity=>false}}
assert_equal CU.inspect(ctx), %{{:mode=>false, :nested_activity=>false}}
end

end
4 changes: 4 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ def assert_equal(asserted, expected, *args)

Minitest::Spec.class_eval do
include Fixtures


require "trailblazer/core"
CU = Trailblazer::Core::Utils
end
24 changes: 12 additions & 12 deletions test/testing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ def call
#@ {#assert_call} returns ctx
it {
ctx = assert_call activity, seq: "[:b, :c]"
assert_equal ctx.inspect, %{{:seq=>[:b, :c]}}
assert_equal Trailblazer::Core::Utils.inspect(ctx), %{{:seq=>[:b, :c]}}
}

#0006
#@ {#assert_call} allows injecting {**ctx_variables}.
it {
ctx = assert_call activity, seq: "[:b, :c]", current_user: Module
assert_equal ctx.inspect, %{{:seq=>[:b, :c], :current_user=>Module}}
assert_equal Trailblazer::Core::Utils.inspect(ctx), %{{:seq=>[:b, :c], :current_user=>Module}}
}
end

Expand Down Expand Up @@ -85,8 +85,8 @@ def call
@@ -1,3 +1,3 @@
# encoding: US-ASCII
# valid: true
-\"{:seq=>[:xxxxxx]}\"
+\"{:seq=>[:b, :c]}\"
-\"#{{:seq => [:xxxxxx]}}\"
+\"#{{:seq=>[:b, :c]}}\"
}

assert_equal 1, failures.size
Expand All @@ -108,7 +108,7 @@ def call

# b step adding additional ctx variables.
def self.b((ctx, flow_options), **)
ctx[:from_b] = "hello, from b!"
ctx[:from_b] = 1
return Trailblazer::Activity::Right, [ctx, flow_options]
end
end
Expand All @@ -118,11 +118,11 @@ def self.b((ctx, flow_options), **)

#0001
#@ we can provide additional {:expected_ctx_variables}.
it { assert_call activity, seq: "[:c]", expected_ctx_variables: {from_b: "hello, from b!"} }
it { assert_call activity, seq: "[:c]", expected_ctx_variables: {from_b: 1} }

#0002
#@ wrong {:expected_ctx_variables} fails
it { assert_call activity, seq: "[:c]", expected_ctx_variables: {from_b: "hello, absolutely not from b!"} }
it { assert_call activity, seq: "[:c]", expected_ctx_variables: {from_b: 2} }
end

test_case = test.new(:test_0001_anonymous)
Expand All @@ -137,8 +137,8 @@ def self.b((ctx, flow_options), **)
@@ -1,3 +1,3 @@
# encoding: US-ASCII
# valid: true
-\"{:seq=>[:c], :from_b=>\\\"hello, absolutely not from b!\\\"}\"
+\"{:seq=>[:c], :from_b=>\\\"hello, from b!\\\"}\"
-\"#{{:seq=>[:c], :from_b=>2}}\"
+\"#{{:seq=>[:c], :from_b=>1}}\"
}
end

Expand Down Expand Up @@ -201,8 +201,8 @@ def invisible
signal, (ctx, flow_options) = assert_invoke activity, seq: "[:call]", flow_options: {start: "yes"}

assert_equal signal.inspect, %(#<Trailblazer::Activity::End semantic=:success>)
assert_equal ctx.inspect, %({:seq=>[:call]})
assert_equal flow_options.inspect, %({:start=>\"yes\"})
assert_equal Trailblazer::Core::Utils.inspect(ctx), %({:seq=>[:call]})
assert_equal Trailblazer::Core::Utils.inspect(flow_options), %({:start=>\"yes\"})
}

# #0002
Expand All @@ -221,7 +221,7 @@ def invisible
# #@ {#assert_call} returns ctx
# it {
# ctx = assert_call activity, seq: "[:b, :c]"
# assert_equal ctx.inspect, %{{:seq=>[:b, :c]}}
# assert_equal Trailblazer::Core::Utils.inspect(ctx), %{{:seq=>[:b, :c]}}
# }

# #0006
Expand Down
10 changes: 5 additions & 5 deletions test/wrap/task_wrap_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,30 +215,30 @@ def change_start_task(wrap_ctx, original_args)
it "accepts {:wrap_static} option" do
host_activity = Activity::TaskWrap.container_activity_for(Object, wrap_static: {a: 1})

assert_equal host_activity.inspect, "{:config=>{:wrap_static=>{Object=>{:a=>1}}}, :nodes=>{Object=>#<struct Trailblazer::Activity::Schema::Nodes::Attributes id=nil, task=Object, data=nil, outputs=nil>}}"
assert_equal CU.inspect(host_activity), "{:config=>{:wrap_static=>{Object=>{:a=>1}}}, :nodes=>{Object=>#<struct Trailblazer::Activity::Schema::Nodes::Attributes id=nil, task=Object, data=nil, outputs=nil>}}"
end

it "if {:wrap_static} not given it adds {#initial_wrap_static}" do
host_activity = Activity::TaskWrap.container_activity_for(Object)

assert_equal host_activity.inspect, "{:config=>{:wrap_static=>{Object=>#{Activity::TaskWrap.initial_wrap_static.inspect}}}, :nodes=>{Object=>#<struct Trailblazer::Activity::Schema::Nodes::Attributes id=nil, task=Object, data=nil, outputs=nil>}}"
assert_equal CU.inspect(host_activity), "{:config=>{:wrap_static=>{Object=>#{Activity::TaskWrap.initial_wrap_static.inspect}}}, :nodes=>{Object=>#<struct Trailblazer::Activity::Schema::Nodes::Attributes id=nil, task=Object, data=nil, outputs=nil>}}"
end

it "accepts additional options for {:config}, e.g. {each: true}" do
host_activity = Activity::TaskWrap.container_activity_for(Object, each: true)

assert_equal host_activity.inspect, "{:config=>{:wrap_static=>{Object=>#{Activity::TaskWrap.initial_wrap_static.inspect}}, :each=>true}, :nodes=>{Object=>#<struct Trailblazer::Activity::Schema::Nodes::Attributes id=nil, task=Object, data=nil, outputs=nil>}}"
assert_equal CU.inspect(host_activity), "{:config=>{:wrap_static=>{Object=>#{Activity::TaskWrap.initial_wrap_static.inspect}}, :each=>true}, :nodes=>{Object=>#<struct Trailblazer::Activity::Schema::Nodes::Attributes id=nil, task=Object, data=nil, outputs=nil>}}"

# allows mixing
host_activity = Activity::TaskWrap.container_activity_for(Object, each: true, wrap_static: {a: 1})

assert_equal host_activity.inspect, "{:config=>{:wrap_static=>{Object=>{:a=>1}}, :each=>true}, :nodes=>{Object=>#<struct Trailblazer::Activity::Schema::Nodes::Attributes id=nil, task=Object, data=nil, outputs=nil>}}"
assert_equal CU.inspect(host_activity), "{:config=>{:wrap_static=>{Object=>{:a=>1}}, :each=>true}, :nodes=>{Object=>#<struct Trailblazer::Activity::Schema::Nodes::Attributes id=nil, task=Object, data=nil, outputs=nil>}}"
end

it "accepts {:id}" do
host_activity = Activity::TaskWrap.container_activity_for(Object, id: :OBJECT)

assert_equal host_activity.inspect, "{:config=>{:wrap_static=>{Object=>#{Activity::TaskWrap.initial_wrap_static.inspect}}}, :nodes=>{Object=>#<struct Trailblazer::Activity::Schema::Nodes::Attributes id=:OBJECT, task=Object, data=nil, outputs=nil>}}"
assert_equal CU.inspect(host_activity), "{:config=>{:wrap_static=>{Object=>#{Activity::TaskWrap.initial_wrap_static.inspect}}}, :nodes=>{Object=>#<struct Trailblazer::Activity::Schema::Nodes::Attributes id=:OBJECT, task=Object, data=nil, outputs=nil>}}"
end
end # {TaskWrap.container_activity_for}
end

0 comments on commit 79570ed

Please sign in to comment.