Skip to content

Commit

Permalink
fixed _get_indices
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinuzziFrancesco committed Jan 23, 2024
1 parent 5994aaf commit 249a489
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4,663 deletions.
8 changes: 6 additions & 2 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,15 @@ indices = _get_indices(true)
'''
```
"""
function _get_indices(online::Bool=false)
function _get_indices(
online::Bool=false;
filename="spectral-indices-dict.json",
fileloc=joinpath(dirname(@__FILE__), "..", "data", filename),
)
if online
indices_loc = Downloads.download(
"https://raw.githubusercontent.com/awesome-spectral-indices/awesome-spectral-indices/main/output/spectral-indices-dict.json",
string(pwd(), "spectral-indices-dict.json"),
fileloc,
)
indices = JSON.parsefile(indices_loc)
else
Expand Down
20 changes: 19 additions & 1 deletion test/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,25 @@ using SpectralIndices
# Test offline
@test SpectralIndices._get_indices() isa Dict
# Test online
@test SpectralIndices._get_indices(true) isa Dict
@testset "Download Indices Test" begin
test_dir = mktempdir()
try
# Define the file location within the test directory
test_fileloc = joinpath(test_dir, "spectral-indices-dict.json")

# Run the _get_indices function with online = true
indices = SpectralIndices._get_indices(true; fileloc=test_fileloc)

# Test if the file was downloaded and parsed successfully
@test isfile(test_fileloc)
@test !isempty(indices)
@test indices isa Dict

finally
# Clean up: Delete the test file and directory
rm(test_dir; recursive=true)
end
end

params = Dict("N" => 0.6, "R" => 0.3)
# Test correctness
Expand Down
Loading

0 comments on commit 249a489

Please sign in to comment.