Skip to content

Commit

Permalink
Better tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zozlak committed Oct 25, 2018
1 parent ba60f5c commit d313eb3
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 22 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
^Meta$
^doc$
^.*\.Rproj$
^\.Rproj\.user$
^\.travis.yml$
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Meta
doc
.Rproj.user
.Rhistory
.RData
.DS_Store
.DS_Store
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: sentinel2
Title: Tools to access Sentinel-2 data pre-processed by IVFL, BOKU Vienna
Version: 0.2.0
Version: 0.2.1
Authors@R: c(
person("Sebastian", "Boeck", email = "[email protected]", role = c("aut", "cre")),
person("Mateusz", "Zoltak", email = "[email protected]", role = c("ctb"))
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 0.2.0 (2018-10-25)
# 0.2.1 (2018-10-25)

* A `regionId` parameter added to all `S2_query_...()` functions for which it's valid.
While since 0.1.0 it was possible to use it using the `...` parameter, the explicit
Expand All @@ -8,6 +8,7 @@
default values assumed by the underlaing REST API) and they messed up proper `regionId`
parameter handling (they interfered with picking up default `dateMin`, `dateMax` and
`cloudCovMax` values from the region of interest settings)
* Tests coverage slightly improved

# 0.1.1 (2018-06-21)

Expand Down
124 changes: 105 additions & 19 deletions tests/testthat/test-S2_query.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,42 @@
context('S2_query')
S2_initialize_user()

test_that('S2_query_angle() works', {
data = S2_query_angle(
cloudCovMin = 80,
dateMin = '2016-01-01',
dateMax = '2016-01-10',
utm = '33UXP',
angleType = 'sun'
)
expect_is(data, 'data.frame')
expect_gt(nrow(data), 0)
cols = c("angleId", "productId", "granuleId", "product", "granule", "date", "processDate", "utm", "orbit", "angleType", "band", "zenithAngle", "azimuthAngle", "url")
expect_equal(intersect(names(data), cols), cols)
expect_true(all(data$date >= '2016-01-01 00:00:00.000'))
expect_true(all(data$date <= '2016-01-10 23:59:59.999 '))
expect_true(all(data$utm == '33UXP'))
expect_true(all(data$angleType == 'sun'))
expect_true(all(data$band == 'all'))
})

test_that('S2_query_granule() works', {
data = S2_query_granule(
cloudCovMin = 80,
dateMin = '2016-06-01',
dateMax = '2016-08-31',
utm = '33UXP'
)
expect_is(data, 'data.frame')
expect_gt(nrow(data), 0)
cols = c("granuleId", "productId", "product", "granule", "date", "processDate", "utm", "orbit", "cloudCov", "atmCorr", "broken", "url")
expect_equal(intersect(names(data), cols), cols)
expect_true(all(data$cloudCov >= 80))
expect_true(all(data$date >= '2016-06-01'))
expect_true(all(data$date <= '2016-08-31'))
expect_true(all(data$utm == '33UXP'))
})

test_that('S2_query_image() works', {
data = S2_query_image(
atmCorr = FALSE,
Expand All @@ -22,38 +58,82 @@ test_that('S2_query_image() works', {
expect_true(all(data$utm == '33UXP'))
})

test_that('S2_query_granule() works', {
data = S2_query_granule(
cloudCovMin = 80,
test_that('S2_query_job() works', {
data = S2_query_job(
regionId = 'testROI'
)
expect_is(data, 'data.frame')
expect_gt(nrow(data), 0)
cols = c("jobId", "jobType", "productId", "granuleId", "product", "granule", "date", "priority", "created", "started", "ended", "failed")
expect_equal(intersect(names(data), cols), cols)
expect_true(all(!is.na(data$jobId)))
expect_true(all(data$date >= '2016-01-01 00:00:00.000'))
expect_true(all(data$date <= '2016-07-01 23:59:59.999'))
})

test_that('S2_query_product() works', {
data = S2_query_product(
dateMin = '2016-06-01',
dateMax = '2016-08-31',
utm = '33UXP'
regionId = 'testROI'
)
expect_is(data, 'data.frame')
expect_gt(nrow(data), 0)
cols = c("granuleId", "productId", "product", "granule", "date", "processDate", "utm", "orbit", "cloudCov", "atmCorr", "broken", "url")
cols = c("productId", "product", "date", "dateEnd", "processDate", "orbitNo", "orbitDir", "granulesCount")
expect_equal(intersect(names(data), cols), cols)
expect_true(all(data$orbit == 'DESCENDING'))
expect_true(all(data$date >= '2016-06-01 00:00:00.000'))
expect_true(all(data$date <= '2016-08-31 23:59:59.999'))
})

test_that('S2_query_qiData() works', {
data = S2_query_qiData(
cloudCovMin = 80,
dateMin = '2016-06-01',
dateMax = '2016-06-15',
utm = '33UXP',
qiType = 'satura'
)
expect_is(data, 'data.frame')
expect_gt(nrow(data), 0)
cols = c("qiDataId", "productId", "granuleId", "product", "granule", "date", "processDate", "utm", "orbit", "qiType", "band", "url")
expect_equal(intersect(names(data), cols), cols)
expect_true(all(data$cloudCov >= 80))
expect_true(all(data$date >= '2016-06-01'))
expect_true(all(data$date <= '2016-08-31'))
expect_true(all(data$date >= '2016-06-01 00:00:00.000'))
expect_true(all(data$date <= '2016-06-15 23:59:59.999'))
expect_true(all(data$utm == '33UXP'))
expect_true(all(data$qiType == 'satura'))
})

test_that('S2_query_granule() works', {
test_that('S2_query_roi() works', {
data = S2_query_roi(
regionId = 'test%'
)
expect_is(data, 'data.frame')
expect_gt(nrow(data), 0)
cols = c("userId", "regionId", "dateMin", "dateMax", "priority", "cloudCovMax", "jobTypes", "geometry", "url")
expect_equal(intersect(names(data), cols), cols)
expect_true(all(grepl('^test', data$regionId)))
expect_true(all(data$userId == '[email protected]'))
})

test_that('S2_query_granule(spatial = TRUE) works', {
data = S2_query_granule(
cloudCovMin = 80,
dateMin = '2016-06-01',
dateMax = '2016-08-31',
utm = '33UXP'
dateMax = '2016-06-15',
utm = '33UXP',
spatial = TRUE
)
expect_is(data, 'data.frame')
expect_gt(nrow(data), 0)
cols = c("granuleId", "productId", "product", "granule", "date", "processDate", "utm", "orbit", "cloudCov", "atmCorr", "broken", "url")
expect_equal(intersect(names(data), cols), cols)
expect_true(all(data$cloudCov >= 80))
expect_true(all(data$date >= '2016-06-01'))
expect_true(all(data$date <= '2016-08-31'))
expect_true(all(data$date >= '2016-06-01 00:00:00.000'))
expect_true(all(data$date <= '2016-06-15 23:59:59.999'))
expect_true(all(data$utm == '33UXP'))
expect_true(all(unlist(lapply(data$geometry, function(x){'SpatialPolygonsDataFrame' %in% class(x)}))))
})

test_that('S2 downloads images', {
Expand All @@ -79,12 +159,18 @@ test_that('S2 downloads granules', {
if (dir.exists('testDir')) {
system('rm -fR testDir')
}
on.exit({
if (file.exists('testDir.zip')) {
unlink('testDir.zip')
tryCatch(
{
S2_download('https://test%40s2.boku.eodc.eu:[email protected]/granule/2920000', destfile = 'testDir', zip = TRUE, skipExisting = FALSE)
expect_true(file.exists('testDir/MTD_TL.xml'))
},
finally = {
if (file.exists('testDir.zip')) {
unlink('testDir.zip')
}
if (dir.exists('testDir')) {
system('rm -fR testDir')
}
}
if (dir.exists('testDir')) {
system('rm -fR testDir')
}
})
)
})

0 comments on commit d313eb3

Please sign in to comment.