@@ -71,6 +71,15 @@ function test_context(context::DynamicPPL.AbstractContext, model::DynamicPPL.Mod
7171 node_trait isa Union{DynamicPPL. IsLeaf,DynamicPPL. IsParent} ||
7272 throw (ValueError (" Invalid NodeTrait: $node_trait " ))
7373
74+ # To see change, let's make sure we're using a different leaf context than the current.
75+ leafcontext_new = if DynamicPPL. leafcontext (context) isa DefaultContext
76+ PriorContext ()
77+ else
78+ DefaultContext ()
79+ end
80+ @test DynamicPPL. leafcontext (DynamicPPL. setleafcontext (context, leafcontext_new)) ==
81+ leafcontext_new
82+
7483 # The interface methods.
7584 if node_trait isa DynamicPPL. IsParent
7685 # `childcontext` and `setchildcontext`
@@ -79,22 +88,14 @@ function test_context(context::DynamicPPL.AbstractContext, model::DynamicPPL.Mod
7988 @test DynamicPPL. childcontext (
8089 DynamicPPL. setchildcontext (context, childcontext_new)
8190 ) == childcontext_new
91+ # Setting the child context to a leaf should now change the leafcontext
92+ # accordingly.
93+ context_with_new_leaf = DynamicPPL. setchildcontext (context, leafcontext_new)
94+ @test DynamicPPL. childcontext (context_with_new_leaf) ===
95+ DynamicPPL. leafcontext (context_with_new_leaf) ===
96+ leafcontext_new
8297 end
8398
84- # To see change, let's make sure we're using a different leaf context than the current.
85- leafcontext_new = if DynamicPPL. leafcontext (context) isa DefaultContext
86- PriorContext ()
87- else
88- DefaultContext ()
89- end
90- @test DynamicPPL. leafcontext (DynamicPPL. setleafcontext (context, leafcontext_new)) ==
91- leafcontext_new
92-
93- # Setting the child context to a leaf should now change the leafcontext accordingly.
94- context_with_new_leaf = DynamicPPL. setchildcontext (context, leafcontext_new)
95- @test DynamicPPL. childcontext (context_with_new_leaf) ===
96- DynamicPPL. leafcontext (context_with_new_leaf) ===
97- leafcontext_new
9899
99100 # Make sure that the we can evaluate the model with the context (i.e. that none of the tilde-functions are incorrectly overloaded).
100101 # The tilde-pipeline contains two different paths: with `SamplingContext` as a parent, and without it.
0 commit comments