Skip to content

Commit

Permalink
feat: extend Base.parentmodule for Model
Browse files Browse the repository at this point in the history
  • Loading branch information
ven-k committed Dec 4, 2023
1 parent 26097d3 commit e210997
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/systems/model_parsing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ struct Model{F, S}
end
(m::Model)(args...; kw...) = m.f(args...; kw...)

Base.parentmodule(m::Model) = parentmodule(m.f)

Check warning on line 27 in src/systems/model_parsing.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/model_parsing.jl#L27

Added line #L27 was not covered by tests

for f in (:connector, :mtkmodel)
isconnector = f == :connector ? true : false
@eval begin
Expand Down
12 changes: 12 additions & 0 deletions test/model_parsing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -547,3 +547,15 @@ end
@test getdefault(component.written_out_for_1.sc) == 2
@test getdefault(component.written_out_for_2.sc) == 3
end

module GetParentModule

using ModelingToolkit

@mtkmodel Component begin end

end

@testset "Parent module of Models" begin
@test parentmodule(GetParentModule.Component) == GetParentModule
end

0 comments on commit e210997

Please sign in to comment.