Closed Rekyt closed 4 years ago
thanks for the report, i'll have a look - are you testing with your pkg on your master branch?
(related to #112 )
Woah thank you for the quick answer. I'm currently updating the cassettes on Rekyt/bnfimage@a4539ef30c1004201eb320b2453e98be5fce7a86 on branch new_cassettes
let me know if it works. all webmockr an vcr tests are passing now, added new tests specifically for images to each pkg for changes made
@Rekyt looks like the png package is needed on your travis build?
I'm only depending on magick so I don't think the png package is needed.
I update both vcr and webmockr, everything work now.
However, there seems to be an incompatibility with the option preserve_body_bytes = TRUE
.
Is it expected? (The way vcr works is still obscure to me...)
Reprex:
# Reprex for image
library(vcr)
use_cassette("test_cassette_preserve", {
b = httr::GET("https://httpbin.org/image/jpeg")
testthat::expect_equal(length(b$content), 35588)
}, preserve_exact_body_bytes = TRUE)
#> CrulAdapter enabled!
#> HttrAdapter enabled!
#> net connect allowed
#> net connect disabled
#> ejecting cassette: test_cassette_preserve
#> CrulAdapter disabled!
#> HttrAdapter disabled!
#> <vcr - Cassette> test_cassette_preserve
#> Record method: once
#> Serialize with: yaml
#> Persist with: FileSystem
#> Re-record interval (s):
#> Clean outdated interactions?: FALSE
#> update_content_length_header: FALSE
#> decode_compressed_response:
#> allow_playback_repeats: FALSE
#> allow_unused_http_interactions:
#> exclusive:
#> preserve_exact_body_bytes: TRUE
use_cassette("test_cassette_preserve", {
b = httr::GET("https://httpbin.org/image/jpeg")
testthat::expect_equal(length(b$content), 35588)
}, preserve_exact_body_bytes = TRUE)
#> CrulAdapter enabled!
#> HttrAdapter enabled!
#> net connect allowed
#> Error in charToRaw(x): l'argument doit être un vecteur de caractères de longueur 1
#> ejecting cassette: test_cassette_preserve
#> CrulAdapter disabled!
#> HttrAdapter disabled!
Created on 2019-12-13 by the reprex package (v0.3.0)
Oof, this is quite complicated, and i'm not as familiar with httr, i'll have a look.
I do want to make it easier to understand how vcr works - will keep working on that
@Rekyt try again after reinstalling. Should work now.
It works!
Hi @sckott, I've been trying to use
vcr
to implement tests inbnfimage
Now
vcr
does support saving images. But for a reason I don't know, when re-reading vcr cassettes, my tests kept failing.Here's a reprex:
Created on 2019-12-12 by the reprex package (v0.3.0)
Session info
``` r devtools::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 3.6.0 (2019-04-26) #> os macOS Sierra 10.12.6 #> system x86_64, darwin15.6.0 #> ui X11 #> language (EN) #> collate fr_FR.UTF-8 #> ctype fr_FR.UTF-8 #> tz Europe/Paris #> date 2019-12-12 #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date lib source #> assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.0) #> backports 1.1.5 2019-10-02 [1] CRAN (R 3.6.0) #> base64enc 0.1-3 2015-07-28 [1] CRAN (R 3.6.0) #> callr 3.4.0 2019-12-09 [1] CRAN (R 3.6.0) #> cli 2.0.0 2019-12-09 [1] CRAN (R 3.6.0) #> crayon 1.3.4 2017-09-16 [1] CRAN (R 3.6.0) #> crul 0.9.0 2019-11-06 [1] CRAN (R 3.6.0) #> curl 4.3 2019-12-02 [1] CRAN (R 3.6.0) #> desc 1.2.0 2018-05-01 [1] CRAN (R 3.6.0) #> devtools 2.2.1 2019-09-24 [1] CRAN (R 3.6.0) #> digest 0.6.23 2019-11-23 [1] CRAN (R 3.6.0) #> ellipsis 0.3.0 2019-09-20 [1] CRAN (R 3.6.0) #> evaluate 0.14 2019-05-28 [1] CRAN (R 3.6.0) #> fansi 0.4.0 2018-10-05 [1] CRAN (R 3.6.0) #> fauxpas 0.2.0 2018-03-01 [1] CRAN (R 3.6.0) #> fs 1.3.1 2019-05-06 [1] CRAN (R 3.6.0) #> glue 1.3.1 2019-03-12 [1] CRAN (R 3.6.0) #> highr 0.8 2019-03-20 [1] CRAN (R 3.6.0) #> htmltools 0.4.0 2019-10-04 [1] CRAN (R 3.6.0) #> httpcode 0.2.0 2016-11-14 [1] CRAN (R 3.6.0) #> httr 1.4.1 2019-08-05 [1] CRAN (R 3.6.0) #> jpeg 0.1-8.1 2019-10-24 [1] CRAN (R 3.6.0) #> jsonlite 1.6 2018-12-07 [1] CRAN (R 3.6.0) #> knitr 1.26 2019-11-12 [1] CRAN (R 3.6.0) #> lazyeval 0.2.2 2019-03-15 [1] CRAN (R 3.6.0) #> magrittr 1.5 2014-11-22 [1] CRAN (R 3.6.0) #> memoise 1.1.0 2017-04-21 [1] CRAN (R 3.6.0) #> pkgbuild 1.0.6 2019-10-09 [1] CRAN (R 3.6.0) #> pkgload 1.0.2 2018-10-29 [1] CRAN (R 3.6.0) #> prettyunits 1.0.2 2015-07-13 [1] CRAN (R 3.6.0) #> processx 3.4.1 2019-07-18 [1] CRAN (R 3.6.0) #> ps 1.3.0 2018-12-21 [1] CRAN (R 3.6.0) #> R6 2.4.1 2019-11-12 [1] CRAN (R 3.6.0) #> Rcpp 1.0.3 2019-11-08 [1] CRAN (R 3.6.0) #> remotes 2.1.0 2019-06-24 [1] CRAN (R 3.6.0) #> rlang 0.4.2 2019-11-23 [1] CRAN (R 3.6.0) #> rmarkdown 1.18 2019-11-27 [1] CRAN (R 3.6.0) #> rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.6.0) #> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.6.0) #> stringi 1.4.3 2019-03-12 [1] CRAN (R 3.6.0) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 3.6.0) #> testthat 2.3.1 2019-12-01 [1] CRAN (R 3.6.0) #> triebeard 0.3.0 2016-08-04 [1] CRAN (R 3.6.0) #> urltools 1.7.3 2019-04-14 [1] CRAN (R 3.6.0) #> usethis 1.5.1 2019-07-04 [1] CRAN (R 3.6.0) #> vcr * 0.4.0.91 2019-12-12 [1] Github (ropensci/vcr@6e863d8) #> webmockr 0.5.0 2019-12-04 [1] CRAN (R 3.6.0) #> withr 2.1.2 2018-03-15 [1] CRAN (R 3.6.0) #> xfun 0.11 2019-11-12 [1] CRAN (R 3.6.0) #> yaml 2.2.0 2018-07-25 [1] CRAN (R 3.6.0) #> #> [1] /Library/Frameworks/R.framework/Versions/3.6/Resources/library ```When reading the cassettes for a second time, the output of
a$content
israw(0)
instead of being a realraw()
of specified length.