diff --git a/test/runner.jl b/test/runner.jl index 97e39b4..88b01da 100644 --- a/test/runner.jl +++ b/test/runner.jl @@ -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) @@ -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") diff --git a/test/sieve_variance.jl b/test/sieve_variance.jl index 8365d1b..0095067 100644 --- a/test/sieve_variance.jl +++ b/test/sieve_variance.jl @@ -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 @@ -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") @@ -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] @@ -363,7 +362,6 @@ end @test standalone_estimates[i].OSE.std != src_results[i].OSE.std end - close(src_results) close(io) # clean