Skip to content

Commit 64925e2

Browse files
test: do not use @mtkmodel in tests
1 parent df6c944 commit 64925e2

26 files changed

+1015
-1004
lines changed

lib/ModelingToolkitBase/test/analysis_points.jl

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ using Test
66
using ModelingToolkitBase: t_nounits as t, D_nounits as D, AnalysisPoint, AbstractSystem
77
import ModelingToolkitBase as MTK
88
import ControlSystemsBase as CS
9-
using SciCompDSL
109
using ModelingToolkitStandardLibrary
1110

1211
using Symbolics: NAMESPACE_SEPARATOR
@@ -693,17 +692,26 @@ using DynamicQuantities
693692

694693
@testset "AnalysisPoint is ignored when verifying units" begin
695694
# no units first
696-
@mtkmodel FirstOrderTest begin
697-
@components begin
695+
@component function FirstOrderTest(; name)
696+
pars = @parameters begin
697+
end
698+
699+
systems = @named begin
698700
in = Step()
699701
fb = Feedback()
700702
fo = SecondOrder(k = 1, w = 1, d = 0.1)
701703
end
702-
@equations begin
704+
705+
vars = @variables begin
706+
end
707+
708+
equations = Equation[
703709
connect(in.output, :u, fb.input1)
704710
connect(fb.output, :e, fo.input)
705711
connect(fo.output, :y, fb.input2)
706-
end
712+
]
713+
714+
return System(equations, t, vars, pars; name, systems)
707715
end
708716
@named model = FirstOrderTest()
709717
@test model isa System
@@ -735,38 +743,48 @@ using DynamicQuantities
735743
]
736744
return System(eqs, t, [], pars; systems, name)
737745
end
738-
@mtkmodel TestAPAroundUnits begin
739-
@components begin
746+
@component function TestAPAroundUnits(; name)
747+
pars = @parameters begin
748+
end
749+
750+
systems = @named begin
740751
input = UnitfulInput()
752+
ub = UnitfulBlock()
741753
end
742-
@variables begin
754+
755+
vars = @variables begin
743756
output(t), [output=true, unit=u"m^2"]
744757
end
745-
@components begin
746-
ub = UnitfulBlock()
747-
end
748-
@equations begin
758+
759+
equations = Equation[
749760
connect(ub.output, :ap, input)
750761
output ~ input.u^2
751-
end
762+
]
763+
764+
return System(equations, t, vars, pars; name, systems)
752765
end
753766
@named sys = TestAPAroundUnits()
754767
@test sys isa System
755768

756-
@mtkmodel TestAPWithNoOutputs begin
757-
@components begin
769+
@component function TestAPWithNoOutputs(; name)
770+
pars = @parameters begin
771+
end
772+
773+
systems = @named begin
758774
input = UnitfulInput()
775+
ub = UnitfulBlock()
759776
end
760-
@variables begin
777+
778+
vars = @variables begin
761779
output(t), [output=true, unit=u"m^2"]
762780
end
763-
@components begin
764-
ub = UnitfulBlock()
765-
end
766-
@equations begin
781+
782+
equations = Equation[
767783
connect(ub.output, :ap, input)
768784
output ~ input.u^2
769-
end
785+
]
786+
787+
return System(equations, t, vars, pars; name, systems)
770788
end
771789
@named sys2 = TestAPWithNoOutputs()
772790
@test sys2 isa System

lib/ModelingToolkitBase/test/basic_transformations.jl

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ using ModelingToolkitStandardLibrary.Blocks: RealInput, RealOutput
33
using Symbolics: value
44
using SymbolicUtils: symtype, _iszero
55
using ModelingToolkitBase: SymbolicContinuousCallback
6-
using SciCompDSL
76

87
@independent_variables t
98
D = Differential(t)
@@ -256,48 +255,72 @@ end
256255

257256
@testset "Change independent variable, no equations" begin
258257
# make this "look" like the standard library RealInput
259-
@mtkmodel Input begin
260-
@variables begin
258+
@component function Input(; name)
259+
pars = @parameters begin
260+
end
261+
262+
systems = @named begin
263+
end
264+
265+
vars = @variables begin
261266
u(t)
262267
end
268+
269+
equations = Equation[]
270+
271+
return System(equations, t, vars, pars; name, systems)
263272
end
264273
@named input_sys = Input()
265274
input_sys = complete(input_sys)
266275
# test no failures
267276
@test change_independent_variable(input_sys, input_sys.u) isa System
268277

269-
@mtkmodel NestedInput begin
270-
@components begin
278+
@component function NestedInput(; name)
279+
pars = @parameters begin
280+
end
281+
282+
systems = @named begin
271283
in = Input()
272284
end
273-
@variables begin
285+
286+
vars = @variables begin
274287
x(t)
275288
end
276-
@equations begin
289+
290+
equations = Equation[
277291
D(x) ~ in.u
278-
end
292+
]
293+
294+
return System(equations, t, vars, pars; name, systems)
279295
end
280296
@named nested_input_sys = NestedInput()
281297
nested_input_sys = complete(nested_input_sys; flatten = false)
282298
@test change_independent_variable(nested_input_sys, nested_input_sys.x) isa System
283299
end
284300

285301
@testset "Change of variables, connections" begin
286-
@mtkmodel ConnectSys begin
287-
@components begin
302+
@component function ConnectSys(; name)
303+
pars = @parameters begin
304+
end
305+
306+
systems = @named begin
288307
in = RealInput()
289308
out = RealOutput()
290309
end
291-
@variables begin
310+
311+
vars = @variables begin
292312
x(t)
293313
y(t)
294314
end
295-
@equations begin
315+
316+
equations = Equation[
296317
connect(in, out)
297318
in.u ~ x
298319
D(x) ~ -out.u
299320
D(y) ~ 1
300-
end
321+
]
322+
323+
return System(equations, t, vars, pars; name, systems)
301324
end
302325
@named sys = ConnectSys()
303326
sys = complete(sys; flatten = false)

lib/ModelingToolkitBase/test/causal_variables_connection.jl

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using ModelingToolkitBase, ModelingToolkitStandardLibrary.Blocks
2-
using SciCompDSL
32
using ModelingToolkitBase: t_nounits as t, D_nounits as D
43
using Test
54

@@ -96,27 +95,44 @@ if @isdefined(ModelingToolkit)
9695
end
9796

9897
@testset "Outside input to inside input connection" begin
99-
@mtkmodel Inner begin
100-
@variables begin
98+
@component function Inner(; name)
99+
pars = @parameters begin
100+
end
101+
102+
systems = @named begin
103+
end
104+
105+
vars = @variables begin
101106
x(t), [input = true]
102107
y(t), [output = true]
103108
end
104-
@equations begin
109+
110+
equations = Equation[
105111
y ~ x
106-
end
112+
]
113+
114+
return System(equations, t, vars, pars; name, systems)
107115
end
108-
@mtkmodel Outer begin
109-
@variables begin
110-
u(t), [input = true]
111-
v(t), [output = true]
116+
117+
@component function Outer(; name)
118+
pars = @parameters begin
112119
end
113-
@components begin
120+
121+
systems = @named begin
114122
inner = Inner()
115123
end
116-
@equations begin
124+
125+
vars = @variables begin
126+
u(t), [input = true]
127+
v(t), [output = true]
128+
end
129+
130+
equations = Equation[
117131
connect(u, inner.x)
118132
connect(inner.y, v)
119-
end
133+
]
134+
135+
return System(equations, t, vars, pars; name, systems)
120136
end
121137
@named sys = Outer()
122138
ss = toggle_namespacing(sys, false)

lib/ModelingToolkitBase/test/common/rc_model.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import ModelingToolkitStandardLibrary.Electrical as El
22
import ModelingToolkitStandardLibrary.Blocks as Bl
3-
using SciCompDSL
43

54
@component function RCModel(; name)
65
pars = @parameters begin
Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,41 @@
11
import ModelingToolkitStandardLibrary.Electrical as El
22
import ModelingToolkitStandardLibrary.Blocks as Bl
3-
using SciCompDSL
43

5-
@mtkmodel LLModel begin
6-
@components begin
4+
@component function LLModel(; name)
5+
pars = @parameters begin
6+
end
7+
8+
systems = @named begin
79
shape = Bl.Constant(k = 10.0)
810
source = El.Voltage()
911
resistor = El.Resistor(R = 1.0)
1012
inductor1 = El.Inductor(L = 1.0e-2)
1113
inductor2 = El.Inductor(L = 2.0e-2)
1214
ground = El.Ground()
1315
end
14-
@equations begin
16+
17+
vars = @variables begin
18+
end
19+
20+
equations = Equation[
1521
connect(shape.output, source.V)
1622
connect(source.p, resistor.p)
1723
connect(resistor.n, inductor1.p)
1824
connect(inductor1.n, inductor2.p)
1925
connect(source.n, inductor2.n)
2026
connect(inductor2.n, ground.g)
21-
end
27+
]
28+
29+
return System(equations, t, vars, pars; name, systems)
2230
end
2331

2432
@named ll_model = LLModel()
2533

26-
@mtkmodel LL2Model begin
27-
@components begin
34+
@component function LL2Model(; name)
35+
pars = @parameters begin
36+
end
37+
38+
systems = @named begin
2839
shape = Bl.Constant(k = 10.0)
2940
source = El.Voltage()
3041
resistor1 = El.Resistor(R = 1.0)
@@ -33,7 +44,11 @@ end
3344
inductor2 = El.Inductor(L = 2.0e-2)
3445
ground = El.Ground()
3546
end
36-
@equations begin
47+
48+
vars = @variables begin
49+
end
50+
51+
equations = Equation[
3752
connect(shape.output, source.V)
3853
connect(source.p, inductor1.p)
3954
connect(inductor1.n, resistor1.p)
@@ -42,7 +57,9 @@ end
4257
connect(resistor2.n, inductor2.p)
4358
connect(source.n, inductor2.n)
4459
connect(inductor2.n, ground.g)
45-
end
60+
]
61+
62+
return System(equations, t, vars, pars; name, systems)
4663
end
4764

4865
@named ll2_model = LL2Model()

lib/ModelingToolkitBase/test/complex.jl

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
using ModelingToolkitBase
22
using ModelingToolkitBase: t_nounits as t
3-
using SciCompDSL
43
using Test
54

6-
@mtkmodel ComplexModel begin
7-
@variables begin
5+
@component function ComplexModel(; name)
6+
pars = @parameters begin
7+
end
8+
9+
systems = @named begin
10+
end
11+
12+
vars = @variables begin
813
x(t)
914
y(t)
1015
z(t)::Complex{Real}
1116
end
12-
@equations begin
13-
z ~ x + im * y
14-
end
17+
18+
equations = Equation[
19+
z ~ x + im * y;
20+
]
21+
22+
return System(equations, t, vars, pars; name, systems)
1523
end
1624
@named mixed = ComplexModel()
1725
@test length(equations(mixed)) == 2

0 commit comments

Comments
 (0)