From 9cd75f6e5b25194021764fdb6f2f54dfd590b9ef Mon Sep 17 00:00:00 2001 From: Max Freudenberg <67329240+maxfreu@users.noreply.github.com> Date: Wed, 9 Aug 2023 18:14:48 +0200 Subject: [PATCH] add series duplicate_first test (#493) Co-authored-by: Max Freudenberg --- test/series.jl | 11 +++++++++++ test/test_utils.jl | 15 +++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/test/series.jl b/test/series.jl index 664dd60c..67e5d8ff 100644 --- a/test/series.jl +++ b/test/series.jl @@ -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 @@ -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 \ No newline at end of file diff --git a/test/test_utils.jl b/test/test_utils.jl index c6d3ed80..1557dfc7 100644 --- a/test/test_utils.jl +++ b/test/test_utils.jl @@ -1,3 +1,5 @@ +using ArchGDAL + # Loader for external sources maybedownload(url, filename=splitdir(url)[2]) = begin dirpath = joinpath(dirname(pathof(Rasters)), "../test/data") @@ -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 \ No newline at end of file