-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
start small refactoring #46
Conversation
Codecov Report
@@ Coverage Diff @@
## master #46 +/- ##
==========================================
+ Coverage 84.86% 85.21% +0.35%
==========================================
Files 4 5 +1
Lines 218 230 +12
==========================================
+ Hits 185 196 +11
- Misses 33 34 +1
Continue to review full report at Codecov.
|
|
||
Assertion on 'wfs' failed: Must be an R6 class, not character. | ||
|
||
# emodnet_get_layers errors well when bad layer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably not the best error message, actually.
httptest::with_mock_dir(testthat::test_path(file.path("fixtures", name)), ...) | ||
} | ||
|
||
create_biology_wfs <- function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this way we re-use this one in most tests, with a single fixture :-)
@@ -0,0 +1 @@ | |||
pre_test_options <- options(usethis.quiet = TRUE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is how it's done in usethis itself
wfs <- create_biology_wfs() | ||
expect_equal(class(wfs), c("WFSClient", "OWSClient", "OGCAbstractObject", "R6")) | ||
expect_equal(wfs$getUrl(), "http://geo.vliz.be/geoserver/Emodnetbio/wfs") | ||
}) | ||
|
||
test_that("Specified connection works", { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@annakrystalli what was the difference between default and specified connection? I'm not sure I got it so I might have badly altered the test.
|
||
expect_equal(or_filter_sf$country %>% unique(), c("Bulgaria", "Baltic Sea")) | ||
|
||
skip_if_offline() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@annakrystalli simpler filters because I used smaller layers.
expect_length(l_crs, 1) | ||
expect_equal(3857, l_crs) | ||
test_that("crs transform works from wfs object", { | ||
skip_if_offline() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: Do we need to skip if offline if we are going to use cached results through httptest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've only one question regarding skip if offline below.
Once that's resolved, I'm happy to merge
Ooops, some merge conflicts too. Let me know if you want me to tackle them @maelle |
Still trying to figure out what the problem is with failing tests. The annoying thing is that the code works when run outside of the testing framework: library(EMODnetWFS)
library(testthat)
create_biology_wfs <- function() {
emodnet_init_wfs_client(service = "biology")
}
wfs <- create_biology_wfs()
#> Loading ISO 19139 XML schemas...
#> Loading ISO 19115 codelists...
#> Loading IANA mime types...
#> No encoding supplied: defaulting to UTF-8.
#> ✓ WFS client created succesfully
#> ℹ Service: 'http://geo.vliz.be/geoserver/Emodnetbio/wfs'
#> ℹ Version: '2.0.0'
simple_filter_sf <- emodnet_get_layers(
wfs = wfs,
layers = "mediseh_cymodocea_pnt",
cql_filter = "country='Grecia'",
reduce_layers = TRUE
)
simple_filter_sf
#> Simple feature collection with 159 features and 3 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 20.01482 ymin: 35.19033 xmax: 28.20996 ymax: 40.95
#> Geodetic CRS: WGS 84
#> First 10 features:
#> gml_id id country the_geom
#> 1 mediseh_cymodocea_pnt.981 0 Grecia POINT (24.88624 37.43593)
#> 2 mediseh_cymodocea_pnt.982 0 Grecia POINT (24.66667 36.96667)
#> 3 mediseh_cymodocea_pnt.983 0 Grecia POINT (23.91667 37.71667)
#> 4 mediseh_cymodocea_pnt.984 0 Grecia POINT (24.43333 36.71667)
#> 5 mediseh_cymodocea_pnt.985 0 Grecia POINT (26.2 39.2)
#> 6 mediseh_cymodocea_pnt.986 0 Grecia POINT (26.48333 39.08333)
#> 7 mediseh_cymodocea_pnt.987 0 Grecia POINT (24.00725 37.92523)
#> 8 mediseh_cymodocea_pnt.988 0 Grecia POINT (24.5 40.95)
#> 9 mediseh_cymodocea_pnt.989 0 Grecia POINT (24.56667 40.91667)
#> 10 mediseh_cymodocea_pnt.990 0 Grecia POINT (24.3176 40.81667)
expect_equal(unique(simple_filter_sf$country), 'Grecia') Created on 2022-03-14 by the reprex package (v2.0.1) Yet during testing they fail.
|
I feel like it is something to do with how the fixtures are set up. I also noticed something strange in the fs::dir_tree("tests", 4)
#> /Users/Anna/Documents/workflows/EMODnet/EMODnetWFS/tests
#> ├── testthat
#> │ ├── _snaps
#> │ │ ├── layer_attributes.md
#> │ │ └── layers.md
#> │ ├── fixtures
#> │ │ ├── bathymetry-info
#> │ │ │ └── ows.emodnet-bathymetry.eu
#> │ │ │ └── wfs-8af060.xml
#> │ │ ├── biology-attr2
#> │ │ │ └── geo.vliz.be
#> │ │ │ └── geoserver
#> │ │ ├── biology-attr3
#> │ │ │ └── geo.vliz.be
#> │ │ │ └── geoserver
#> │ │ ├── biology-info
#> │ │ │ └── geo.vliz.be
#> │ │ │ └── geoserver
#> │ │ ├── mediseh_cymodocea_pnt-Francia-Grecia
#> │ │ │ └── geo.vliz.be
#> │ │ │ └── geoserver
#> │ │ ├── mediseh_cymodocea_pnt-Grecia
#> │ │ │ └── geo.vliz.be
#> │ │ │ └── geoserver
#> │ │ └── mediseh_posidonia_nodata
#> │ │ └── geo.vliz.be
#> │ │ └── geoserver
#> │ ├── helper.R
#> │ ├── setup.R
#> │ ├── teardown.R
#> │ ├── test-client.R
#> │ ├── test-filter.R
#> │ ├── test-info.R
#> │ ├── test-layer_attributes.R
#> │ ├── test-layers.R
#> │ ├── testdata
#> │ │ ├── attr_desc.rds
#> │ │ ├── maritime_crs.rds
#> │ │ └── test-data-prep.R
#> │ └── tests
#> │ └── testthat
#> │ └── fixtures
#> │ ├── bathymetry-info
#> │ ├── biology-attr
#> │ ├── biology-attr2
#> │ ├── biology-attr3
#> │ ├── biology-info
#> │ ├── layers-biology
#> │ ├── layers-biology2
#> │ ├── layers-biology3
#> │ ├── layers-biology4
#> │ ├── layers-biology5
#> │ ├── mediseh_cymodocea_pnt-Francia-Grecia
#> │ ├── mediseh_cymodocea_pnt-Grecia
#> │ ├── mediseh_posidonia_nodata
#> │ ├── reduce
#> │ └── wfs-biology
#> └── testthat.R Created on 2022-03-14 by the reprex package (v2.0.1) |
Fix #60
Mostly simplifying control flow.
In tests I use
skip_if_offline()
which with the latest testthat version also doesskip_on_cran()
. I can't cache all responses as some of them are not done with httr (but with a sf function IIRC). With the skipping, the tests don't fail when offline. (I've turned of wifi).TODOS