Skip to content
This repository has been archived by the owner on Jul 13, 2021. It is now read-only.

Commit

Permalink
loosen constraints of to_colormap (#307)
Browse files Browse the repository at this point in the history
* loosen constraints of `to_colormap`

Fix #306

* Refactor tests

* test on 1.3

Pkg's resolver has improved, also artifacts
  • Loading branch information
asinghvi17 authored Feb 15, 2020
1 parent 44dbfd9 commit 68ee316
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 116 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ language: julia
os:
- linux
julia:
- 1.2
- 1.3
- nightly
notifications:
email: false
Expand Down
10 changes: 5 additions & 5 deletions src/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -667,12 +667,12 @@ struct Reverse{T}
data::T
end

function convert_attribute(r::Reverse, ::key"colormap")
reverse(to_colormap(r.data))
function convert_attribute(r::Reverse, ::key"colormap", n::Integer = 20)
reverse(to_colormap(r.data, n))
end

function convert_attribute(cs::ColorScheme, ::key"colormap")
return to_colormap(cs.colors)
function convert_attribute(cs::ColorScheme, ::key"colormap", n::Integer = 20)
return to_colormap(cs.colors, n)
end


Expand All @@ -690,7 +690,7 @@ function convert_attribute(cs::Union{Tuple, Pair}, ::key"colormap")
[to_color.(cs)...]
end

to_colormap(x::Union{String, Symbol}, n::Integer) = convert_attribute(x, key"colormap"(), n)
to_colormap(x, n::Integer) = convert_attribute(x, key"colormap"(), n)

"""
A Symbol/String naming the gradient. For more on what names are available please see: `available_gradients()`.
Expand Down
139 changes: 80 additions & 59 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ using MakieGallery
using Test
using GLMakie

# Download reference images from master
MakieGallery.current_ref_version[] = "master"

const MINIMAL = get(ENV, "ABSTRACTPLOTTING_MINIMAL", "false")

# does this machine have a OPENGL?
Expand All @@ -14,10 +17,19 @@ OPENGL || (MINIMAL = "true")
OPENGL && begin @info "OpenGL detected"; using GLMakie end
OPENGL || @warn "No OpenGL detected! Software tests only."

@info "Running conversion tests"
include("conversions.jl")

@info "Running quaternion tests"
include("quaternions.jl")

@info "Running projection tests"
include("projection_math.jl")

@info "Running shorthand tests"
include("shorthands.jl")

@info "Running basic Scene test"
@testset "basic functionality" begin
scene = scatter(rand(4))
@test scene[Axis].ticks.title_gap[] == 3
Expand All @@ -26,91 +38,98 @@ include("projection_math.jl")
@test scene[Axis].tickmarks.length[] == (3, 3)
end

@testset "shorthand functions" begin
include("shorthands_tests.jl")
end

if MINIMAL == "false"

@info "Minimal was false; running full tests!"

# Load all entries in the database

database = MakieGallery.load_database()

## Exceptions are made on basis of title and not index,
# because index may change as MakieGallery changes.

# All these require FFMpeg and need to save,
# and are therefore ignored
ffmpeg_exs = [
"Animation", "Lots of Heatmaps","Animated Scatter",
"Chess Game", "Record Video", "Animated surface and wireframe",
"Moire", "pong", "pulsing marker", "Travelling wave",
"Type recipe for molecule simulation", "Cobweb plot"
]

# All these require GLMakie and so are ignored
glmakie_exs = [
"Textured Mesh", "Load Mesh", "Wireframe of a Mesh",
"FEM mesh 3D", "Normals of a Cat", "Line GIF"
# we found which ones are the slowest, and kicked those out!
slow_examples = [
"Animated time series",
"Animation",
"Lots of Heatmaps",
"Chess Game",
"Line changing colour",
"Line changing colour with Observables",
"Colormap collection",
"Record Video",
"Animated surface and wireframe",
"Moire",
"Line GIF",
"Electrostatic repulsion",
"pong",
"pulsing marker",
"Travelling wave",
"Axis theming",
"Legend",
"Color Legend",
"DifferentialEquations path animation",
"Interactive Differential Equation",
"Spacecraft from a galaxy far, far away",
"WorldClim visualization",
"Image on Geometry (Moon)",
"Image on Geometry (Earth)",
"Interaction with mouse",
"Air Particulates",
]

# Requires GDAL (a GL package) so ignored
gdal_exs = [
"WorldClim visualization"
]

# Requires GLMakie and ModernGL, so ignored
moderngl_exs = [
"Explicit frame rendering"
]

# use Stepper plots, which save, so ignored
save_exs = [
"Axis theming", "Labels", "Color Legend",
"Stepper demo"
]

# hopefullly fixed by next tag of MakieGallery (already in AbstractPlotting
color_exs = ["colormaps"]

# curl fails with this for some reason, so it has been ignored.
curl_exs = ["Earth & Ships"]
stepper_exclude = ["Tutorial plot transformation", "Legend"]
if OPENGL
excluded_examples = Set()
else
# combine all exceptions into a single Set
excluded_examples = union(
ffmpeg_exs, glmakie_exs, gdal_exs, moderngl_exs,
save_exs, color_exs, curl_exs, stepper_exclude
)
# diffeq is also slow, as are analysis heatmaps. Colormap collection likes to
# fail a lot.
filter!(MakieGallery.database) do entry
!("diffeq" in entry.tags) &&
!(entry.unique_name in (:analysis, :colormap_collection, :lots_of_heatmaps)) &&
!(entry.title in slow_examples)
end

# Download is broken on CI
if get(ENV, "CI", "false") == "true"
printstyled("CI detected\n"; bold = true, color = :yellow)
println("Filtering out examples which download")
filter!(entry-> !("download" in entry.tags), database)
end

else
# Load only short tests
database = MakieGallery.load_tests()
excluded_examples = Set(["Comparing contours, image, surfaces and heatmaps"])
end

# one last time to make sure
filter!(database) do entry
!("diffeq" in entry.tags) &&
!(entry.unique_name in (:analysis, :colormap_collection, :lots_of_heatmaps))
end

# Here, we specialize on two cases.
# If there is no opengl, then we have to run software-only tests, i.e., eval the
# examples and test that nothing errors.
# If there is opengl, then we use MakieGallery's test protocol.

if !OPENGL # run software only tests...
# Make sure we don't include Makie in the usings
empty!(MakieGallery.plotting_backends)
push!(MakieGallery.plotting_backends, "AbstractPlotting")
@test AbstractPlotting.current_backend[] isa Missing

@test AbstractPlotting.current_backend[] isa Missing # should we change this, so e.g. CairoMakie works?

@info "Starting minimal software tests"
filter!(database) do example
!(example.title in excluded_examples) &&
!("record" in example.tags)
end

@testset "Gallery short tests" begin
# iterate over database
@testset "$(database[i].title) (#$i)" for i in 1:length(database)
@debug("Running " * database[i].title * "\n(index $i)\n")

printstyled("Running "; bold = true, color = :blue)
print(database[i].title * "\n(index $i)\n")

# evaluate the entry
try
MakieGallery.eval_example(database[i])
Expand All @@ -127,24 +146,26 @@ if !OPENGL # run software only tests...
@test rethrow(e)
end
end
@assert AbstractPlotting.current_backend[] isa Missing
@debug AbstractPlotting.current_backend[] isa Missing
end
end

else # full MakieGallery comparisons here
using GLMakie
@info("Running full tests - artifacts will be stored!")
for exc in excluded_examples
printstyled("Excluded ", color = :yellow, bold = true)
println(exc)
end
filter!(entry -> !(entry.title in excluded_examples), database)

tested_diff_path = joinpath(@__DIR__, "tested_different")
test_record_path = joinpath(@__DIR__, "test_recordings")

rm(tested_diff_path, force = true, recursive = true)
mkpath(tested_diff_path)

rm(test_record_path, force = true, recursive = true)
mkpath(test_record_path)

examples = MakieGallery.record_examples(test_record_path)
MakieGallery.run_comparison(test_record_path, tested_diff_path)
end

@test length(examples) == length(database)

printstyled("Running ", color = :green, bold = true)
println("visual regression tests")
end
52 changes: 52 additions & 0 deletions test/shorthands.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
@testset "shorthands" begin

scene2d = scatter(1:10, 1:10);
scene = scatter(1:10, 1:10, 1:10);
axis = scene[Axis]

@testset "tick labels" begin

@test xticklabels(scene) == ["0.0", "2.5", "5.0", "7.5", "10.0"]
@test yticklabels(scene) == ["2", "4", "6", "8", "10"]
@test zticklabels(scene) == ["2", "4", "6", "8", "10"]
@test_throws AssertionError("The Scene does not have a z-axis!") zticklabels(scene2d)

@test xtickrange(scene) == [0.0, 2.5, 5.0, 7.5, 10.0]
@test ytickrange(scene) == [2.0, 4.0, 6.0, 8.0, 10.0]
@test ztickrange(scene) == [2.0, 4.0, 6.0, 8.0, 10.0]
@test_throws AssertionError("The Scene does not have a z-axis!") ztickrange(scene2d)

xticks!(scene, xticklabels=["a", "b", "c", "d", "e"])
@test xticklabels(scene) == ["a", "b", "c", "d", "e"]

yticks!(scene, yticklabels=["a", "b", "c", "d", "e", "f"], ytickrange=collect(range(2.0, stop=10.0, length=6)))
@test yticklabels(scene) == ["a", "b", "c", "d", "e", "f"]

yticks!(scene2d, yticklabels=["a", "b", "c", "d", "e", "f"], ytickrange=collect(range(2.0, stop=10.0, length=6)))
@test yticklabels(scene2d) == ["a", "b", "c", "d", "e", "f"]

zticks!(scene, zticklabels=["2", "10"], ztickrange=[2.0, 10.0])
@test zticklabels(scene) == ["2", "10"]

@test_throws AssertionError("The Scene does not have a z-axis!") zticks!(scene2d, zticklabels=["2", "10"], ztickrange=[2.0, 10.0])
end

@testset "tick rotation" begin
@test xtickrotation(scene) == axis.ticks.rotation[][1]
@test ytickrotation(scene) == axis.ticks.rotation[][2]
@test ztickrotation(scene) == axis.ticks.rotation[][3]

xtickrotation!(0.0)
@test xtickrotation(scene) == 0.0

ytickrotation!(0.0)
@test ytickrotation(scene) == 0.0

ztickrotation!(0.0)
@test ztickrotation(scene) == 0.0

@test_throws AssertionError("The Scene does not have a z-axis!") ztickrotation(scene2d)
@test_throws AssertionError("The Scene does not have a z-axis!") ztickrotation!(scene2d, 0.0)
end

end
51 changes: 0 additions & 51 deletions test/shorthands_tests.jl

This file was deleted.

0 comments on commit 68ee316

Please sign in to comment.