Skip to content

Commit

Permalink
fix poor closing of jld2 files
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierlabayle committed Dec 22, 2023
1 parent 1518216 commit bcd5ba5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
27 changes: 14 additions & 13 deletions test/runner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,17 @@ end
end

# Check results from HDF5
results_from_hdf5 = jldopen(outputs.hdf5.filename)["Batch_1"]
for estimator in (:OSE, :TMLE)
@test results_from_hdf5[1][estimator] isa TargetedEstimation.FailedEstimate
@test results_from_hdf5[2][estimator] isa TMLE.EICEstimate
for i in 3:6
@test results_from_hdf5[i][estimator] isa TargetedEstimation.FailedEstimate
@test results_from_hdf5[i][estimator].estimand isa TMLE.Estimand
jldopen(outputs.hdf5.filename) do io
results_from_hdf5 = io["Batch_1"]
for estimator in (:OSE, :TMLE)
@test results_from_hdf5[1][estimator] isa TargetedEstimation.FailedEstimate
@test results_from_hdf5[2][estimator] isa TMLE.EICEstimate
for i in 3:6
@test results_from_hdf5[i][estimator] isa TargetedEstimation.FailedEstimate
@test results_from_hdf5[i][estimator].estimand isa TMLE.Estimand
end
end
end
close(results_from_hdf5)
# Clean
rm(outputs.json.filename)
rm(outputs.hdf5.filename)
Expand Down Expand Up @@ -285,11 +286,11 @@ end
@test length(results_from_json) == 3

# HDF5
results_from_hdf5 = jldopen("output.hdf5")
@test length(results_from_hdf5["Batch_1"]) == 2
composed_result = only(results_from_hdf5["Batch_2"])
@test composed_result.OSE.cov == results[3].OSE.cov
close(results_from_hdf5)
jldopen("output.hdf5") do io
@test length(io["Batch_1"]) == 2
composed_result = only(io["Batch_2"])
@test composed_result.OSE.cov == results[3].OSE.cov
end

rm(datafile)
rm("output.jls")
Expand Down
10 changes: 4 additions & 6 deletions test/sieve_variance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ end
# Check results
svp_results = io["results"]

tmleout1 = jldopen("tmle_output_1.hdf5")["Batch_1"]
tmleout2 = jldopen("tmle_output_2.hdf5")["Batch_1"]
tmleout1 = jldopen(x -> x["Batch_1"], "tmle_output_1.hdf5")
tmleout2 = jldopen(x -> x["Batch_1"], "tmle_output_2.hdf5")
src_results = [tmleout1..., tmleout2...]

for svp_result in svp_results
Expand All @@ -313,8 +313,7 @@ end
@test src_result.TMLE.n == svp_result.TMLE.n
@test svp_result.TMLE.IC == []
end
close(tmleout1)
close(tmleout2)

close(io)
# clean
rm("svp.hdf5")
Expand Down Expand Up @@ -348,7 +347,7 @@ end
])

# The ComposedEstimate std is not updated but each component is.
src_results = jldopen("tmle_output.hdf5")["Batch_1"]
src_results = jldopen(x -> x["Batch_1"], "tmle_output.hdf5")
io = jldopen("svp.hdf5")
svp_results = io["results"]
standalone_estimates = svp_results[1:2]
Expand All @@ -363,7 +362,6 @@ end
@test standalone_estimates[i].OSE.std != src_results[i].OSE.std
end

close(src_results)
close(io)

# clean
Expand Down

0 comments on commit bcd5ba5

Please sign in to comment.