@@ -185,58 +185,96 @@ def test_pruning_raises_for_bad_output():
185185
186186
187187def test_pruning_not_overrides_given_intermediate ():
188- # Test #25: not overriding intermediate data when an output is not asked
189- graph = compose (name = "graph " )(
190- operation (name = "unjustly run" , needs = ["a" ], provides = ["overriden" ])(lambda a : a ),
188+ # Test #25: v1.2.4 overrides intermediate data when no output asked
189+ netop = compose (name = "netop " )(
190+ operation (name = "unjustly run" , needs = ["a" ], provides = ["overriden" ])(lambda x : x ),
191191 operation (name = "op" , needs = ["overriden" , "c" ], provides = ["asked" ])(add ),
192192 )
193193
194- assert graph ({"a" : 5 , "overriden" : 1 , "c" : 2 }, ["asked" ]) == {"asked" : 3 } # that"s ok
195- assert graph ({"a" : 5 , "overriden" : 1 , "c" : 2 }) == {"a" : 5 , "overriden" : 1 , "c" : 2 , "asked" : 3 } # FAILs
194+ # v1.2.4.ok
195+ assert netop ({"a" : 5 , "overriden" : 1 , "c" : 2 }, ["asked" ]) == {"asked" : 3 }
196+ # FAILs
197+ # - on v1.2.4 with (overriden, asked): = (5, 7) instead of (1, 3)
198+ # - on #18(unsatisfied) with (overriden, asked) = (5, 7) instead of (1, 3)
199+ assert (
200+ netop ({"a" : 5 , "overriden" : 1 , "c" : 2 })
201+ ==
202+ {"a" : 5 , "overriden" : 1 , "c" : 2 , "asked" : 3 })
203+
204+
205+ def test_pruning_multiouts_not_override_intermediates ():
206+ # Test #25: v.1.2.4 overrides intermediate data when a previous operation
207+ # must run for its other outputs (outputs asked or not)
208+ netop = compose (name = "netop" )(
209+ operation (name = "must run" , needs = ["a" ], provides = ["overriden" , "e" ])
210+ (lambda x : (x , 2 * x )),
211+ operation (name = "op1" , needs = ["overriden" , "c" ], provides = ["d" ])(add ),
212+ operation (name = "op2" , needs = ["d" , "e" ], provides = ["asked" ])(lambda x , y : x * y ),
213+ )
214+
215+ # FAILs
216+ # - on v1.2.4 with KeyError: 'e',
217+ # - on #18(unsatisfied) with empty result.
218+ assert netop ({"a" : 5 , "overriden" : 1 , "c" : 2 }, ["asked" ]) == {"asked" : 3 }
219+ # FAILs
220+ # - on v1.2.4 with (overriden, asked) = (5, 70) instead of (1, 13)
221+ # - on #18(unsatisfied) like v1.2.4.
222+ assert (
223+ netop ({"a" : 5 , "overriden" : 1 , "c" : 2 })
224+ ==
225+ {"a" : 5 , "overriden" : 1 , "c" : 2 , "asked" : 3 })
196226
197227
198228def test_pruning_with_given_intermediate_and_asked_out ():
199- # Test pruning intermidate data is the same when outputs are (not) asked .
200- graph = compose (name = "graph" )(
201- operation (name = "unjustly pruned" , needs = ["given-1" ], provides = ["a" ])(lambda a : a ),
229+ # Test #24: v1.2.4 does not prune before given intermediate data when
230+ # outputs not asked, but does so when output asked.
231+ netop = compose (name = "netop" )(
232+ operation (name = "unjustly pruned" , needs = ["given-1" ], provides = ["a" ])(lambda x : x ),
202233 operation (name = "shortcuted" , needs = ["a" , "b" ], provides = ["given-2" ])(add ),
203234 operation (name = "good_op" , needs = ["a" , "given-2" ], provides = ["asked" ])(add ),
204235 )
205236
206- assert graph ({"given-1" : 5 , "b" : 2 , "given-2" : 2 }) == {"given-1" : 5 , "b" : 2 , "given-2" : 7 , "a" : 5 , "b" : 2 , "asked" : 12 } # that ok # FAILS!
207- assert graph ({"given-1" : 5 , "b" : 2 , "given-2" : 2 }, ["asked" ]) == {"asked" : 12 } # FAILS!
237+ # v1.2.4 is ok
238+ assert (
239+ netop ({"given-1" : 5 , "b" : 2 , "given-2" : 2 })
240+ ==
241+ {"given-1" : 5 , "b" : 2 , "given-2" : 7 , "a" : 5 , "asked" : 12 })
242+ # FAILS
243+ # - on v1.2.4 with KeyError: 'a',
244+ # - on #19 (unsatisfied) with no result.
245+ assert netop ({"given-1" : 5 , "b" : 2 , "given-2" : 2 }, ["asked" ]) == {"asked" : 12 }
208246
209247
210248def test_unsatisfied_operations ():
211249 # Test that operations with partial inputs are culled and not failing.
212- graph = compose (name = "graph " )(
250+ netop = compose (name = "netop " )(
213251 operation (name = "add" , needs = ["a" , "b1" ], provides = ["a+b1" ])(add ),
214252 operation (name = "sub" , needs = ["a" , "b2" ], provides = ["a-b2" ])(sub ),
215253 )
216-
254+
217255 exp = {"a" : 10 , "b1" : 2 , "a+b1" : 12 }
218- assert graph ({"a" : 10 , "b1" : 2 }) == exp
219- assert graph ({"a" : 10 , "b1" : 2 }, outputs = ["a+b1" ]) == {"a+b1" : 12 }
256+ assert netop ({"a" : 10 , "b1" : 2 }) == exp
257+ assert netop ({"a" : 10 , "b1" : 2 }, outputs = ["a+b1" ]) == {"a+b1" : 12 }
220258
221259 exp = {"a" : 10 , "b2" : 2 , "a-b2" : 8 }
222- assert graph ({"a" : 10 , "b2" : 2 }) == exp
223- assert graph ({"a" : 10 , "b2" : 2 }, outputs = ["a-b2" ]) == {"a-b2" : 8 }
260+ assert netop ({"a" : 10 , "b2" : 2 }) == exp
261+ assert netop ({"a" : 10 , "b2" : 2 }, outputs = ["a-b2" ]) == {"a-b2" : 8 }
224262
225263def test_unsatisfied_operations_same_out ():
226264 # Test unsatisfied pairs of operations providing the same output.
227- graph = compose (name = "graph " )(
265+ netop = compose (name = "netop " )(
228266 operation (name = "mul" , needs = ["a" , "b1" ], provides = ["ab" ])(mul ),
229267 operation (name = "div" , needs = ["a" , "b2" ], provides = ["ab" ])(floordiv ),
230268 operation (name = "add" , needs = ["ab" , "c" ], provides = ["ab_plus_c" ])(add ),
231269 )
232-
270+
233271 exp = {"a" : 10 , "b1" : 2 , "c" : 1 , "ab" : 20 , "ab_plus_c" : 21 }
234- assert graph ({"a" : 10 , "b1" : 2 , "c" : 1 }) == exp
235- assert graph ({"a" : 10 , "b1" : 2 , "c" : 1 }, outputs = ["ab_plus_c" ]) == {"ab_plus_c" : 21 }
272+ assert netop ({"a" : 10 , "b1" : 2 , "c" : 1 }) == exp
273+ assert netop ({"a" : 10 , "b1" : 2 , "c" : 1 }, outputs = ["ab_plus_c" ]) == {"ab_plus_c" : 21 }
236274
237275 exp = {"a" : 10 , "b2" : 2 , "c" : 1 , "ab" : 5 , "ab_plus_c" : 6 }
238- assert graph ({"a" : 10 , "b2" : 2 , "c" : 1 }) == exp
239- assert graph ({"a" : 10 , "b2" : 2 , "c" : 1 }, outputs = ["ab_plus_c" ]) == {"ab_plus_c" : 6 }
276+ assert netop ({"a" : 10 , "b2" : 2 , "c" : 1 }) == exp
277+ assert netop ({"a" : 10 , "b2" : 2 , "c" : 1 }, outputs = ["ab_plus_c" ]) == {"ab_plus_c" : 6 }
240278
241279
242280def test_optional ():
0 commit comments