Skip to content

Commit

Permalink
Run formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
contradict committed Aug 1, 2024
1 parent c7bd8da commit 8ab6bfe
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
17 changes: 11 additions & 6 deletions src/systems/model_parsing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,14 @@ function parse_variable_def!(dict, mod, arg, varclass, kwargs, where_types;
end
Expr(:(::), a, type) => begin
type = getfield(mod, type)
parse_variable_def!(dict, mod, a, varclass, kwargs, where_types; def, type, meta)
parse_variable_def!(
dict, mod, a, varclass, kwargs, where_types; def, type, meta)
end
Expr(:(::), Expr(:call, a, b), type) => begin
type = getfield(mod, type)
def = _type_check!(def, a, type, varclass)
parse_variable_def!(dict, mod, a, varclass, kwargs, where_types; def, type, meta)
parse_variable_def!(
dict, mod, a, varclass, kwargs, where_types; def, type, meta)
end
Expr(:call, a, b) => begin
var = generate_var!(dict, a, b, varclass, mod; indices, type)
Expand Down Expand Up @@ -618,7 +620,8 @@ function parse_variable_arg!(exprs, vs, dict, mod, arg, varclass, kwargs, where_
end

function convert_units(varunits::DynamicQuantities.Quantity, value)
DynamicQuantities.ustrip(DynamicQuantities.uconvert(DynamicQuantities.SymbolicUnits.as_quantity(varunits), value))
DynamicQuantities.ustrip(DynamicQuantities.uconvert(
DynamicQuantities.SymbolicUnits.as_quantity(varunits), value))
end

function convert_units(varunits::Unitful.FreeUnits, value)
Expand All @@ -639,10 +642,12 @@ function parse_variable_arg(dict, mod, arg, varclass, kwargs, where_types)
try
$setdefault($vv, $convert_units($unit, $name))
catch e
if isa(e, $(DynamicQuantities.DimensionError)) || isa(e, $(Unitful.DimensionError))
error("Unable to convert units for \'"*string(:($$vv))*"\'")
if isa(e, $(DynamicQuantities.DimensionError)) ||
isa(e, $(Unitful.DimensionError))
error("Unable to convert units for \'" * string(:($$vv)) * "\'")
elseif isa(e, MethodError)
error("No or invalid units provided for \'"*string(:($$vv))*"\'")
error("No or invalid units provided for \'" * string(:($$vv)) *
"\'")
else
rethrow(e)
end
Expand Down
10 changes: 5 additions & 5 deletions test/dq_units.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,17 @@ maj2 = MassActionJump(γ, [S => 1], [S => -1])

@mtkmodel ParamTest begin
@parameters begin
a, [unit=u"m"]
a, [unit = u"m"]
end
@variables begin
b(t), [unit=u"kg"]
b(t), [unit = u"kg"]
end
end

@named sys = ParamTest()

@named sys = ParamTest(a=3.0u"cm")
@named sys = ParamTest(a = 3.0u"cm")
@test ModelingToolkit.getdefault(sys.a) 0.03

@test_throws ErrorException ParamTest(;name=:t, a=1.0)
@test_throws ErrorException ParamTest(;name=:t, a=1.0u"s")
@test_throws ErrorException ParamTest(; name = :t, a = 1.0)
@test_throws ErrorException ParamTest(; name = :t, a = 1.0u"s")
3 changes: 2 additions & 1 deletion test/model_parsing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ resistor = getproperty(rc, :resistor; namespace = false)
# Test that `C_val` passed via argument is set as default of C.
@test getdefault(rc.capacitor.C) * get_unit(rc.capacitor.C) == C_val
# Test that `k`'s default value is unchanged.
@test getdefault(rc.constant.k) * get_unit(rc.constant.k) == eval(RC.structure[:kwargs][:k_val][:value])
@test getdefault(rc.constant.k) * get_unit(rc.constant.k) ==
eval(RC.structure[:kwargs][:k_val][:value])
@test getdefault(rc.capacitor.v) == 0.0

@test get_gui_metadata(rc.resistor).layout == Resistor.structure[:icon] ==
Expand Down
10 changes: 5 additions & 5 deletions test/units.jl
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,17 @@ maj2 = MassActionJump(γ, [S => 1], [S => -1])

@mtkmodel ParamTest begin
@parameters begin
a, [unit=u"m"]
a, [unit = u"m"]
end
@variables begin
b(t), [unit=u"kg"]
b(t), [unit = u"kg"]
end
end

@named sys = ParamTest()

@named sys = ParamTest(a=3.0u"cm")
@named sys = ParamTest(a = 3.0u"cm")
@test ModelingToolkit.getdefault(sys.a) 0.03

@test_throws ErrorException ParamTest(;name=:t, a=1.0)
@test_throws ErrorException ParamTest(;name=:t, a=1.0u"s")
@test_throws ErrorException ParamTest(; name = :t, a = 1.0)
@test_throws ErrorException ParamTest(; name = :t, a = 1.0u"s")

0 comments on commit 8ab6bfe

Please sign in to comment.