Skip to content

Commit

Permalink
✅ test print methods #57
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Cazelles committed Nov 1, 2021
1 parent 9fb23b7 commit 9974af0
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 6 deletions.
50 changes: 50 additions & 0 deletions tests/testthat/_snaps/distributions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# spp_distributions() defaults work

Code
print(res)
Output
-- Distributions ($distributions): ---------------------------------------------
# A tibble: 42 x 5
id iso_code2 name type tags
<int> <chr> <chr> <chr> <chr>
1 1778 ML Mali COUNTRY ""
2 1923 GQ Equatorial Guinea COUNTRY ""
3 4429 RW Rwanda COUNTRY ""
4 4491 GH Ghana COUNTRY ""
5 5628 SD Sudan COUNTRY ""
6 6724 ET Ethiopia COUNTRY ""
7 8995 GA Gabon COUNTRY ""
8 12983 AO Angola COUNTRY ""
9 15554 CM Cameroon COUNTRY ""
10 17060 BJ Benin COUNTRY ""
# ... with 32 more rows
-- References ($references): ---------------------------------------------------
# A tibble: 146 x 2
id reference
<int> <chr>
1 1778 Kingdon, J., Happold [truncated]
2 1923 Basilio, A. 1962. La [truncated]
3 4429 Jackson, P. 1982. El [truncated]
4 4429 Monfort, A. 1992. Pr [truncated]
5 4491 Grubb, P., Jones, T. [truncated]
6 4491 Jackson, P. 1982. El [truncated]
7 5628 Hameed, S.M.A. and E [truncated]
8 6724 Bolton, M. 1973. Not [truncated]
9 6724 Largen, M. J. and Ya [truncated]
10 6724 Meester, J. and Setz [truncated]
# ... with 136 more rows

# spp_distributions() works when no info available

Code
print(res)
Output
-- Distributions ($distributions): ---------------------------------------------
No records available.
-- References ($references): ---------------------------------------------------
No records available.

60 changes: 60 additions & 0 deletions tests/testthat/_snaps/legislations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# spp_cites_legislation() defaults work

Code
print(res)
Output
-- Cites listings ($cites_listings): -------------------------------------------
# A tibble: 10 x 6
id taxon_concept_id is_current appendix change_type effective_at
<chr> <chr> <lgl> <chr> <chr> <chr>
1 30344 4521 TRUE I + 2017-01-02
2 30115 4521 TRUE II + 2019-11-26
3 32160 4521 TRUE II R+ 2019-11-26
4 32161 4521 TRUE II R+ 2019-11-26
5 32156 4521 TRUE II R+ 2019-11-26
6 32158 4521 TRUE II R+ 2019-11-26
7 32154 4521 TRUE II R+ 2019-11-26
8 32159 4521 TRUE II R+ 2019-11-26
9 32157 4521 TRUE II R+ 2019-11-26
10 32155 4521 TRUE II R+ 2019-11-26
-- Cites quotas ($cites_quotas): -----------------------------------------------
# A tibble: 38 x 10
id taxon_concept_id quota publication_date public_display is_current unit
<chr> <chr> <chr> <chr> <lgl> <lgl> <chr>
1 25337 4521 0 2021-02-03 TRUE TRUE <NA>
2 25348 4521 0 2021-02-03 TRUE TRUE <NA>
3 25355 4521 0 2021-02-03 TRUE TRUE <NA>
4 25358 4521 0 2021-02-03 TRUE TRUE <NA>
5 25375 4521 0 2021-02-03 TRUE TRUE <NA>
6 25390 4521 0 2021-02-03 TRUE TRUE <NA>
7 25414 4521 0 2021-02-03 TRUE TRUE <NA>
8 25431 4521 0 2021-02-03 TRUE TRUE <NA>
9 25554 4521 100 2021-02-03 TRUE TRUE <NA>
10 25555 4521 300 2021-02-03 TRUE TRUE <NA>
# ... with 28 more rows, and 3 more variables: geo_entity.iso_code2 <chr>,
# geo_entity.name <chr>, geo_entity.type <chr>
Field(s) not printed: notes, url
-- Cites suspensions ($cites_suspensions): -------------------------------------
# A tibble: 13 x 8
id taxon_concept_id start_date is_current applies_to_import
<chr> <chr> <chr> <lgl> <lgl>
1 17621 4521 2014-08-11 TRUE TRUE
2 17620 4521 2014-08-11 TRUE TRUE
3 17686 4521 2014-10-10 TRUE TRUE
4 18709 4521 2010-08-16 TRUE TRUE
5 15983 <NA> 2011-01-19 TRUE FALSE
6 22079 <NA> 2018-01-30 TRUE FALSE
7 22076 <NA> 2018-01-22 TRUE FALSE
8 22132 4521 2018-03-19 TRUE FALSE
9 23168 <NA> 2019-07-04 TRUE FALSE
10 24947 4521 2020-05-26 TRUE TRUE
11 25328 4521 2020-12-11 TRUE FALSE
12 26123 <NA> 2021-05-06 TRUE FALSE
13 26275 4521 2018-06-01 TRUE TRUE
# ... with 3 more variables: geo_entity.iso_code2 <chr>, geo_entity.name <chr>,
# geo_entity.type <chr>
Field(s) not printed: notes, start_notification.name, start_notification.date, start_notification.url

26 changes: 26 additions & 0 deletions tests/testthat/_snaps/references.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# spp_references() defaults works

Code
print(res)
Output
-- References ($references): ---------------------------------------------------
# A tibble: 15 x 3
id citation is_standard
<chr> <chr> <chr>
1 10265 Anon. 1978. Red data book: Mammalia. IUC [truncated] FALSE
2 6344 Barnes, R. F., Agnagna, M., Alers, M. P. [truncated] FALSE
3 17013 Blanc, J.J., Thouless, C.R., Hart, J.A., [truncated] FALSE
4 6371 Burton, M. P. 1994. Alternative projecti [truncated] FALSE
5 6532 Douglas-Hamilton, I. 1987. African Eleph [truncated] FALSE
6 6534 Douglas-Hamilton, I. 1987. African Eleph [truncated] FALSE
7 6825 Jackson, P. 1982. Elephants and rhinos i [truncated] FALSE
8 7224 Meester, J. and Setzer, H. W (eds.) 1974 [truncated] FALSE
9 7609 Parker, I. and Amin, M. 1983. Ivory cris [truncated] FALSE
10 19397 Parker, I.S.C. and Martin, E.B. 1982. Ho [truncated] FALSE
11 19572 Riddle, H.S., Schulte, B.A., Desai, A.A. [truncated] FALSE
12 15783 Roca, A. L., Georgiadis, N., Pecon-Slatt [truncated] FALSE
13 7852 Said, M. and Change, R. 1994. African el [truncated] FALSE
14 43172 Wilson, D.E. and Reeder, D.M. (Eds.) 199 [truncated] TRUE
15 17655 Wilson, D.E. and Reeder, D.M. (Eds.). 20 [truncated] FALSE

46 changes: 46 additions & 0 deletions tests/testthat/_snaps/taxonconcept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# spp_taxonconcept() defaults work

Code
print(res)
Output
-- General info - CITES ($general): --------------------------------------------
# A tibble: 1 x 8
id full_name author_year rank name_status updated_at active
* <chr> <chr> <chr> <chr> <chr> <dttm> <lgl>
1 4521 Loxodonta a~ (Blumenbach, ~ SPEC~ A 2021-10-13 13:12:58 TRUE
# ... with 1 more variable: cites_listing <chr>
-- Classification ($higher_taxa): ----------------------------------------------
# A tibble: 1 x 6
id kingdom phylum class order family
<chr> <chr> <chr> <chr> <chr> <chr>
1 4521 Animalia Chordata Mammalia Proboscidea Elephantidae
-- Synonyms ($synonyms): -------------------------------------------------------
# A tibble: 4 x 2
id apply.do.call.rbind..tmp.wch....2..unlist.
<chr> <chr>
1 4521 37069
2 4521 Loxodonta cyclotis
3 4521 (Matschie, 1900)
4 4521 SPECIES
-- Common names ($common_names): -----------------------------------------------
# A tibble: 37 x 3
id name language
<chr> <chr> <chr>
1 4521 Ndovo SW
2 4521 Tembo SW
3 4521 Haathi UR
4 4521 Elefante PT
5 4521 Slon RU
6 4521 Elefant NO
7 4521 Olifant NL
8 4521 Afrikaanse olifant NL
9 4521 Elefante africano ES
10 4521 afrikansk elefant SV
# ... with 27 more rows
Information available: $all_id, $general, $higher_taxa, $accepted_names, $common_names, $synonyms, $cites_listings

2 changes: 2 additions & 0 deletions tests/testthat/setup-helper-citesr.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
library(tibble)

# https://cran.r-project.org/web/packages/httr/vignettes/secrets.html
skip_if_no_auth <- function() {
if (identical(Sys.getenv("SPECIESPLUS_TOKEN"), "")) {
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-distributions.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ test_that("spp_distributions() defaults work", {
expect_type(res[1L], "list")
expect_true(all(unlist(lapply(res, function(x) is_cl_df(x)))))
expect_identical(lang_GQ %in% res$distributions$name, c(TRUE, FALSE, FALSE))
# expect_snapshot(print(res))
expect_snapshot(print(res))
})

test_that("spp_distributions() works when no info available", {
vcr::use_cassette("spp_distributions_noi", {
expect_warning(res <- spp_distributions(taxon_id = 0))
})
# expect_snapshot(print(res))
expect_snapshot(print(res))
})

test_that("spp_distributions() raw mode works", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-legislations.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test_that("spp_cites_legislation() defaults work", {
expect_type(res$cites_suspensions$applies_to_import, "logical")
expect_type(res$cites_quotas$public_display, "logical")
expect_true("Guinea" %in% res$cites_suspensions$geo_entity.name)
# expect_snapshot(print(res))
expect_snapshot(print(res))
})

test_that("spp_cites_legislation() raw mode works", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-references.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test_that("spp_references() defaults works", {
expect_true(is(res[1L], "list"))
expect_true(all(unlist(lapply(res, function(x) is_cl_df(x)))))
expect_true(all(names(res$references == nm1)))
# expect_snapshot(print(res))
expect_snapshot(print(res))
})

test_that("spp_references() raw mode", {
Expand Down
3 changes: 1 addition & 2 deletions tests/testthat/test-taxonconcept.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ nm1 <- c("all_id", "general", "higher_taxa", "accepted_names", "common_names",
nm2 <- c("id", "full_name", "author_year", "rank", "name_status", "updated_at",
"active", "cites_listing")


test_that("spp_taxonconcept() defaults work", {
vcr::use_cassette("spp_taxonconcept_def", {
res <- spp_taxonconcept(query_taxon = tx_nm)
Expand All @@ -16,7 +15,7 @@ test_that("spp_taxonconcept() defaults work", {
expect_true(all(unlist(lapply(res, function(x) is_cl_df(x)))))
expect_type(res$cites_listings$annotation, "character")
expect_equal(attributes(res)$taxonomy, "CITES")
# expect_snapshot(print(res))
expect_snapshot(print(res))
})

test_that("spp_taxonconcept() raw mode works", {
Expand Down

0 comments on commit 9974af0

Please sign in to comment.