Skip to content

Commit

Permalink
fix serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
jd-lara committed Dec 21, 2023
1 parent 423874f commit 1192753
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/utils/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ end
"""
Returns an array of all super types of T.
"""
function supertypes(::Type{T}, types=[]) where {T}
function supertypes(::Type{T}, types = []) where {T}

Check warning on line 52 in src/utils/utils.jl

View check run for this annotation

Codecov / codecov/patch

src/utils/utils.jl#L52

Added line #L52 was not covered by tests
super = supertype(T)
push!(types, super)
if super == Any
Expand Down Expand Up @@ -122,26 +122,27 @@ Recursively compares struct values. Prints all mismatched values to stdout.
- `y::T`: Second value
- `compare_uuids::Bool = false`: Compare any UUID in the object or composed objects.
"""
function compare_values(x::T, y::T; compare_uuids=false) where {T}
function compare_values(x::T, y::T; compare_uuids = false) where {T}
match = true
fields = fieldnames(T)
if isempty(fields)
match = x == y
else
for field_name in fields
if T <: TimeSeriesContainer && field_name == :time_series_storage
if (T <: TimeSeriesContainer || T <: SupplementalAttributes) &&
field_name == :time_series_storage
# This gets validated at SystemData. Don't repeat for each component.
continue
end
val1 = getfield(x, field_name)
val2 = getfield(y, field_name)
if !isempty(fieldnames(typeof(val1)))
if !compare_values(val1, val2, compare_uuids=compare_uuids)
if !compare_values(val1, val2; compare_uuids = compare_uuids)
@error "values do not match" T field_name val1 val2
match = false
end
elseif val1 isa AbstractArray
if !compare_values(val1, val2, compare_uuids=compare_uuids)
if !compare_values(val1, val2; compare_uuids = compare_uuids)

Check warning on line 145 in src/utils/utils.jl

View check run for this annotation

Codecov / codecov/patch

src/utils/utils.jl#L145

Added line #L145 was not covered by tests
@error "values do not match" T field_name val1 val2
match = false
end
Expand All @@ -157,15 +158,15 @@ function compare_values(x::T, y::T; compare_uuids=false) where {T}
return match
end

function compare_values(x::Vector{T}, y::Vector{T}; compare_uuids=false) where {T}
function compare_values(x::Vector{T}, y::Vector{T}; compare_uuids = false) where {T}
if length(x) != length(y)
@error "lengths do not match" T length(x) length(y)
return false
end

match = true
for i in range(1, length=length(x))
if !compare_values(x[i], y[i], compare_uuids=compare_uuids)
for i in range(1; length = length(x))
if !compare_values(x[i], y[i]; compare_uuids = compare_uuids)

Check warning on line 169 in src/utils/utils.jl

View check run for this annotation

Codecov / codecov/patch

src/utils/utils.jl#L169

Added line #L169 was not covered by tests
@error "values do not match" typeof(x[i]) i x[i] y[i]
match = false
end
Expand All @@ -174,7 +175,7 @@ function compare_values(x::Vector{T}, y::Vector{T}; compare_uuids=false) where {
return match
end

function compare_values(x::Dict, y::Dict; compare_uuids=false)
function compare_values(x::Dict, y::Dict; compare_uuids = false)
keys_x = Set(keys(x))
keys_y = Set(keys(y))
if keys_x != keys_y
Expand All @@ -184,7 +185,7 @@ function compare_values(x::Dict, y::Dict; compare_uuids=false)

match = true
for key in keys_x
if !compare_values(x[key], y[key], compare_uuids=compare_uuids)
if !compare_values(x[key], y[key]; compare_uuids = compare_uuids)
@error "values do not match" typeof(x[key]) key x[key] y[key]
match = false
end
Expand All @@ -193,8 +194,8 @@ function compare_values(x::Dict, y::Dict; compare_uuids=false)
return match
end

compare_values(::Type{T}, ::Type{T}; compare_uuids=false) where {T} = true
compare_values(::Type{T}, ::Type{U}; compare_uuids=false) where {T, U} = false
compare_values(::Type{T}, ::Type{T}; compare_uuids = false) where {T} = true
compare_values(::Type{T}, ::Type{U}; compare_uuids = false) where {T, U} = false

Check warning on line 198 in src/utils/utils.jl

View check run for this annotation

Codecov / codecov/patch

src/utils/utils.jl#L197-L198

Added lines #L197 - L198 were not covered by tests

# Copied from https://discourse.julialang.org/t/encapsulating-enum-access-via-dot-syntax/11785/10
"""
Expand Down Expand Up @@ -328,7 +329,7 @@ function forward(sender::Tuple{Type, Symbol}, receiver::Type, exclusions::Vector
return code
end

macro forward(sender, receiver, exclusions=Symbol[])
macro forward(sender, receiver, exclusions = Symbol[])
out = quote
list = InfrastructureSystems.forward($sender, $receiver, $exclusions)
for line in list
Expand Down Expand Up @@ -379,8 +380,11 @@ end
function get_module(module_name)
# root_module cannot find InfrastructureSystems if it hasn't been installed by the
# user (but has been installed as a dependency to another package).
return module_name == "InfrastructureSystems" ? InfrastructureSystems :
Base.root_module(Base.__toplevel__, Symbol(module_name))
return if module_name == "InfrastructureSystems"
InfrastructureSystems
else
Base.root_module(Base.__toplevel__, Symbol(module_name))

Check warning on line 386 in src/utils/utils.jl

View check run for this annotation

Codecov / codecov/patch

src/utils/utils.jl#L386

Added line #L386 was not covered by tests
end
end

get_type_from_strings(module_name, type) = getfield(get_module(module_name), Symbol(type))
Expand Down Expand Up @@ -409,7 +413,7 @@ function get_initial_times(
return [initial_timestamp]
end

return range(initial_timestamp; length=count, step=interval)
return range(initial_timestamp; length = count, step = interval)
end

function get_total_period(
Expand Down

0 comments on commit 1192753

Please sign in to comment.