diff --git a/CHANGELOG.md b/CHANGELOG.md index 915717e..b265c61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ InfrastructureModels.jl Change Log ================================== ### Staged -- nothing +- Fix support for strongly type network data (#92) ### v0.7.7 - Fix support for utf-8 in matlab parser (#91) diff --git a/src/core/base.jl b/src/core/base.jl index 8886a0e..619fb42 100644 --- a/src/core/base.jl +++ b/src/core/base.jl @@ -209,7 +209,7 @@ function _populate_ref_it!(refs::Dict{Symbol, <:Any}, data_it::Dict{String, <:An for (key, item) in nw_data if !(key in global_keys) - if isa(item, Dict{String, Any}) && _iscomponentdict(item) + if typeof(item) <: Dict{String, <:Any} && _iscomponentdict(item) item_lookup = Dict{Int, Any}([(parse(Int, k), v) for (k, v) in item]) ref[Symbol(key)] = item_lookup else diff --git a/test/base.jl b/test/base.jl index 6e368b2..ef566bd 100644 --- a/test/base.jl +++ b/test/base.jl @@ -55,6 +55,11 @@ end @test ref[:it][:foo][:nw][0][:comp][2]["a"] == 3 end +@testset "ref initialize keytype" begin + ref = ref_initialize(generic_si_network_data_native, "foo", Set(["per_unit", "dict"])) + @test keytype(ref[:it][:foo][:nw][0][:comp]) == Int +end + abstract type MyAbstractInfrastructureModel <: AbstractInfrastructureModel end mutable struct MyInfrastructureModel <: MyAbstractInfrastructureModel @im_fields end diff --git a/test/common.jl b/test/common.jl index 3d884ad..f66fddb 100644 --- a/test/common.jl +++ b/test/common.jl @@ -29,6 +29,34 @@ generic_si_network_data = JSON.parse("""{ } }""") +# used to check that ref_initialize works correctly with strongly typed data +generic_si_network_data_native = Dict( + "per_unit" => false, + "a" => 1, + "b" => "bloop", + "list" => [1, "two", 3.0, false], + "dict" => Dict("a" => 1, "b" => 2.0, "c" => true, "d" => "bloop"), + "comp" => Dict( + "1" => Dict( + "a" => 1, + "b" => 2, + "c" => "same", + "status" => 1 + ), + "2" => Dict( + "a" => 3, + "b" => 4, + "c" => "same", + "status" => 0 + ), + "3" => Dict( + "a" => 5, + "b" => 6, + "c" => "same", + "d" => false + ) + ) +) generic_mi_network_data = JSON.parse(""" {