rorcid icon indicating copy to clipboard operation
rorcid copied to clipboard

sort out testing for others

Open sckott opened this issue 6 years ago • 8 comments

via #74 - @RLumSK can you share the errors you are getting when you run devtools::test() and your R session info too so I can see if certain package versions are to blame

sckott avatar Aug 01 '19 20:08 sckott

sessionInfo() R Under development (unstable) (2019-07-31 r76909) Platform: x86_64-apple-darwin15.6.0 (64-bit) Running under: macOS Mojave 10.14.6

Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK: /Library/Frameworks/R.framework/Versions/3.7/Resources/lib/libRlapack.dylib

locale: [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages: [1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached): [1] compiler_3.7.0 tools_3.7.0 packrat_0.5.0

RLumSK avatar Aug 01 '19 20:08 RLumSK

devtools::test()
Loading rorcid
Registered S3 method overwritten by 'httr':
  method                 from
  as.character.form_file crul
Testing rorcid
✔ |  OK F W S | Context
✖ |   3 2 18   | as.orcid [23.2 s]
────────────────────────────────────────────
>test-as.orcid.R:4: warning: as.orcid
incomplete final line found on '../fixtures/as_orcid.yml'

test-as.orcid.R:4: error: as.orcid
Unauthorized (HTTP 401). Failed to get an access token.
1: vcr::use_cassette("as_orcid", {
       aa <- as.orcid("0000-0002-1642-628X")
   }) at /Users/rorcid_user/GitHub/rorcid/tests/testthat/test-as.orcid.R:4
2: cassette$call_block(...)
3: lazyeval::lazy_eval(tmp)
4: lapply(x, lazy_eval, data = data)
5: FUN(X[[i]], ...)
6: eval(x$expr, x$env, emptyenv())
7: eval(x$expr, x$env, emptyenv())
8: as.orcid("0000-0002-1642-628X") at /Users/rorcid_user/GitHub/rorcid/tests/testthat/test-as.orcid.R:5
9: as.orcid.character("0000-0002-1642-628X") at /Users/rorcid_user/GitHub/rorcid/R/as.orcid.R:31
10: as.orcid(orcid_id(x, ...)) at /Users/rorcid_user/GitHub/rorcid/R/as.orcid.R:42
...
18: crul::HttpClient$new(url = url, opts = list(...), headers = list(Accept = ctype, `User-Agent` = orcid_ua(), `X-USER-AGENT` = orcid_ua(), 
       Authorization = orcid_auth())) at /Users/rorcid_user/GitHub/rorcid/R/zzz.R:9
19: .subset2(public_bind_env, "initialize")(...)
20: orcid_auth()
21: oauth2.0_token(endpt, rorcid_app, scope = scope, cache = !reauth) at /Users/rorcid_user/GitHub/rorcid/R/auth.R:80
22: Token2.0$new(app = app, endpoint = endpoint, params = params, credentials = credentials, cache_path = if (is.null(credentials)) cache else FALSE)
23: .subset2(public_bind_env, "initialize")(...)
24: self$init_credentials()
25: init_oauth2.0(self$endpoint, self$app, scope = self$params$scope, user_params = self$params$user_params, type = self$params$type, 
       use_oob = self$params$use_oob, oob_value = self$params$oob_value, use_basic_auth = self$params$use_basic_auth, config_init = self$params$config_init, 
       client_credentials = self$params$client_credentials, query_authorize_extra = self$params$query_authorize_extra)
26: oauth2.0_access_token(endpoint, app, code = code, user_params = user_params, type = type, redirect_uri = redirect_uri, client_credentials = client_credentials, 
       use_basic_auth = use_basic_auth, config = config_init)
27: stop_for_status(req, task = "get an access token")

test-extract_bibtex.R:4: error: extract_bibtex_basic_test
Unauthorized (HTTP 401). Failed to get an access token.
1: vcr::use_cassette("extract_bibtex", {
       aa <- cite_put(orcid = "0000-0002-0734-2199", pc = "40038622", ctype = "application/vnd.orcid+json; qs=4")
   }) at /Users/rorcid_user/GitHub/rorcid/tests/testthat/test-extract_bibtex.R:4
2: cassette$call_block(...)
3: lazyeval::lazy_eval(tmp)
4: lapply(x, lazy_eval, data = data)
5: FUN(X[[i]], ...)
6: eval(x$expr, x$env, emptyenv())
7: eval(x$expr, x$env, emptyenv())
8: cite_put(orcid = "0000-0002-0734-2199", pc = "40038622", ctype = "application/vnd.orcid+json; qs=4") at /Users/rorcid_user/GitHub/rorcid/tests/testthat/test-extract_bibtex.R:5
9: orcid_prof_helper(orcid, file.path("work", pc), ctype = ctype, parse = FALSE, ...) at /Users/rorcid_user/GitHub/rorcid/R/orcid_citations.R:168
10: orc_GET(url2, ctype = ctype, ...) at /Users/rorcid_user/GitHub/rorcid/R/zzz.R:106
11: crul::HttpClient$new(url = url, opts = list(...), headers = list(Accept = ctype, `User-Agent` = orcid_ua(), `X-USER-AGENT` = orcid_ua(), 
       Authorization = orcid_auth())) at /Users/rorcid_user/GitHub/rorcid/R/zzz.R:9
12: .subset2(public_bind_env, "initialize")(...)
13: orcid_auth()
14: oauth2.0_token(endpt, rorcid_app, scope = scope, cache = !reauth) at /Users/rorcid_user/GitHub/rorcid/R/auth.R:80
15: Token2.0$new(app = app, endpoint = endpoint, params = params, credentials = credentials, cache_path = if (is.null(credentials)) cache else FALSE)
16: .subset2(public_bind_env, "initialize")(...)
17: self$init_credentials()
18: init_oauth2.0(self$endpoint, self$app, scope = self$params$scope, user_params = self$params$user_params, type = self$params$type, 
       use_oob = self$params$use_oob, oob_value = self$params$oob_value, use_basic_auth = self$params$use_basic_auth, config_init = self$params$config_init, 
       client_credentials = self$params$client_credentials, query_authorize_extra = self$params$query_authorize_extra)
19: oauth2.0_access_token(endpoint, app, code = code, user_params = user_params, type = type, redirect_uri = redirect_uri, client_credentials = client_credentials, 
       use_basic_auth = use_basic_auth, config = config_init)
20: stop_for_status(req, task = "get an access token")
──────────────────────────────────────────
⠴ |   0 3 23   | identifiersError in oauth2.0_access_token(endpoint, app, code = code, user_params = user_params,  : 
  Unauthorized (HTTP 401). Failed to get an access token.
✖ |   3 4 24   | identifiers [2.9 s]
────────────────────────────────────────────
test-orcid_citations.R:5: error: orcid_citations_basic_test
Unauthorized (HTTP 401). Failed to get an access token.
1: vcr::use_cassette("orcid_citations_with_bibtex", {
       aa <- orcid_citations(orcid = "0000-0002-0734-2199", put_code = "40038622")
   }) at /Users/rorcid_user/GitHub/rorcid/tests/testthat/test-orcid_citations.R:5
2: cassette$call_block(...)
3: lazyeval::lazy_eval(tmp)
4: lapply(x, lazy_eval, data = data)
5: FUN(X[[i]], ...)
6: eval(x$expr, x$env, emptyenv())
7: eval(x$expr, x$env, emptyenv())
8: orcid_citations(orcid = "0000-0002-0734-2199", put_code = "40038622") at /Users/rorcid_user/GitHub/rorcid/tests/testthat/test-orcid_citations.R:6
9: orcid_works(orcid, put_code) at /Users/rorcid_user/GitHub/rorcid/R/orcid_citations.R:78
10: lapply(orcid, orcid_prof_helper, path = pth, ctype = format, ...) at /Users/rorcid_user/GitHub/rorcid/R/orcid_works.R:80
...
13: crul::HttpClient$new(url = url, opts = list(...), headers = list(Accept = ctype, `User-Agent` = orcid_ua(), `X-USER-AGENT` = orcid_ua(), 
       Authorization = orcid_auth())) at /Users/rorcid_user/GitHub/rorcid/R/zzz.R:9
14: .subset2(public_bind_env, "initialize")(...)
15: orcid_auth()
16: oauth2.0_token(endpt, rorcid_app, scope = scope, cache = !reauth) at /Users/rorcid_user/GitHub/rorcid/R/auth.R:80
17: Token2.0$new(app = app, endpoint = endpoint, params = params, credentials = credentials, cache_path = if (is.null(credentials)) cache else FALSE)
18: .subset2(public_bind_env, "initialize")(...)
19: self$init_credentials()
20: init_oauth2.0(self$endpoint, self$app, scope = self$params$scope, user_params = self$params$user_params, type = self$params$type, 
       use_oob = self$params$use_oob, oob_value = self$params$oob_value, use_basic_auth = self$params$use_basic_auth, config_init = self$params$config_init, 
       client_credentials = self$params$client_credentials, query_authorize_extra = self$params$query_authorize_extra)
21: oauth2.0_access_token(endpoint, app, code = code, user_params = user_params, type = type, redirect_uri = redirect_uri, client_credentials = client_credentials, 
       use_basic_auth = use_basic_auth, config = config_init)
22: stop_for_status(req, task = "get an access token")
────────────────────────────────────────────
⠼ |   0   5   | orcid_doiError in oauth2.0_access_token(endpoint, app, code = code, user_params = user_params,  : 
  Unauthorized (HTTP 401). Failed to get an access token.
⠼ |   2 2 11   | orcid_doiError in oauth2.0_access_token(endpoint, app, code = code, user_params = user_params,  : 
  Unauthorized (HTTP 401). Failed to get an access token.
⠦ |   2 2 13   | orcid_doiError in oauth2.0_access_token(endpoint, app, code = code, user_params = user_params,  : 
  Unauthorized (HTTP 401). Failed to get an access token.
⠦ |   4 4 19   | orcid_doiError in oauth2.0_access_token(endpoint, app, code = code, user_params = user_params,  : 
  Unauthorized (HTTP 401). Failed to get an access token.
⠇ |   4 4 21   | orcid_doiError in oauth2.0_access_token(endpoint, app, code = code, user_params = user_params,  : 
  Unauthorized (HTTP 401). Failed to get an access token.
✖ |   6 5 22   | orcid_doi [4.4 s]
────────────────────────────────────────────
test-orcid_doi.R:10: failure: orcid_doi basic functionality works
length(aa) not equal to 1.
1/1 mismatches
[1] 0 - 1 == -1

test-orcid_doi.R:11: error: orcid_doi basic functionality works
subscript out of bounds
1: expect_is(aa[[1]], "tbl_df") at /Users/rorcid_user/GitHub/rorcid/tests/testthat/test-orcid_doi.R:11
2: quasi_label(enquo(object), label, arg = "object")
3: eval_bare(get_expr(quo), get_env(quo))

test-orcid_doi.R:25: failure: orcid_doi accepts many doi's
length(bb) not equal to 2.
1/1 mismatches
[1] 0 - 2 == -2

══ Terminating early ════════════════════════════════════════════
Too many failures

RLumSK avatar Aug 01 '19 20:08 RLumSK

Ok, pasting the output here did ring the bell:

I was expecting (without telling) that devtools::test() in combination with 'vcr' miraculously takes care of the ORCID_TOKEN. Now it works as expected. What did I do?

x <- strsplit(x = orcid_auth(), " ")[[1]][2]
Sys.setenv(ORCID_TOKEN = x)
  1. Delete all files in tests/fixtures

  2. Run devtools::test()

Sorry for the trouble, I am not familiar with the behaviour of 'vcr', and obviously I need to learn it.

RLumSK avatar Aug 01 '19 20:08 RLumSK

thanks for all this.

Did you have your ORCID_TOKEN environment variable set before? did you set it temporarily in each R session?

sckott avatar Aug 01 '19 20:08 sckott

Yes, I set it only temporarily as written above (I always have). But since such ORCID_TOKEN is not available by default on the CI resources, so I wrongly assumed that the tests would take care of it.

RLumSK avatar Aug 02 '19 06:08 RLumSK

Thanks, now it makes sense.

It looks like you were running devtools::test in an interactive R session. Otherwise, no browser tabs would be opened (im pretty sure). If you had run it from the command line outside of R, you'd have gotten notes about setting the env var:

Testing rorcid
✔ |  OK F W S | Context
✖ |   3 2     | as.orcid [0.2 s]
────────────────
test-as.orcid.R:4: error: as.orcid
In non-interactive environments, please set ORCID_TOKEN env to a ORCID access token, see ?orcid_auth for details
1: vcr::use_cassette("as_orcid", {
... etc.

which is a more helpful note, but requires a non-interactive R session.

I think it makes sense to not allow tests to be run unless a token is present, since pkg use requires a token anyway - Install from the branch tests-require-env-var remotes::install_github("ropensci/rorcid@tests-require-env-var") - let me know what you think. it doesn't let test be run unless a env var is set. e.g. try

Rscript -e 'Sys.unsetenv("ORCID_TOKEN"); devtools::test()'
# OR inside of R
Sys.unsetenv("ORCID_TOKEN"); devtools::test()

#> Error: set an ORCID_TOKEN env var before running tests

If you don't have a token set permanently the above will be the same as not having one set

vs.

Rscript -e 'Sys.setenv(ORCID_TOKEN = "yourtoken"); devtools::test()'
# OR inside of R
Sys.setenv(ORCID_TOKEN = "yourtoken"); devtools::test()

Ideally you'd set your token permanently so you don't have to set it each time, but up to you.

sckott avatar Aug 02 '19 23:08 sckott

Thanks for the feedback. You have correctly assumed that I tried to run the test in an interactive session. I should have mentioned that.

And it makes sense indeed to deny the tests until an ORCID token has been set.

RLumSK avatar Aug 03 '19 17:08 RLumSK

great, thanks for the feedback, i'll merge the change into master.

sckott avatar Aug 06 '19 00:08 sckott