Skip to content

Commit 72ac7a1

Browse files
authored
Merge pull request #971 from SciML/tests___new_tests___rs_serlalisation
Expand reaction system serialisation tests
2 parents abf9b93 + 283215b commit 72ac7a1

File tree

1 file changed

+64
-1
lines changed

1 file changed

+64
-1
lines changed

test/miscellaneous_tests/reactionsystem_serialisation.jl

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,4 +462,67 @@ let
462462
rs_incomplete_loaded = include("../serialised_rs_incomplete.jl")
463463
@test !ModelingToolkit.iscomplete(rs_incomplete_loaded)
464464
rm("serialised_rs_incomplete.jl")
465-
end
465+
end
466+
467+
# Tests network without species, reactions, and parameters.
468+
let
469+
# Creates model.
470+
rs = @reaction_network begin
471+
@equations D(V) ~ -V
472+
end
473+
474+
# Checks its serialisation.
475+
save_reactionsystem("test_serialisation.jl", rs; safety_check = false)
476+
isequal(rs, include("../test_serialisation.jl"))
477+
rm("test_serialisation.jl")
478+
end
479+
480+
# Tests various corner cases (multiple observables, species observables, non-default combinatoric
481+
# rate law, and rate law disabling)
482+
let
483+
# Creates model.
484+
rs = @reaction_network begin
485+
@combinatoric_ratelaws false
486+
@species Xcount(t)
487+
@observables begin
488+
Xtot ~ X + 2X2
489+
Xcount ~ X + X2
490+
end
491+
p, 0 --> X
492+
d*X2, X => 0
493+
(k1,k2), 2X <--> X2
494+
end
495+
496+
# Checks its serialisation.
497+
save_reactionsystem("test_serialisation.jl", rs; safety_check = false)
498+
isequal(rs, include("../test_serialisation.jl"))
499+
rm("test_serialisation.jl")
500+
end
501+
502+
# Tests saving of empty network.
503+
let
504+
rs = @reaction_network
505+
save_reactionsystem("test_serialisation.jl", rs; safety_check = false)
506+
isequal(rs, include("../test_serialisation.jl"))
507+
rm("test_serialisation.jl")
508+
end
509+
510+
# Test that serialisation of unknown type (here a function) yields an error.
511+
let
512+
rs = @reaction_network begin
513+
d, X --> 0, [misc = x -> 2x]
514+
end
515+
@test_throws Exception save_reactionsystem("test_serialisation.jl", rs)
516+
end
517+
518+
# Test connection field.
519+
# Not really used for `ReactionSystem`s right now, so tests the direct function and its warning.
520+
let
521+
rs = @reaction_network begin
522+
d, X --> 0
523+
end
524+
@test (@test_logs (:warn, ) match_mode=:any Catalyst.get_connection_type_string(rs)) == ""
525+
@test Catalyst.get_connection_type_annotation(rs) == "Connection types:: (OBS: Currently not supported, and hence empty)"
526+
end
527+
528+

0 commit comments

Comments
 (0)