-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathprelude.jl
69 lines (61 loc) · 2.78 KB
/
prelude.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using Test
using Logging
using QuartoNotebookRunner
import JSON3
import JSONSchema
import NodeJS_18_jll
import quarto_jll
if !@isdefined(SCHEMA)
SCHEMA = JSONSchema.Schema(
open(JSON3.read, joinpath(@__DIR__, "../schema/nbformat.v4.schema.json")),
)
function test_example(f, each)
examples = joinpath(@__DIR__, "../examples")
name = relpath(each, pwd())
@info "Testing $name"
@testset "$(name)" begin
server = QuartoNotebookRunner.Server()
buffer = IOBuffer()
QuartoNotebookRunner.run!(server, each; output = buffer, showprogress = false)
seekstart(buffer)
json = JSON3.read(buffer, Any)
@test JSONSchema.validate(SCHEMA, json) === nothing
## Common tests.
@test json["nbformat"] == 4
@test json["nbformat_minor"] == 5
@test json["metadata"]["language_info"]["name"] == "julia"
@test json["metadata"]["language_info"]["version"] == "$VERSION"
@test json["metadata"]["language_info"]["codemirror_mode"] == "julia"
@test json["metadata"]["kernel_info"]["name"] == "julia"
@test startswith(json["metadata"]["kernelspec"]["name"], "julia")
@test startswith(json["metadata"]["kernelspec"]["display_name"], "Julia")
@test json["metadata"]["kernelspec"]["language"] == "julia"
## File-specific tests.
f(json)
function with_extension(path, ext)
root, _ = splitext(path)
return "$root.$ext"
end
ipynb = joinpath(examples, with_extension(each, "ipynb"))
QuartoNotebookRunner.run!(server, each; output = ipynb, showprogress = false)
if !Sys.iswindows()
# No macOS ARM build, so just look for a local version that the dev
# should have installed. This avoids having to use rosetta2 to run
# the x86_64 version of Julia to get access to the x86_64 version of
# Quarto artifact.
quarto_bin =
quarto_jll.is_available() ? quarto_jll.quarto() : setenv(`quarto`)
# Just a smoke test to make sure it runs. Use docx since it doesn't
# output a bunch of folders (html), or require a tinytex install
# (pdf). All we are doing here at the moment is ensuring quarto doesn't
# break on our notebook outputs.
if success(`$quarto_bin --version`)
@test success(`$quarto_bin render $ipynb --to docx`)
else
@error "quarto not found, skipping smoke test."
end
end
QuartoNotebookRunner.close!(server, each)
end
end
end