Skip to content

Commit

Permalink
solves #99 allowing "EPSG:xxx" as value for EPSGCode
Browse files Browse the repository at this point in the history
  • Loading branch information
flahn committed Dec 2, 2021
1 parent f1cc3cb commit 2843135
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 27 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# version 1.1.1

## Added
* in addition to integer it is now allowed to state text as input for argument `EPSGCode` like *EPSG:4326* [#99](https://github.com/Open-EO/openeo-r-client/issues/99) and wrote a test case for that
* Started test case for `OpenEOClient`
* Test case for `Boolean` argument validation

Expand Down
23 changes: 16 additions & 7 deletions R/argument_types.R
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,14 @@ Argument = R6Class(

invisible(NULL)
}, error = function(e) {
node_id = self$getProcess()$getNodeId()
if (!is.null(node_id)) node_id = paste0("[",node_id,"] ")

message = paste0(node_id,"Parameter '",private$name,"': ",e$message)

if (length(self$getProcess()) >0 ) {
node_id = self$getProcess()$getNodeId()
if (!is.null(node_id)) node_id = paste0("[",node_id,"] ")

message = paste0(node_id,"Parameter '",private$name,"': ",e$message)
} else {
message = e$message
}
return(message)
}
)
Expand Down Expand Up @@ -440,7 +443,7 @@ Integer = R6Class(
# EPSG-Code ====
#' EPSGCode class
#'
#' Inheriting from \code{\link{Argument}} in order to represent an EPSG Code as a single integer value.
#' Inheriting from \code{\link{Argument}} in order to represent an EPSG Code. Allowed values are single integer values like \code{4326} or a text containing 'EPSG:' like \code{EPSG:4326}.
#'
#' @name EPSGCode
#'
Expand Down Expand Up @@ -476,7 +479,13 @@ EPSGCode = R6Class(

if (is.null(coerced) ||
is.na(coerced) ||
length(coerced) == 0) stop(paste0("Value '", private$value,"' cannot be coerced into integer."))
length(coerced) == 0) {
if (is.character(private$value) && grepl(tolower(private$value),pattern = "^epsg:")) {
coerced = as.integer(gsub(x = private$value,replacement = "",pattern = "[^0-9]"))
} else {
stop(paste0("Value '", private$value,"' cannot be coerced into integer."))
}
}
# correct value if you can
private$value = coerced

Expand Down
40 changes: 20 additions & 20 deletions man/EPSGCode.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions tests/testthat/test-argument-epsgcode.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
test_that("numeric epsg code works", {
tryCatch({
code = openeo:::EPSGCode$new()
code$setValue(4326)

code$validate()
expect(TRUE,failure_message = "It doesn't work")
}, error = function(e) {
expect(FALSE,failure_message=e$message)
})
})

test_that("epsg code as string works", {
tryCatch({
code = openeo:::EPSGCode$new()
code$setValue("EPSG:4326")

code$validate()
expect(TRUE,failure_message = "It doesn't work")
}, error = function(e) {
expect(FALSE,failure_message=e$message)
})
})

test_that("epsg code as string in lower letter works", {
tryCatch({
code = openeo:::EPSGCode$new()
code$setValue("epsg:4326")

code$validate()
expect(TRUE,failure_message = "It doesn't work")
}, error = function(e) {
expect(FALSE,failure_message=e$message)
})
})

test_that("other text for code does not work", {
tryCatch({
code = openeo:::EPSGCode$new()
code$setValue("foo.bar")

code$validate()
expect(FALSE,failure_message = "It doesn't work")
}, error = function(e) {
expect(TRUE,failure_message=e$message)
})
})

0 comments on commit 2843135

Please sign in to comment.