Skip to content

Commit

Permalink
add series duplicate_first test
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Freudenberg committed Aug 9, 2023
1 parent 81f4d78 commit fe4c991
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/series.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Rasters, Test, Dates, DimensionalData
using Rasters.LookupArrays, Rasters.Dimensions
include(joinpath(dirname(pathof(Rasters)), "../test/test_utils.jl"))

# RasterSeries from Raster/RasterStack components

Expand Down Expand Up @@ -115,3 +116,13 @@ end
@test occursin("Raster", sh)
@test occursin("X", sh)
end

@testset "duplicate_first & lazy" begin
temporary_random_rasters(3, (10,10,3), UInt8) do filenames
times = Ti(DateTime.(sort(rand(UInt16, length(filenames)))))
series = RasterSeries(filenames, times; duplicate_first=true, lazy=true)
@test all(Rasters.filename.(series) .== filenames)
first_dims = dims(first(series))
@test all(dims(r) == first_dims for r in series)
end
end
15 changes: 15 additions & 0 deletions test/test_utils.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using ArchGDAL

# Loader for external sources
maybedownload(url, filename=splitdir(url)[2]) = begin
dirpath = joinpath(dirname(pathof(Rasters)), "../test/data")
Expand All @@ -6,3 +8,16 @@ maybedownload(url, filename=splitdir(url)[2]) = begin
isfile(filepath) || download(url, filepath)
filepath
end

# create `N` random rasters with eltype `type` and x,y,band size `size`
function temporary_random_rasters(f, N, size, type=UInt8)
filenames = [tempname() * ".tif" for _ in 1:N]
try
for f in filenames
write(f, Raster(rand(type, size); dims=(X(1:size[1]), Y(1:size[2]), Band(1:size[3]))))
end
f(filenames)
finally
rm.(filenames; force=true)
end
end

0 comments on commit fe4c991

Please sign in to comment.