Skip to content

Commit 1db7d98

Browse files
committed
Fix fragile Dict doctests
1 parent 5c1a2df commit 1db7d98

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/contexts.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,8 +702,14 @@ ConditionContext(Dict(a.x => 1), DefaultContext())
702702
julia> # Here, `x` gets prefixed only with `a`, whereas `y` is prefixed with both.
703703
c2 = PrefixContext{:a}(ConditionContext((x=1, ), PrefixContext{:b}(ConditionContext((y=2,)))));
704704
705-
julia> collapse_prefix_stack(c2)
706-
ConditionContext(Dict{VarName{:a}, Int64}(a.b.y => 2, a.x => 1), DefaultContext())
705+
julia> collapsed = collapse_prefix_stack(c2);
706+
707+
julia> # `collapsed` really looks something like this:
708+
# ConditionContext(Dict{VarName{:a}, Int64}(a.b.y => 2, a.x => 1), DefaultContext())
709+
# To avoid fragility arising from the order of the keys in the doctest, we test
710+
# this indirectly:
711+
collapsed.values[@varname(a.x)], collapsed.values[@varname(a.b.y)]
712+
(1, 2)
707713
```
708714
"""
709715
function collapse_prefix_stack(context::PrefixContext{Prefix}) where {Prefix}

src/model.jl

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -431,10 +431,8 @@ julia> # Nested ones also work.
431431
# container has to be broadened to a `Dict`.)
432432
cm = condition(contextualize(m, PrefixContext{:a}(ConditionContext((m=1.0,)))), x=100.0);
433433
434-
julia> conditioned(cm)
435-
Dict{VarName, Any} with 2 entries:
436-
a.m => 1.0
437-
x => 100.0
434+
kulia> Set(keys(conditioned(cm))) == Set([@varname(a.m), @varname(x)])
435+
true
438436
439437
julia> # Since we conditioned on `a.m`, it is not treated as a random variable.
440438
# However, `a.x` will still be a random variable.
@@ -773,10 +771,8 @@ julia> # Returns all the variables we have fixed on + their values.
773771
julia> # The rest of this is the same as the `condition` example above.
774772
cm = fix(contextualize(m, PrefixContext{:a}(fix(m=1.0))), x=100.0);
775773
776-
julia> fixed(cm)
777-
Dict{VarName, Any} with 2 entries:
778-
a.m => 1.0
779-
x => 100.0
774+
kulia> Set(keys(fixed(cm))) == Set([@varname(a.m), @varname(x)])
775+
true
780776
781777
julia> keys(VarInfo(cm))
782778
1-element Vector{VarName{:a, Accessors.PropertyLens{:x}}}:

0 commit comments

Comments
 (0)