Skip to content

Commit

Permalink
Add tests for bonds and APD
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp committed Nov 2, 2021
1 parent 7b1bd73 commit a8f1553
Show file tree
Hide file tree
Showing 2 changed files with 234 additions and 6 deletions.
12 changes: 6 additions & 6 deletions test/ExpressionExplorer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,10 @@ Some of these @test_broken lines are commented out to prevent printing to the te
@test testee(:(Base.@kwdef struct A; x = 1; y::Int = two; z end), [], [], [], [], [[:Base, Symbol("@kwdef")]])
@test testee(quote "asdf" f(x) = x end, [], [], [], [], [Symbol("@doc")])

@test testee(:(@bind a b), [:b, :PlutoRunner, :Base, :Core], [:a], [[:PlutoRunner, :Bond], [:Core, :applicable], [:Base, :get]], [], [Symbol("@bind")])
@test testee(:(PlutoRunner.@bind a b), [:b, :PlutoRunner, :Base, :Core], [:a], [[:PlutoRunner, :Bond], [:Core, :applicable], [:Base, :get]], [], [[:PlutoRunner, Symbol("@bind")]])
@test_broken testee(:(Main.PlutoRunner.@bind a b), [:b, :PlutoRunner, :Base, :Core], [:a], [[:Base, :get], [:Core, :applicable], [:PlutoRunner, :Bond], [:PlutoRunner, Symbol("@bind")]], [], verbose=false)
@test testee(:(let @bind a b end), [:b, :PlutoRunner, :Base, :Core], [:a], [[:PlutoRunner, :Bond], [:Core, :applicable], [:Base, :get]], [], [Symbol("@bind")])
@test testee(:(@bind a b), [:b, :PlutoRunner, :Base, :Core], [:a], [[:PlutoRunner, :create_bond], [:Core, :applicable], [:Base, :get]], [], [Symbol("@bind")])
@test testee(:(PlutoRunner.@bind a b), [:b, :PlutoRunner, :Base, :Core], [:a], [[:PlutoRunner, :create_bond], [:Core, :applicable], [:Base, :get]], [], [[:PlutoRunner, Symbol("@bind")]])
@test_broken testee(:(Main.PlutoRunner.@bind a b), [:b, :PlutoRunner, :Base, :Core], [:a], [[:Base, :get], [:Core, :applicable], [:PlutoRunner, :create_bond], [:PlutoRunner, Symbol("@bind")]], [], verbose=false)
@test testee(:(let @bind a b end), [:b, :PlutoRunner, :Base, :Core], [:a], [[:PlutoRunner, :create_bond], [:Core, :applicable], [:Base, :get]], [], [Symbol("@bind")])

@test testee(:(@asdf a = x1 b = x2 c = x3), [], [], [], [], [Symbol("@asdf")]) # https://github.com/fonsp/Pluto.jl/issues/670

Expand All @@ -468,8 +468,8 @@ Some of these @test_broken lines are commented out to prevent printing to the te
@test testee(:(Pack.@asdf a[1,k[j]] := log(x[i]/y[j])), [], [], [], [], [[:Pack, Symbol("@asdf")]])

@test testee(:(`hey $(a = 1) $(b)`), [:b], [], [:cmd_gen], [], [Symbol("@cmd")])
@test testee(:(md"hey $(@bind a b) $(a)"), [:b, :PlutoRunner, :Base, :Core], [:a], [[:PlutoRunner, :Bond], [:Core, :applicable], [:Base, :get], :getindex], [], [Symbol("@md_str"), Symbol("@bind")])
@test testee(:(md"hey $(a) $(@bind a b)"), [:a, :b, :PlutoRunner, :Base, :Core], [:a], [[:PlutoRunner, :Bond], [:Core, :applicable], [:Base, :get], :getindex], [], [Symbol("@md_str"), Symbol("@bind")])
@test testee(:(md"hey $(@bind a b) $(a)"), [:b, :PlutoRunner, :Base, :Core], [:a], [[:PlutoRunner, :create_bond], [:Core, :applicable], [:Base, :get], :getindex], [], [Symbol("@md_str"), Symbol("@bind")])
@test testee(:(md"hey $(a) $(@bind a b)"), [:a, :b, :PlutoRunner, :Base, :Core], [:a], [[:PlutoRunner, :create_bond], [:Core, :applicable], [:Base, :get], :getindex], [], [Symbol("@md_str"), Symbol("@bind")])
@test testee(:(html"a $(b = c)"), [], [], [], [], [Symbol("@html_str")])
@test testee(:(md"a $(b = c) $(b)"), [:c], [:b], [:getindex], [], [Symbol("@md_str")])
@test testee(:(md"\* $r"), [:r], [], [:getindex], [], [Symbol("@md_str")])
Expand Down
228 changes: 228 additions & 0 deletions test/RichOutput.jl
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,234 @@ import Pluto: update_run!, WorkspaceManager, ClientSession, ServerSession, Noteb
end
end

@testset "AbstractPlutoDingetjes.jl" begin
🍭.options.evaluation.workspace_use_distributed = true
notebook = Notebook([
Cell("""
begin
import Pkg
try
Pkg.UPDATED_REGISTRY_THIS_SESSION[] = true
catch; end
Pkg.activate(mktempdir())
Pkg.add(Pkg.PackageSpec(name="AbstractPlutoDingetjes", rev="0494e5a"))
import AbstractPlutoDingetjes as APD
import AbstractPlutoDingetjes.Bonds
end
"""),
Cell("""
begin
struct HTMLShower
f::Function
end
Base.show(io::IO, m::MIME"text/html", hs::HTMLShower) = hs.f(io)
end
"""),
Cell("""
APD.is_inside_pluto()
"""),
Cell("""
HTMLShower() do io
write(io, string(APD.is_inside_pluto(io)))
end
"""),
Cell("""
HTMLShower() do io
write(io, string(APD.is_supported_by_display(io, Bonds.initial_value)))
end
"""),
Cell("""
HTMLShower() do io
write(io, string(APD.is_supported_by_display(io, Bonds.transform_value)))
end
"""),
Cell("""
HTMLShower() do io
write(io, string(APD.is_supported_by_display(io, Bonds.validate_value)))
end
"""),
Cell("""
HTMLShower() do io
write(io, string(APD.is_supported_by_display(io, sqrt)))
end
"""),
Cell("""
@bind x_simple html"<input type=range>"
"""),
Cell("""
x_simple
"""),
Cell("""
begin
struct OldSlider end
Base.show(io::IO, m::MIME"text/html", os::OldSlider) = write(io, "<input type=range value=1>")
Base.get(os::OldSlider) = 1
end
"""),
Cell("""
@bind x_old OldSlider()
"""),
Cell("""
x_old
"""),
Cell("""
begin
struct NewSlider end
Base.show(io::IO, m::MIME"text/html", os::NewSlider) = write(io, "<input type=range value=1>")
Bonds.initial_value(os::NewSlider) = 1
end
"""),
Cell("""
@bind x_new NewSlider()
"""),
Cell("""
x_new
"""),
Cell("""
begin
struct TransformSlider end
Base.show(io::IO, m::MIME"text/html", os::TransformSlider) = write(io, "<input type=range value=1>")
Bonds.initial_value(os::TransformSlider) = "x"
Bonds.transform_value(os::TransformSlider, from_js) = repeat("x", from_js)
end
"""),
Cell("""
@bind x_transform TransformSlider()
"""),
Cell("""
x_transform
"""),
Cell("""
begin
struct BadTransformSlider end
Base.show(io::IO, m::MIME"text/html", os::BadTransformSlider) = write(io, "<input type=range value=1>")
Bonds.initial_value(os::BadTransformSlider) = "x"
Bonds.transform_value(os::BadTransformSlider, from_js) = repeat("x", from_js)
end
"""),
Cell("""
@bind x_badtransform BadTransformSlider()
"""),
Cell("""
x_badtransform
"""),
Cell("""
count = Ref(0)
"""),
Cell("""
@bind x_counter NewSlider() #or OldSlider(), same idea
"""),
Cell("""
let
x_counter
count[] += 1
end
"""),
])
fakeclient.connected_notebook = notebook

update_run!(🍭, notebook, notebook.cells)

@test noerror(notebook.cells[1])
@test noerror(notebook.cells[2])
@test noerror(notebook.cells[3])
@test noerror(notebook.cells[4])
@test noerror(notebook.cells[5])
@test noerror(notebook.cells[6])
@test noerror(notebook.cells[7])
@test noerror(notebook.cells[8])

@test notebook.cells[3].output.body == "true"
@test notebook.cells[4].output.body == "true"
@test notebook.cells[5].output.body == "true"
@test notebook.cells[6].output.body == "true"
@test notebook.cells[7].output.body == "false"
@test notebook.cells[8].output.body == "false"




@test noerror(notebook.cells[9])
@test noerror(notebook.cells[10])
@test noerror(notebook.cells[11])
@test noerror(notebook.cells[12])
@test noerror(notebook.cells[13])
@test noerror(notebook.cells[14])
@test noerror(notebook.cells[15])
@test noerror(notebook.cells[16])
@test noerror(notebook.cells[17])
@test noerror(notebook.cells[18])
@test noerror(notebook.cells[19])
@test noerror(notebook.cells[20])
@test noerror(notebook.cells[21])
@test noerror(notebook.cells[22])
@test noerror(notebook.cells[23])
@test noerror(notebook.cells[24])
@test noerror(notebook.cells[25])


function set_bond_value(name, value, is_first_value=false)
notebook.bonds[name] = Dict("value" => value, "is_first_value" => is_first_value)
Pluto.set_bond_values_reactive(;
session=🍭,
notebook=notebook,
bound_sym_names=[name],
run_async=false,
)
end


@test notebook.cells[10].output.body == "missing"
set_bond_value(:x_simple, 1, true)
@test notebook.cells[10].output.body == "1"


@test notebook.cells[13].output.body == "1"
set_bond_value(:x_old, 1, true)
@test notebook.cells[13].output.body == "1"
set_bond_value(:x_old, 99, false)
@test notebook.cells[13].output.body == "99"


@test notebook.cells[16].output.body == "1"
set_bond_value(:x_new, 1, true)
@test notebook.cells[16].output.body == "1"
set_bond_value(:x_new, 99, false)
@test notebook.cells[16].output.body == "99"


@test notebook.cells[19].output.body == "\"x\""
set_bond_value(:x_transform, 1, true)
@test notebook.cells[19].output.body == "\"x\""
set_bond_value(:x_transform, 3, false)
@test notebook.cells[19].output.body == "\"xxx\""


@test notebook.cells[22].output.body != "missing"
set_bond_value(:x_badtransform, 1, true)
@test notebook.cells[22].output.body != "missing"
set_bond_value(:x_badtransform, 7, false)
@test notebook.cells[22].output.body != "missing"


@test notebook.cells[25].output.body == "1"
set_bond_value(:x_counter, 1, true)
@test notebook.cells[25].output.body == "1"
set_bond_value(:x_counter, 7, false)
@test notebook.cells[25].output.body == "2"


WorkspaceManager.unmake_workspace((🍭, notebook))
🍭.options.evaluation.workspace_use_distributed = false
end

@testset "Table viewer" begin
🍭.options.evaluation.workspace_use_distributed = true
Expand Down

0 comments on commit a8f1553

Please sign in to comment.