Skip to content

Commit

Permalink
Don't test setchildcontext on leaf contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
penelopeysm committed Nov 28, 2024
1 parent 1a0982c commit 527b389
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/test_utils/contexts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ function test_context(context::DynamicPPL.AbstractContext, model::DynamicPPL.Mod
node_trait isa Union{DynamicPPL.IsLeaf,DynamicPPL.IsParent} ||
throw(ValueError("Invalid NodeTrait: $node_trait"))

# To see change, let's make sure we're using a different leaf context than the current.
leafcontext_new = if DynamicPPL.leafcontext(context) isa DefaultContext
PriorContext()
else
DefaultContext()
end
@test DynamicPPL.leafcontext(DynamicPPL.setleafcontext(context, leafcontext_new)) ==
leafcontext_new

# The interface methods.
if node_trait isa DynamicPPL.IsParent
# `childcontext` and `setchildcontext`
Expand All @@ -79,22 +88,14 @@ function test_context(context::DynamicPPL.AbstractContext, model::DynamicPPL.Mod
@test DynamicPPL.childcontext(
DynamicPPL.setchildcontext(context, childcontext_new)
) == childcontext_new
# Setting the child context to a leaf should now change the leafcontext
# accordingly.
context_with_new_leaf = DynamicPPL.setchildcontext(context, leafcontext_new)
@test DynamicPPL.childcontext(context_with_new_leaf) ===
DynamicPPL.leafcontext(context_with_new_leaf) ===
leafcontext_new
end

# To see change, let's make sure we're using a different leaf context than the current.
leafcontext_new = if DynamicPPL.leafcontext(context) isa DefaultContext
PriorContext()
else
DefaultContext()
end
@test DynamicPPL.leafcontext(DynamicPPL.setleafcontext(context, leafcontext_new)) ==
leafcontext_new

# Setting the child context to a leaf should now change the leafcontext accordingly.
context_with_new_leaf = DynamicPPL.setchildcontext(context, leafcontext_new)
@test DynamicPPL.childcontext(context_with_new_leaf) ===
DynamicPPL.leafcontext(context_with_new_leaf) ===
leafcontext_new

# Make sure that the we can evaluate the model with the context (i.e. that none of the tilde-functions are incorrectly overloaded).
# The tilde-pipeline contains two different paths: with `SamplingContext` as a parent, and without it.
Expand Down

0 comments on commit 527b389

Please sign in to comment.