Skip to content

Commit

Permalink
invalid kwargs specification should throw an error now
Browse files Browse the repository at this point in the history
  • Loading branch information
behinger committed Nov 13, 2023
1 parent d9e56b5 commit 781ec58
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
15 changes: 15 additions & 0 deletions src/plotconfig.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ end
Takes a kwargs named tuple of Key => NamedTuple and merges the fields with the defaults
"""
function config_kwargs!(cfg::PlotConfig; kwargs...)
is_namedtuple = [isa(t,NamedTuple) for t in values(kwargs)]
@debug is_namedtuple
@assert(all(is_namedtuple),
""" Keyword-Argument specification (kwargs...)
All your specified config-groups need to be `NamedTuples`, but: `$(keys(kwargs)[.!is_namedtuple])` was not.
Maybe you forgot the semicolon (;) in your specification? It should be:
plot_example(...;layout = (;showColorbar=true))
and not:
plot_example(...;layout = (showColorbar=true))
The former creates a NamedTuple as required, the later doesn't do something helpful in this case.""")
list = fieldnames(PlotConfig)#[:layout,:visual,:mapping,:legend,:colorbar,:axis]
keyList = collect(keys(kwargs))
:extra keyList ? @warn("Extra is deprecated in 0.4 and extra-keyword args have to be used directly as key-word arguments") : ""
Expand Down
16 changes: 10 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,30 @@ using UnfoldMakie
include("setup.jl")
#include("../src/UnfoldMakie.jl")

@testset "UnfoldMakie.jl" begin

@testset "Test Config" begin
include("test_config.jl")
end
@testset "CircularEEGTopoPlot" begin
include("test_plot_circulareegtopoplot.jl")
end

@testset "UnfoldMakie.jl" begin
@testset "TopoSeries" begin
include("test_toposeries.jl")
end

@testset "UnfoldMakie.jl" begin
@testset "ERPImage" begin
include("test_erpimage.jl")
end

@testset "UnfoldMakie.jl" begin
@testset "TopoPlot" begin
include("test_topoplot.jl")
end

@testset "UnfoldMakie.jl" begin
@testset "Butterfly" begin
include("test_butterfly.jl")
end

@testset "UnfoldMakie.jl" begin
@testset "AllPlots" begin
include("test_all.jl")
end
9 changes: 9 additions & 0 deletions test/test_config.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@testset "config kwargs" begin
cfg = PlotConfig()
UnfoldMakie.config_kwargs!(cfg;visual=(;bla=:blub))
@test cfg.visual.bla == :blub

# now test that you cannot forget the ; - that is, cant forget to specify a NamedTuple
@test_throws AssertionError UnfoldMakie.config_kwargs!(cfg;visual=(bla=:blub))

end

0 comments on commit 781ec58

Please sign in to comment.