osmdata icon indicating copy to clipboard operation
osmdata copied to clipboard

Update tests to use internal sample .osm file

Open mpadge opened this issue 3 years ago • 2 comments

Most of the tests could be run with no mocking at all, by just using an internal .osm file.

mpadge avatar Jan 26 '22 12:01 mpadge

@jmaspons What are your thoughts on this issue? Mock tests are currently only in these four files:

  1. Single mock call only which could be replaced: https://github.com/ropensci/osmdata/blob/503674690ab3763cf5ea48e699c3466849c2e24f/tests/testthat/test-unname.R#L15-L17

  2. In test-features.R, which can't be replaced by an internal file.

  3. Single mock call only which could be replaced: https://github.com/ropensci/osmdata/blob/503674690ab3763cf5ea48e699c3466849c2e24f/tests/testthat/test-elevation.R#L11-L13

  4. In test-getbb.R, with lots of mocked calls to nominatim which likely can't be replaced.

  5. Lots of calls in test-osmdata.R which likely could be replaced by using a local file instead of mocking: https://github.com/ropensci/osmdata/blob/503674690ab3763cf5ea48e699c3466849c2e24f/tests/testthat/test-osmdata.R#L267-L269

That suggests this, which would be good to do for current (v0.1.2) release:


TODO

  • [ ] Replace single mock call in test-unname.R through using local file.
  • [ ] Replace single mock call in test-elevation.R through using local file.
  • [ ] Replace most (all?) mock calls in test-osmdata.R through using local file instead.

mpadge avatar Feb 07 '23 09:02 mpadge

Mock calls are cool! I would keep them in the places where we actually want to check the functionality, ie. test-osmdata.R to check overpass_query function. In other places such as test-elevation.R or test-unname.R it's not necessary because there we are testing other functions, but it doesn't hurt.

All in all, if the test coverage doesn't degrade, both approaches are fine. What can be interesting to reduce the package size is to reuse the mock calls. I don't see why we need different queries for each osmdata_* function. Perhaps different mock calls for different query types (adiff, diff, tags...) is enough if needed at all (.osm files also works for checking all the code paths).

jmaspons avatar Feb 07 '23 17:02 jmaspons