Skip to content

Commit

Permalink
Merge pull request #48 from PumasAI/mh/skip-nothings
Browse files Browse the repository at this point in the history
Fix #46, don't create any output for `nothing`s
  • Loading branch information
MichaelHatherly authored Feb 29, 2024
2 parents 50b08e0 + 7259932 commit ea0178e
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 44 deletions.
38 changes: 21 additions & 17 deletions src/server.jl
Original file line number Diff line number Diff line change
Expand Up @@ -522,14 +522,16 @@ function evaluate_raw_cells!(f::File, chunks::Vector, options::Dict; showprogres
if isnothing(remote.error)
for display_result in remote.display_results
processed_display = process_results(display_result)
push!(
outputs,
(;
output_type = "display_data",
processed_display.data,
processed_display.metadata,
),
)
if !isempty(processed_display.data)
push!(
outputs,
(;
output_type = "display_data",
processed_display.data,
processed_display.metadata,
),
)
end
if !isempty(processed_display.errors)
append!(outputs, processed_display.errors)
if !allow_error_cell
Expand All @@ -542,15 +544,17 @@ function evaluate_raw_cells!(f::File, chunks::Vector, options::Dict; showprogres
end
end
end
push!(
outputs,
(;
output_type = "execute_result",
execution_count = 1,
processed.data,
processed.metadata,
),
)
if !isempty(processed.data)
push!(
outputs,
(;
output_type = "execute_result",
execution_count = 1,
processed.data,
processed.metadata,
),
)
end
else
# These are errors arising from evaluation of the contents
# of a code cell, not from the `show` output of the values,
Expand Down
14 changes: 2 additions & 12 deletions test/testsets/const_redefinition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ include("../utilities/prelude.jl")
cells = json["cells"]

cell = cells[2]
@test only(cell["outputs"]) == Dict(
"output_type" => "execute_result",
"execution_count" => 1,
"data" => Dict(),
"metadata" => Dict(),
)
@test isempty(cell["outputs"])

cell = cells[4]
@test only(cell["outputs"]) == Dict(
Expand Down Expand Up @@ -84,12 +79,7 @@ include("../utilities/prelude.jl")
cells = json["cells"]

cell = cells[2]
@test only(cell["outputs"]) == Dict(
"output_type" => "execute_result",
"execution_count" => 1,
"data" => Dict(),
"metadata" => Dict(),
)
@test isempty(cell["outputs"])

cell = cells[4]
@test only(cell["outputs"]) == Dict(
Expand Down
2 changes: 1 addition & 1 deletion test/testsets/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test_example(joinpath(@__DIR__, "../examples/display.qmd")) do json

cell = cells[4]
outputs = cell["outputs"]
@test length(outputs) == 3
@test length(outputs) == 2

@test outputs[1]["output_type"] == "display_data"
@test haskey(outputs[1]["data"], "image/png")
Expand Down
12 changes: 5 additions & 7 deletions test/testsets/errors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,27 @@ test_example(joinpath(@__DIR__, "../examples/errors.qmd")) do json
cell = cells[18]

outputs = cell["outputs"]
@test length(outputs) == 5
@test outputs[1]["output_type"] == "execute_result"
@test isempty(outputs[1]["data"])
@test length(outputs) == 4

output = outputs[2]
output = outputs[1]
@test output["output_type"] == "error"
@test output["ename"] == "text/plain showerror"
@test length(output["traceback"]) == 11
@test contains(output["traceback"][end], "multimedia.jl")

output = outputs[3]
output = outputs[2]
@test output["output_type"] == "error"
@test output["ename"] == "text/html showerror"
@test length(output["traceback"]) == 9
@test contains(output["traceback"][end], "multimedia.jl")

output = outputs[4]
output = outputs[3]
@test output["output_type"] == "error"
@test output["ename"] == "text/latex showerror"
@test length(output["traceback"]) == 9
@test contains(output["traceback"][end], "multimedia.jl")

output = outputs[5]
output = outputs[4]
@test output["output_type"] == "error"
@test output["ename"] == "image/svg+xml showerror"
@test length(output["traceback"]) == 9
Expand Down
3 changes: 1 addition & 2 deletions test/testsets/project.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ test_example(joinpath(@__DIR__, "../examples/project.qmd")) do json

cell = json["cells"][10]
@test cell["cell_type"] == "code"
@test cell["outputs"][1]["output_type"] == "execute_result"
@test isempty(cell["outputs"][1]["data"])
@test isempty(cell["outputs"])

cell = json["cells"][12]
@test cell["cell_type"] == "code"
Expand Down
3 changes: 1 addition & 2 deletions test/testsets/project_exeflags.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ test_example(joinpath(@__DIR__, "../examples/project_exeflags.qmd")) do json

cell = cells[8]
@test cell["cell_type"] == "code"
@test cell["outputs"][1]["output_type"] == "execute_result"
@test isempty(cell["outputs"][1]["data"])
@test isempty(cell["outputs"])

cell = cells[10]
@test cell["cell_type"] == "code"
Expand Down
2 changes: 1 addition & 1 deletion test/testsets/semicolons.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ include("../utilities/prelude.jl")
json = run!(server, path; showprogress = false)

cell = json.cells[2]
@test isempty(cell.outputs[1].data)
@test isempty(cell.outputs)

cell = json.cells[4]
@test cell.outputs[1].data["text/plain"] == "1"
Expand Down
3 changes: 1 addition & 2 deletions test/testsets/stdout.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ test_example(joinpath(@__DIR__, "../examples/stdout.qmd")) do json
cell = json["cells"][2]
@test cell["cell_type"] == "code"
@test cell["execution_count"] == 1
@test length(cell["outputs"]) == 1
@test cell["outputs"][1]["output_type"] == "stream"
@test cell["outputs"][1]["name"] == "stdout"
@test contains(cell["outputs"][1]["text"], "1")
@test cell["outputs"][2]["output_type"] == "execute_result"
@test isempty(cell["outputs"][2]["data"])

cell = json["cells"][3]
@test cell["cell_type"] == "markdown"
Expand Down

0 comments on commit ea0178e

Please sign in to comment.