66from ymmsl .v0_2 import ConduitFilter , Configuration , Timeline
77from ymmsl .v0_2 import Reference as Ref
88from ymmsl .v0_2 .timeline_resolver import (
9- ROOT_TIMELINE ,
109 ConduitTimelineError ,
1110 CyclicDependency ,
1211 InconsistentTimelines ,
1312 TooManyReducerFilters ,
13+ check_timelines ,
1414 resolve_timelines ,
1515)
1616
@@ -29,24 +29,15 @@ def test_consistent_configuration(timelines_configuration: Configuration) -> Non
2929def test_dispatch (timelines_configuration : Configuration ) -> None :
3030 model = timelines_configuration .models [Ref ("dispatch" )]
3131 resolve_timelines (model )
32- assert model .components [Ref ("first" )].timeline == ROOT_TIMELINE
33- assert model .components [Ref ("second" )].timeline == ROOT_TIMELINE
32+ assert model .components [Ref ("first" )].timeline == ":first"
33+ assert model .components [Ref ("second" )].timeline == ":second"
3434
3535
3636def test_macromicro (timelines_configuration : Configuration ) -> None :
3737 model = timelines_configuration .models [Ref ("macromicro" )]
3838 resolve_timelines (model )
39- assert model .components [Ref ("macro" )].timeline == ROOT_TIMELINE
40- assert model .components [Ref ("micro" )].timeline == Timeline (":macro" )
41-
42- # Check that ports have the correct relative timelines:
43- macro = model .components [Ref ("macro" )]
44- assert macro .ports ["init" ].timeline == Timeline ("" )
45- assert macro .ports ["out" ].timeline == Timeline ("macro" )
46- assert macro .ports ["in" ].timeline == Timeline ("macro" )
47-
48- for micro_port in model .components [Ref ("micro" )].ports .values ():
49- assert micro_port .timeline == Timeline ("" )
39+ assert model .components [Ref ("macro" )].timeline == Timeline (":macro" )
40+ assert model .components [Ref ("micro" )].timeline == Timeline (":macro:micro" )
5041
5142
5243def test_cycle (timelines_configuration : Configuration ) -> None :
@@ -57,8 +48,8 @@ def test_cycle(timelines_configuration: Configuration) -> None:
5748def test_reducer (timelines_configuration : Configuration ) -> None :
5849 model = timelines_configuration .models [Ref ("reducer" )]
5950 resolve_timelines (model )
60- assert model .components [Ref ("first" )].timeline == ROOT_TIMELINE
61- assert model .components [Ref ("second" )].timeline == ROOT_TIMELINE
51+ assert model .components [Ref ("first" )].timeline == Timeline ( ":first" )
52+ assert model .components [Ref ("second" )].timeline == Timeline ( ":second" )
6253
6354
6455def test_only_reducer (timelines_configuration : Configuration ) -> None :
@@ -67,8 +58,8 @@ def test_only_reducer(timelines_configuration: Configuration) -> None:
6758 del model .conduits [0 ]
6859 assert model .conduits [0 ].filters == [ConduitFilter ("last" )]
6960 resolve_timelines (model )
70- assert model .components [Ref ("first" )].timeline == ROOT_TIMELINE
71- assert model .components [Ref ("second" )].timeline == ROOT_TIMELINE
61+ assert model .components [Ref ("first" )].timeline == Timeline ( ":first" )
62+ assert model .components [Ref ("second" )].timeline == Timeline ( ":second" )
7263
7364
7465def test_too_many_reducers (timelines_configuration : Configuration ) -> None :
@@ -86,9 +77,9 @@ def test_inconsistent_timelines(timelines_configuration: Configuration) -> None:
8677def test_repeaters (timelines_configuration : Configuration ) -> None :
8778 model = timelines_configuration .models [Ref ("repeaters" )]
8879 resolve_timelines (model )
89- assert model .components [Ref ("macro" )].timeline == ROOT_TIMELINE
90- assert model .components [Ref ("meso" )].timeline == Timeline (":macro" )
91- assert model .components [Ref ("micro" )].timeline == Timeline (":macro:meso" )
80+ assert model .components [Ref ("macro" )].timeline == Timeline ( ":macro" )
81+ assert model .components [Ref ("meso" )].timeline == Timeline (":macro:meso " )
82+ assert model .components [Ref ("micro" )].timeline == Timeline (":macro:meso:micro " )
9283
9384
9485def test_too_many_repeaters (timelines_configuration : Configuration ) -> None :
@@ -115,10 +106,10 @@ def test_repeater_and_too_many_reducers(timelines_configuration: Configuration)
115106def test_repeater_after_reducer (timelines_configuration : Configuration ) -> None :
116107 model = timelines_configuration .models [Ref ("repeater_reducer" )]
117108 resolve_timelines (model )
118- assert model .components [Ref ("macro1" )].timeline == ROOT_TIMELINE
119- assert model .components [Ref ("macro2" )].timeline == ROOT_TIMELINE
120- assert model .components [Ref ("micro1" )].timeline == Timeline (":macro1" )
121- assert model .components [Ref ("micro2" )].timeline == Timeline (":macro2" )
109+ assert model .components [Ref ("macro1" )].timeline == Timeline ( ":macro1" )
110+ assert model .components [Ref ("macro2" )].timeline == Timeline ( ":macro2" )
111+ assert model .components [Ref ("micro1" )].timeline == Timeline (":macro1:micro1 " )
112+ assert model .components [Ref ("micro2" )].timeline == Timeline (":macro2:micro2 " )
122113
123114 # Remove filters on the last conduit to make the incoming timelines inconsistent
124115 model .conduits [- 1 ].filters = []
@@ -132,18 +123,26 @@ def test_repeater_after_reducer_error(timelines_configuration: Configuration) ->
132123 resolve_timelines (model )
133124 model .conduits [- 1 ].filters = []
134125 resolve_timelines (model )
135- assert model .components [Ref ("macro" )].timeline == ROOT_TIMELINE
136- assert model .components [Ref ("micro1" )].timeline == Timeline (":macro" )
137- assert model .components [Ref ("micro2" )].timeline == Timeline (":macro" )
126+ assert model .components [Ref ("macro" )].timeline == Timeline ( ":macro" )
127+ assert model .components [Ref ("micro1" )].timeline == Timeline (":macro:micro1 " )
128+ assert model .components [Ref ("micro2" )].timeline == Timeline (":macro:micro2 " )
138129
139130
140131def test_inconsistent_interact (timelines_configuration : Configuration ) -> None :
141132 model = timelines_configuration .models [Ref ("inconsistent_interact" )]
142133 with pytest .raises (ConduitTimelineError , match = "missing timeline annotations" ):
143134 resolve_timelines (model )
144- model .components [Ref ("B" )].ports ["out" ].timeline = Timeline ("A" )
145- model .components [Ref ("B" )].ports ["in" ].timeline = Timeline ("A" )
146- resolve_timelines (model )
135+ # TODO: add matching_timelines and try again successfully
136+
137+
138+ def test_subtimelines (timelines_configuration : Configuration ) -> None :
139+ model = timelines_configuration .models [Ref ("different_subtimelines" )]
140+ check_timelines (model )
141+
142+ model .conduits [0 ].receiver = Ref ("micro2.init" )
143+ model .conduits [2 ].receiver = Ref ("micro1.init" )
144+ with pytest .raises (ConduitTimelineError , match = "these do not match" ):
145+ resolve_timelines (model )
147146
148147
149148def test_model_ports (timelines_configuration : Configuration ) -> None :
0 commit comments