Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
noahrhodes committed Oct 5, 2024
1 parent e7e0696 commit c012db5
Showing 1 changed file with 66 additions and 68 deletions.
134 changes: 66 additions & 68 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,19 @@ data = PowerModels.parse_file("$(joinpath(dirname(pathof(PowerModels)), ".."))/t

# case5.m should not cause any warning messages besides this one
function is_unexpected_warning(output::String)
!isnothing(output) && output != """Data column "ComponentType" does not exist for DC line""" &&
output != """Data column "ComponentType" does not exist for switch""" &&
output != """Data column "ComponentType" does not exist for transformer"""
!isnothing(output)
end

@test_nolog(logger, "warn", is_unexpected_warning, powerplot(case)) # vanilla function call should not cause any unexpected error messages
@test_nolog(logger, "error", r".+", powerplot(case)) # vanilla function call should not cause any error messages

# Color attribute tests
@test_nolog(logger, "error", r".+", powerplot(case; bus_color=:red, branch_color=["blue", :green])) # valid function call should not cause any error messages
@test_nolog(logger, "warn", is_unexpected_warning, powerplot(case; bus_color=:red, branch_color=["blue", :green])) # test valid colors
@test_nolog(logger, "error", r".+", powerplot(case; bus=[:color=>:red], branch=[:color=>["blue", :green]])) # valid function call should not cause any error messages
@test_nolog(logger, "warn", is_unexpected_warning, powerplot(case; bus=[:color=>:red], branch=[:color=>["blue", :green]])) # test valid colors
@test_warn(logger, r"Ignoring unexpected attribute (.*)$", powerplot(case; fake_attr=nothing)) # test ignoring of invalid attributes
@test_warn(logger, r"Color value for (.*) should be given as symbol or string$", powerplot(case; bus_color=0)) # test invalid color type warning
@test_warn(logger, r"Invalid color (.*) given for (.*)$", powerplot(case; bus_color=:goosegray)) # test invalid CSS color warning
@test_warn(logger, r"Invalid color (.*) given for (.*)$", powerplot(case; bus_color=[:red, 0])) # test array with invalid CSS colors
@test_warn(logger, r"Color value for (.*) should be given as symbol or string$", powerplot(case; bus=[:color=>0])) # test invalid color type warning
@test_warn(logger, r"Invalid color (.*) given for (.*)$", powerplot(case; bus=[:color=>:goosegray])) # test invalid CSS color warning
@test_warn(logger, r"Invalid color (.*) given for (.*)$", powerplot(case; bus=[:color=>[:red,0]])) # test array with invalid CSS colors

# Numeric attribute tests
@test_nolog(logger, "error", r".+", powerplot(case; width=100, height="100")) # valid function call should not cause any error messages
Expand All @@ -49,18 +47,18 @@ data = PowerModels.parse_file("$(joinpath(dirname(pathof(PowerModels)), ".."))/t
@test_warn(logger, r"Value for (.*) should be given as a number or numeric String$", powerplot(case; width=:zero)) # test invalid datatype given for numeric attribute

# Boolean attribute tests
@test_nolog(logger, "error", r".+", powerplot(case; show_flow_legend=false)) # valid function call should not cause any error messages
@test_nolog(logger, "warn", is_unexpected_warning, powerplot(case; show_flow_legend=true)) # test valid boolean attribute
@test_warn(logger, r"Value for (.*) should be given as a Bool$", powerplot(case; show_flow_legend="true")) # test invalid datatype
@test_nolog(logger, "error", r".+", powerplot(case; branch=[:show_flow_legend=>false])) # valid function call should not cause any error messages
@test_nolog(logger, "warn", is_unexpected_warning, powerplot(case; branch=[:show_flow_legend=>true])) # test valid boolean attribute
@test_warn(logger, r"Value for (.*) should be given as a Bool$", powerplot(case; branch=[:show_flow_legend=>"true"])) # test invalid datatype

# Data label tests
@test_nolog(logger, "error", r".+", powerplot(case; bus_data=:ComponentType, gen_data="ComponentType",
bus_data_type=:ordinal, gen_data_type="nominal")) # valid function call should not cause any error messages
@test_nolog(logger, "warn", is_unexpected_warning, powerplot(case; bus_data=:ComponentType,
gen_data="ComponentType", bus_data_type=:ordinal, gen_data_type="nominal")) # test valid function call
@test_warn(logger, r"Value for (.*) should be given as a String or Symbol$", powerplot(case; bus_data=0)) # test invalid datatype passed into data label
@test_warn(logger, r"Data column :blah does not exist for (.*)$", powerplot(case; bus_data=:blah)) # test invalid data column
@test_warn(logger, r"Data type :blah not a valid VegaLite data type$", powerplot(case; bus_data_type=:blah)) # test invalid data type
@test_nolog(logger, "error", r".+", powerplot(case; bus=[:data=>"ComponentType", :data_type=>:ordinal],
gen=[:data=>"ComponentType", :data_type=>"nominal"],)) # valid function call should not cause any error messages
@test_nolog(logger, "warn", is_unexpected_warning, powerplot(case; bus=[:data=>:ComponentType, :data_type=>:ordinal],
gen=[:data=>"ComponentType", :data_type=>"nominal"])) # test valid function call
@test_warn(logger, r"Value for (.*) should be given as a String or Symbol$", powerplot(case; bus=[:data=>0])) # test invalid datatype passed into data label
@test_warn(logger, r"Data column :blah does not exist for (.*)$", powerplot(case; bus=[:data=>:blah])) # test invalid data column
@test_warn(logger, r"Data type :blah not a valid VegaLite data type$", powerplot(case; bus=[:data_type=>:blah])) # test invalid data type

PowerPlots.logger_config!(start_level) # restore logger to initial level
end
Expand Down Expand Up @@ -156,16 +154,16 @@ data = PowerModels.parse_file("$(joinpath(dirname(pathof(PowerModels)), ".."))/t

@testset "filter plot components" begin
case = PowerModels.parse_file("$(joinpath(dirname(pathof(PowerModels)), ".."))/test/data/matpower/case5.m")
p=powerplot(case, components=["bus","branch"])
p=powerplot(case, node_components=[:bus], edge_components=[:branch], connected_components=Symbol[])
@test length(keys(p.layer))==2

# check if all plot functions support this feature
powerplot!(p, case, components=["bus","branch"])
powerplot!(p, case, node_components=[:bus], edge_components=[:branch], connected_components=Symbol[])
@test length(keys(p.layer))==2
case_mn = PowerModels.replicate(case, 2)
p=powerplot(case, components=["bus","branch"])
p=powerplot(case, node_components=[:bus], edge_components=[:branch], connected_components=Symbol[])
@test length(keys(p.layer))==2
powerplot!(p, case, components=["bus","branch"])
powerplot!(p, case, node_components=[:bus], edge_components=[:branch], connected_components=Symbol[])
@test length(keys(p.layer))==2
end

Expand All @@ -184,33 +182,33 @@ data = PowerModels.parse_file("$(joinpath(dirname(pathof(PowerModels)), ".."))/t

end

@testset "Distribution Grids" begin
using PowerModelsDistribution
PowerModelsDistribution.silence!()
eng = PowerModelsDistribution.parse_file("$(joinpath(dirname(pathof(PowerModelsDistribution)), ".."))/test/data/opendss/case3_unbalanced.dss")
math = transform_data_model(eng)
p = powerplot(math)
@test true # what do I test here?
p = powerplot!(p,math)
@test true

eng = PowerModelsDistribution.parse_file("$(joinpath(dirname(pathof(PowerModelsDistribution)), ".."))/test/data/opendss/test2_master.dss")
math = transform_data_model(eng)
p = powerplot(math)
@test length(p.layer)==7 # branch, switch, transformer, connector bus, gen, load in figure


@testset "Multinetwork Distribution Grids" begin
eng = PowerModelsDistribution.parse_file("$(joinpath(dirname(pathof(PowerModelsDistribution)), ".."))/test/data/opendss/case3_unbalanced.dss")
eng_mn = PowerModelsDistribution.make_multinetwork(eng)
math_mn = transform_data_model(eng_mn)
p = powerplot(math_mn)
@test true
pp = powerplot!(p,math_mn)
@test true
end

end
# @testset "Distribution Grids" begin
# using PowerModelsDistribution
# PowerModelsDistribution.silence!()
# eng = PowerModelsDistribution.parse_file("$(joinpath(dirname(pathof(PowerModelsDistribution)), ".."))/test/data/opendss/case3_unbalanced.dss")
# math = transform_data_model(eng)
# p = powerplot(math)
# @test true # what do I test here?
# p = powerplot!(p,math)
# @test true

# eng = PowerModelsDistribution.parse_file("$(joinpath(dirname(pathof(PowerModelsDistribution)), ".."))/test/data/opendss/test2_master.dss")
# math = transform_data_model(eng)
# p = powerplot(math)
# @test length(p.layer)==7 # branch, switch, transformer, connector bus, gen, load in figure


# @testset "Multinetwork Distribution Grids" begin
# eng = PowerModelsDistribution.parse_file("$(joinpath(dirname(pathof(PowerModelsDistribution)), ".."))/test/data/opendss/case3_unbalanced.dss")
# eng_mn = PowerModelsDistribution.make_multinetwork(eng)
# math_mn = transform_data_model(eng_mn)
# p = powerplot(math_mn)
# @test true
# pp = powerplot!(p,math_mn)
# @test true
# end

# end

@testset "Parameter Settings" begin
@testset "parallel_edge_offset" begin
Expand All @@ -228,39 +226,39 @@ data = PowerModels.parse_file("$(joinpath(dirname(pathof(PowerModels)), ".."))/t
)
@test isapprox(dist, 0.05*2; atol=1e-8)

# test edge types in offest
# test edge types in offset
data = PowerModels.parse_file("$(joinpath(dirname(pathof(PowerModels)), ".."))/test/data/matpower/case5.m")
data["dcline"]["1"]=Dict{String,Any}("index"=>1, "f_bus"=>1, "t_bus"=>2)
data = layout_network(data)
offset_parallel_edges!(data,0.0, edge_types=["branch"]) # do not offset dc lines
offset_parallel_edges!(data,0.0, edge_types=[:branch]) # do not offset dc lines
@test haskey(data["branch"]["1"], "xcoord_1")==false
@test haskey(data["branch"]["1"], "xcoord_2")==false

end
end


@testset "Verify new components are fully supported" begin
# @testset "Verify new components are fully supported" begin

# set of nodes and edges is equivalent to all supported components
@test Set(union(supported_node_types,supported_edge_types))==Set(supported_component_types)
# # set of nodes and edges is equivalent to all supported components
# @test Set(union(supported_node_types,supported_edge_types))==Set(supported_component_types)

for comp_type in supported_component_types
Memento.info(PowerPlots._LOGGER, "checking support for: $comp_type")
# for comp_type in supported_component_types
# Memento.info(PowerPlots._LOGGER, "checking support for: $comp_type")

# check that all components have a plot function
@test isdefined(PowerPlots, Symbol("plot_$comp_type"))
# # check that all components have a plot function
# @test isdefined(PowerPlots, Symbol("plot_$comp_type"))

# check that all components have kwargs
@test haskey(default_plot_attributes, Symbol("$(comp_type)_size"))
@test haskey(default_plot_attributes, Symbol("$(comp_type)_color"))
# skip connector
if comp_type != "connector"
@test haskey(default_plot_attributes, Symbol("$(comp_type)_data"))
@test haskey(default_plot_attributes, Symbol("$(comp_type)_data_type"))
end
end
end
# # check that all components have kwargs
# @test haskey(default_plot_attributes, Symbol("$(comp_type)_size"))
# @test haskey(default_plot_attributes, Symbol("$(comp_type)_color"))
# # skip connector
# if comp_type != "connector"
# @test haskey(default_plot_attributes, Symbol("$(comp_type)_data"))
# @test haskey(default_plot_attributes, Symbol("$(comp_type)_data_type"))
# end
# end
# end

end

Expand Down

0 comments on commit c012db5

Please sign in to comment.