Skip to content
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

Dem module tests #48

Merged
merged 42 commits into from
Dec 19, 2024
Merged

Dem module tests #48

merged 42 commits into from
Dec 19, 2024

Conversation

meiertgrootes
Copy link
Collaborator

limited test suite framework for valley.R

@meiertgrootes
Copy link
Collaborator Author

@fnattino This PR sets up limited tests for the functionalities in valley.R. Would be good to discuss what else to add. This will also require (some) realworld test data to be added to the package. Please advise on this. Some paths are currently place holders.

@fnattino fnattino mentioned this pull request Nov 28, 2024
Copy link
Contributor

@fnattino fnattino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for starting this @meiertgrootes! Once #42 is merged, I can add some test data to the package (#49), which we can use for testing.


expect_equal(valley, expected_valley, tolerance = 1e-4)

})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
})
})

@fnattino fnattino requested a review from cforgaci December 2, 2024 15:35
@fnattino
Copy link
Contributor

fnattino commented Dec 2, 2024

@cforgaci #51 is merged, we can move on with the tests!

@cforgaci cforgaci marked this pull request as ready for review December 11, 2024 20:47
Copy link
Contributor

@cforgaci cforgaci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @meiertgrootes! I made a few additional commits:

  • merged the package data from Add packaged DEM data #51
  • replaced placeholders with package data in the tests
  • created test data for the last test

A few things left to do:

  1. We should mock the API calls in the first two tests and allow them to run on CI. I will try this with the mockery package.

  2. When dropping the skip_on_ci() from the last test, I've encountered some issues, will try to fix them and get back with an update.

@cforgaci
Copy link
Contributor

A few things left to do:

  1. We should mock the API calls in the first two tests and allow them to run on CI. I will try this with the mockery package.

This is done.

  1. When dropping the skip_on_ci() from the last test, I've encountered some issues, will try to fix them and get back with an update.

@fnattino, I am having issues with accessing tests/testthat/fixtures/expected_valley.gpkg in the last test. All tests pass when I run devtools::test() but R CMD check fails with Error: Cannot open "fixtures/expected_valley.gpkg"; The file doesn't seem to exist. In the current option, I try using tests/testthat/setup.R to make a copy of the fixtures directory to the root of the package installed temprarily by R CMD check, but this does not seem to work either.

I also tried without setup.R and with the full path on line 61, same error:

expected_valley <- sf::st_read("tests/testthat/fixtures/expected_valley.gpkg",
                                quiet = TRUE) |>
    sf::st_as_sfc()

I know you tried once using test data under the tests directory. Any ideas why I am encountering this issue?

@cforgaci
Copy link
Contributor

@fnattino thanks for the review! After implementing the suggested changes, I still see Error: Cannot open "testdata/expected_valley.gpkg"; The file doesn't seem to exist. in R-CMD-check.

@fnattino
Copy link
Contributor

So annoying.. By googleing a bit I found that in this package very simple relative links seems to work: https://github.com/jeroen/openssl/blob/master/tests/testthat/test_cert.R

So can we try to do:

  expected_valley <- sf::st_read("./testdata/expected_valley.gpkg",
                                 quiet = TRUE) |>
    sf::st_as_sfc()

Locally tests pass..

@cforgaci
Copy link
Contributor

So annoying.. By googleing a bit I found that in this package very simple relative links seems to work: https://github.com/jeroen/openssl/blob/master/tests/testthat/test_cert.R

So can we try to do:

  expected_valley <- sf::st_read("./testdata/expected_valley.gpkg",
                                 quiet = TRUE) |>
    sf::st_as_sfc()

Locally tests pass..

I tried this too, and I get the same results: locally tests pass and CI check fails.

@fnattino
Copy link
Contributor

That package also has the --install-tests option as install argument in the .Rproj file:
https://github.com/jeroen/openssl/blob/597003e7aa95106cd34ff82c431e551a1e1e2978/openssl.Rproj#L20C55-L20C70

This should add the tests (and testdata) to the build, maybe is this the solution? If this does not work as well we might consider whether we actually want to remove the data..

@cforgaci
Copy link
Contributor

@fnattino the testdata issue is solved, but I have one last issue I cannot solve. The last test did not pass R-CMD-check on Wihdows due to a precision issue and after a couple of attempts I still cannot figure out how to solve that. Any thoughts? I remember you gave a solution to a similar issue, maybe her in the same PR.

@fnattino
Copy link
Contributor

fnattino commented Dec 19, 2024

The following should allow for some tolerance. The "exact" means that the two features are used as-they-are, so vertices need to be ordered in the same way. The "par" argument actually set the tolerance for equality:

sf::st_equals_exact(geometry1, geometry2, par =1.e-4, sparse = FALSE)

@cforgaci
Copy link
Contributor

cforgaci commented Dec 19, 2024

sf::st_equals_exact(geometry1, geometry2, par =1.e-4, sparse = FALSE)

@fnattino that was it. I had to adjust the precision of the two objects. All checks seem to be passing. If you agree, we can merge this now.

@fnattino
Copy link
Contributor

Thanks for all the effort with this @cforgaci - this was quite more painful than anticipated.. go ahead and merge for my side!

@cforgaci
Copy link
Contributor

Thanks for all the effort with this @cforgaci - this was quite more painful than anticipated.. go ahead and merge for my side!

Painful is a good word :) Thanks @fnattino!

@cforgaci cforgaci merged commit 2f53f00 into main Dec 19, 2024
8 checks passed
@cforgaci cforgaci deleted the DEM_module_tests branch December 19, 2024 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants