-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve overriding energy parameter dirs via env vars (#5)
Improve overriding energy parameter dirs via env vars Always ensure the DATAPATH, CYCLEFOLD_DATAPATH env vars are pointing to the correct path from the `RNAstructure_jll` binary package. These paths can be overridden with the RNASTRUCTURE_JL_DATAPATH, RNASTRUCTURE_JLCYCLEFOLD_DATAPATH env vars if necessary. Don't warn if the DATAPATH, CYCLEFOLD_DATAPATH env vars are already set to the correct directories. This avoids unnecessary warnings when running the tests. Fixes #4.
- Loading branch information
Showing
4 changed files
with
100 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
@testset "__init__ env vars" begin | ||
showtestset() | ||
|
||
upstream_env_vars = [ | ||
"DATAPATH", | ||
"CYCLEFOLD_DATAPATH", | ||
] | ||
our_env_vars = ["RNASTRUCTURE_JL_" * e for e in upstream_env_vars] | ||
env_var_mapping = Dict(e => "RNASTRUCTURE_JL_" * e for e in upstream_env_vars) | ||
all_env_vars = [upstream_env_vars..., our_env_vars...] | ||
|
||
function delete_all_env_vars() | ||
for e in all_env_vars | ||
delete!(ENV, e); | ||
end | ||
end | ||
|
||
# save relevant ENV vars so that we can change them here for | ||
# testing and then restore them later | ||
saved_env_vars = Dict{String,String}() | ||
for e in all_env_vars | ||
if haskey(ENV, e) | ||
saved_env_vars[e] = ENV[e] | ||
delete!(ENV, e) | ||
end | ||
end | ||
|
||
@test RNAstructure.__init__() == nothing | ||
delete_all_env_vars() | ||
|
||
# setting DATAPATH, etc | ||
for e in upstream_env_vars | ||
ENV[e] = "non-existent-dir-path" | ||
warn_msg = ("RNAstructure: $e env var set, replacing with $(saved_env_vars[e])\n" | ||
* "To override $e used by RNAstructure, set the RNASTRUCTURE_JL_$e env var") | ||
@test (@test_logs (:warn, (warn_msg)) RNAstructure.__init__()) == nothing | ||
delete_all_env_vars() | ||
end | ||
|
||
# setting RNASTRUCTURE_JL_* | ||
for (upstream_env, our_env) in env_var_mapping | ||
ENV[our_env] = "non-existent-dir-path" | ||
info_msg = ("Setting ENV[\"$upstream_env\"] = ENV[\"$our_env\"]") | ||
@test (@test_logs (:info, (info_msg)) RNAstructure.__init__()) == nothing | ||
delete_all_env_vars() | ||
end | ||
|
||
# setting both upstream_env_vars and our_env_vars, our_env_vars | ||
# should have precedence | ||
for (upstream_env, our_env) in env_var_mapping | ||
ENV[upstream_env] = "non-existent-dir-path" | ||
ENV[our_env] = "non-existent-dir-path" | ||
info_msg = ("Setting ENV[\"$upstream_env\"] = ENV[\"$our_env\"]") | ||
@test (@test_logs (:info, (info_msg)) RNAstructure.__init__()) == nothing | ||
delete_all_env_vars() | ||
end | ||
|
||
# restore env vars that we previously unset | ||
for e in all_env_vars | ||
if haskey(saved_env_vars, e) | ||
ENV[e] = saved_env_vars[e] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters