Skip to content

Commit

Permalink
fix tests (#163)
Browse files Browse the repository at this point in the history
* use examples from Brest instead of Nantes, because some examples don't work anymore, cf. #160

* remove tests w.r.t. `min_confidence`, cf. #161, #162

* update {Roxygen} version

* add ProjectId

* update snapshots, presumably due to changes in {testthat}

* make lintr happy

* remove more tests w.r.t. `min_confidence`

* some minor fixes, e.g. `q=Berlin, limit=5` returns only one result, making that example useless. also the hotel de ville in Nantes example isn't working anymore, see #160

* pre-compile vignettes and README
  • Loading branch information
dpprdan authored Jan 13, 2025
1 parent 9b57eef commit 07134ce
Show file tree
Hide file tree
Showing 16 changed files with 332 additions and 437 deletions.
5 changes: 4 additions & 1 deletion .lintr
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
linters: linters_with_tags(c("package_development", "default"), cyclocomp_linter = NULL) # .oc_check_query()
linters: linters_with_tags(
c("package_development", "default"),
cyclocomp_linter = NULL, # .oc_check_query()
indentation_linter = NULL) # https://github.com/r-lib/lintr/issues/2034, https://github.com/r-lib/lintr/issues/2535
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ Encoding: UTF-8
Language: en-GB
LazyData: TRUE
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,27 @@ library(opencage)
oc_forward_df(placename = "Sarzeau")
```

<div class="kable-table">

| placename | oc_lat | oc_lng | oc_formatted |
|:----------|---------:|--------:|:----------------------|
| Sarzeau | 47.52877 | -2.7642 | 56370 Sarzeau, France |

</div>

Or turn a set of coordinates into the name and address of the location:

``` r
oc_reverse_df(latitude = 51.5034070, longitude = -0.1275920)
```

| latitude | longitude | oc_formatted |
|---------:|----------:|:----------------------------------------------------|
| 51.50341 | -0.127592 | 10 Downing Street, London, SW1A 2AA, United Kingdom |
<div class="kable-table">

| latitude | longitude | oc_formatted |
|---:|---:|:---|
| 51.50341 | -0.127592 | 10 Downing Street, Westminster, London, SW1A 2AA, United Kingdom |

</div>

But remember, the vignettes are really great! We have:

Expand Down
1 change: 1 addition & 0 deletions opencage.Rproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Version: 1.0
ProjectId: 3d5685ec-c81f-43a6-a376-4b6992e50ed3

RestoreWorkspace: Default
SaveWorkspace: Default
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/deprecated.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

Code
opencage_key(quiet = FALSE)
Message <simpleMessage>
Message
Using OpenCage API Key from envvar OPENCAGE_KEY

30 changes: 18 additions & 12 deletions tests/testthat/_snaps/oc_check_query.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,47 @@

Code
oc_check_between(symbol, 0, 10)
Error <simpleError>
Every `symbol` must be between 0 and 10.
Condition
Error:
! Every `symbol` must be between 0 and 10.

---

Code
oc_check_between(symbol, 11.0001, 11.0002)
Error <simpleError>
Every `symbol` must be between 11.0001 and 11.0002.
Condition
Error:
! Every `symbol` must be between 11.0001 and 11.0002.

---

Code
oc_check_between(symbol, 0L, 10L)
Error <simpleError>
Every `symbol` must be between 0 and 10.
Condition
Error:
! Every `symbol` must be between 0 and 10.

---

Code
oc_check_between(symbol, 11.0001, 11.0002)
Error <simpleError>
Every `symbol` must be between 11.0001 and 11.0002.
Condition
Error:
! Every `symbol` must be between 11.0001 and 11.0002.

---

Code
oc_check_between(symbol, 0, 11)
Error <simpleError>
Every `symbol` must be numeric.
Condition
Error:
! Every `symbol` must be numeric.

---

Code
oc_check_between(symbol, 0, 11)
Error <simpleError>
Every `symbol` must be numeric.
Condition
Error:
! Every `symbol` must be numeric.

26 changes: 12 additions & 14 deletions tests/testthat/helper-opencage.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,26 @@ skip_if_no_key <- function() {

## forward -----------------------------------------------------------------

oc_locs <- function() c("Nantes", "Flensburg", "Los Angeles")
oc_locs <- function() c("Brest", "Flensburg", "Los Angeles")

oc_fw1 <- function() tibble::tibble(id = 1:3, loc = oc_locs())

oc_fw2 <- function() {
tibble::add_column(
oc_fw1(),
bounds = oc_bbox(
xmin = c(-72, -98, -73),
ymin = c(45, 43, -38),
xmax = c(-70, -90, -71),
ymax = c(46, 49, -36)
xmin = c(17, -98, -73),
ymin = c(49, 43, -38),
xmax = c(18, -90, -71),
ymax = c(50, 49, -36)
),
proximity = oc_points(
latitude = c(45.5, 46, -37),
longitude = c(-71, -95, -72)
latitude = c(49.3, 46, -37),
longitude = c(17.4, -95, -72)
),
countrycode = c("ca", "us", "cl"),
countrycode = c("cz", "us", "cl"),
language = c("de", "fr", "ja"),
limit = 1:3,
confidence = c(7, 9, 5),
annotation = c(FALSE, TRUE, TRUE),
abbrv = c(FALSE, FALSE, TRUE),
address_only = c(TRUE, FALSE, FALSE)
Expand All @@ -57,23 +56,22 @@ oc_fw2 <- function() {
oc_fw3 <- function() {
tibble::tibble(
id = 1:3,
loc = c("Nantes", "Elbphilharmonie Hamburg", "Los Angeles City Hall"),
loc = c("Brest", "Elbphilharmonie Hamburg", "Los Angeles City Hall"),
roadinfo = c(FALSE, TRUE, TRUE)
)
}

## reverse -----------------------------------------------------------------

oc_lat1 <- function() c(47.21864, 53.55034, 34.05369)
oc_lng1 <- function() c(-1.554136, 10.000654, -118.242767)
oc_lat1 <- function() c(47.21947, 53.55034, 34.05369)
oc_lng1 <- function() c(-1.54754, 10.000654, -118.242767)

oc_rev1 <- function() tibble::tibble(id = 1:3, lat = oc_lat1(), lng = oc_lng1())

oc_rev2 <- function() {
tibble::add_column(
oc_rev1(),
language = c("en", "fr", "ja"),
confidence = rep(1L, 3L),
annotation = c(FALSE, TRUE, TRUE),
roadinfo = c(FALSE, TRUE, TRUE),
abbrv = c(FALSE, FALSE, TRUE),
Expand All @@ -82,5 +80,5 @@ oc_rev2 <- function() {
}

oc_rev3 <- function() {
tibble::add_row(oc_rev2(), id = 4, lat = 25, lng = 36, confidence = 5)
tibble::add_row(oc_rev2(), id = 4, lat = 25, lng = 36)
}
3 changes: 0 additions & 3 deletions tests/testthat/test-deprecated.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ test_that("opencage_forward/opencage_reverse return what they should
results <- opencage_forward(
placename = "Paris",
limit = 2,
min_confidence = 5,
language = "fr",
no_annotations = TRUE
)
Expand All @@ -44,7 +43,6 @@ test_that("opencage_forward/opencage_reverse return what they should
results <- opencage_reverse(
latitude = 44,
longitude = 44,
min_confidence = 5,
language = "pt-BR",
no_annotations = TRUE
)
Expand All @@ -68,7 +66,6 @@ test_that("opencage_forward deals well with results being NULL", {
placename = "NOWHERE-INTERESTING",
key = Sys.getenv("OPENCAGE_KEY"),
limit = 2,
min_confidence = 5,
language = "pt-BR",
no_annotations = TRUE
)
Expand Down
10 changes: 0 additions & 10 deletions tests/testthat/test-oc_check_query.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,6 @@ test_that("oc_check_query checks limit", {
)
})

test_that("oc_check_query checks min_confidence", {
expect_error(
oc_check_query(
placename = "Sarzeau",
min_confidence = 20
),
"`min_confidence` must be an integer between 1 and 10."
)
})

test_that("oc_check_query checks no_annotations", {
expect_error(
oc_check_query(
Expand Down
18 changes: 2 additions & 16 deletions tests/testthat/test-oc_forward.R
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ test_that("tidyeval works for arguments", {
## bounds, proximity and countrycode
bounds <- oc_forward_df(oc_fw2(), loc, bounds = bounds, bind_cols = FALSE)
prx <- oc_forward_df(oc_fw2(), loc, proximity = proximity, bind_cols = FALSE)
cc <- oc_forward_df(oc_fw2(), loc, countrycode = countrycode, bind_cols = FALSE)
cc <-
oc_forward_df(oc_fw2(), loc, countrycode = countrycode, bind_cols = FALSE)
expect_false(identical(bounds, noarg))
expect_false(identical(prx, noarg))
expect_false(identical(cc, noarg))
Expand All @@ -207,21 +208,6 @@ test_that("tidyeval works for arguments", {
expect_identical(nrow(limit), 6L)
expect_identical(limit$id, c(1L, 2L, 2L, 3L, 3L, 3L))

# min_confidence
confidence <- oc_forward_df(
oc_fw2(),
loc,
min_confidence = confidence,
bind_cols = FALSE
)

# make sure we get actual results, not only NA
expect_false(anyNA(confidence$oc_formatted))

expect_false(identical(confidence[1, ], noarg[1, ]))
expect_false(identical(confidence[2, ], noarg[2, ]))
expect_false(identical(confidence[3, ], noarg[3, ]))

# no_annotations
ann <-
oc_forward_df(
Expand Down
11 changes: 0 additions & 11 deletions tests/testthat/test-oc_process.R
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ test_that("oc_process handles various other arguments.", {
placename = "Hamburg",
return = "url_only",
limit = 1L,
min_confidence = NULL,
no_annotations = FALSE,
roadinfo = FALSE,
no_dedupe = FALSE,
Expand All @@ -235,7 +234,6 @@ test_that("oc_process handles various other arguments.", {
add_request = FALSE
)
expect_match(res1[[1]], "&limit=1", fixed = TRUE)
expect_false(grepl(pattern = "min_confidence", x = res1[[1]], fixed = TRUE))
expect_match(res1[[1]], "&no_annotations=0", fixed = TRUE)
expect_match(res1[[1]], "&roadinfo=0", fixed = TRUE)
expect_match(res1[[1]], "&no_dedupe=0", fixed = TRUE)
Expand All @@ -247,7 +245,6 @@ test_that("oc_process handles various other arguments.", {
placename = "Hamburg",
return = "url_only",
limit = 10,
min_confidence = 8,
no_annotations = TRUE,
roadinfo = TRUE,
no_dedupe = TRUE,
Expand All @@ -256,7 +253,6 @@ test_that("oc_process handles various other arguments.", {
add_request = TRUE
)
expect_match(res2[[1]], "&limit=10", fixed = TRUE)
expect_match(res2[[1]], "&min_confidence=8", fixed = TRUE)
expect_match(res2[[1]], "&no_annotations=1", fixed = TRUE)
expect_match(res2[[1]], "&roadinfo=1", fixed = TRUE)
expect_match(res2[[1]], "&no_dedupe=1", fixed = TRUE)
Expand All @@ -268,7 +264,6 @@ test_that("oc_process handles various other arguments.", {
placename = c("Hamburg", "Hamburg"),
return = "url_only",
limit = c(10L, 5L),
min_confidence = c(8L, 5L),
no_annotations = c(TRUE, FALSE),
roadinfo = c(TRUE, FALSE),
no_dedupe = c(TRUE, FALSE),
Expand All @@ -278,8 +273,6 @@ test_that("oc_process handles various other arguments.", {
)
expect_match(res3[[1]], "&limit=10", fixed = TRUE)
expect_match(res3[[2]], "&limit=5", fixed = TRUE)
expect_match(res3[[1]], "&min_confidence=8", fixed = TRUE)
expect_match(res3[[2]], "&min_confidence=5", fixed = TRUE)
expect_match(res3[[1]], "&no_annotations=1", fixed = TRUE)
expect_match(res3[[2]], "&no_annotations=0", fixed = TRUE)
expect_match(res3[[1]], "&roadinfo=1", fixed = TRUE)
Expand All @@ -304,7 +297,6 @@ test_that("arguments that are NULL or NA don't show up in url.", {
proximity = NULL,
language = NULL,
countrycode = NULL,
min_confidence = NULL,
roadinfo = NULL,
no_annotations = NULL,
no_dedupe = NULL,
Expand All @@ -318,7 +310,6 @@ test_that("arguments that are NULL or NA don't show up in url.", {
expect_match(res_null[[1]], "^((?!proximity=).)*$", perl = TRUE)
expect_match(res_null[[1]], "^((?!language=).)*$", perl = TRUE)
expect_match(res_null[[1]], "^((?!countrycode=).)*$", perl = TRUE)
expect_match(res_null[[1]], "^((?!min_confidence=).)*$", perl = TRUE)
expect_match(res_null[[1]], "^((?!no_annotations=).)*$", perl = TRUE)
expect_match(res_null[[1]], "^((?!roadinfo=).)*$", perl = TRUE)
expect_match(res_null[[1]], "^((?!no_dedupe=).)*$", perl = TRUE)
Expand All @@ -334,7 +325,6 @@ test_that("arguments that are NULL or NA don't show up in url.", {
proximity = list(),
language = NA_character_,
countrycode = NA_character_,
min_confidence = NA,
no_annotations = NA,
roadinfo = NA,
no_dedupe = NA,
Expand All @@ -348,7 +338,6 @@ test_that("arguments that are NULL or NA don't show up in url.", {
expect_match(res_na[[1]], "^((?!proximity=).)*$", perl = TRUE)
expect_match(res_na[[1]], "^((?!language=).)*$", perl = TRUE)
expect_match(res_na[[1]], "^((?!countrycode=).)*$", perl = TRUE)
expect_match(res_na[[1]], "^((?!min_confidence=).)*$", perl = TRUE)
expect_match(res_na[[1]], "^((?!no_annotations=).)*$", perl = TRUE)
expect_match(res_na[[1]], "^((?!roadinfo=).)*$", perl = TRUE)
expect_match(res_na[[1]], "^((?!no_dedupe=).)*$", perl = TRUE)
Expand Down
18 changes: 4 additions & 14 deletions tests/testthat/test-oc_reverse.R
Original file line number Diff line number Diff line change
Expand Up @@ -181,21 +181,10 @@ test_that("tidyeval works for arguments", {
noarg <- oc_reverse_df(oc_rev2(), lat, lng)

# language
lang <- oc_reverse_df(oc_rev2(), lat, lng, language = language, output = "all")
lang <-
oc_reverse_df(oc_rev2(), lat, lng, language = language, output = "all")
expect_identical(lang$oc_country, c("France", "Allemagne", "アメリカ合衆国"))

# min_confidence
confidence <- oc_reverse_df(oc_rev3(), lat, lng, min_confidence = confidence)
no_con <- oc_reverse_df(oc_rev3(), lat, lng)

expect_identical(confidence[1, ], no_con[1, ])
expect_identical(confidence[2, ], no_con[2, ])
expect_identical(confidence[3, ], no_con[3, ])
expect_false(identical(
confidence[[4, "oc_formatted"]],
no_con[[4, "oc_formatted"]]
))

# no_annotations
ann <-
oc_reverse_df(
Expand Down Expand Up @@ -228,7 +217,8 @@ test_that("tidyeval works for arguments", {
))

# address_only
address_only <- oc_reverse_df(oc_rev2(), lat, lng, address_only = address_only)
address_only <-
oc_reverse_df(oc_rev2(), lat, lng, address_only = address_only)
expect_false(identical(
address_only["oc_formatted"],
noarg["oc_formatted"]
Expand Down
Loading

0 comments on commit 07134ce

Please sign in to comment.