Skip to content

Conversation

@capnrefsmmat
Copy link
Contributor

WIP. Will write some more tests Soonish to see what happens (and how well our CI works).

@capnrefsmmat
Copy link
Contributor Author

Apparently there's a nice package for testing plotting, so we can also do that to avoid regressing our plotting features: https://github.com/r-lib/vdiffr

@capnrefsmmat capnrefsmmat marked this pull request as draft October 31, 2020 03:07
@capnrefsmmat
Copy link
Contributor Author

capnrefsmmat commented Oct 31, 2020

Ok, I've successfully set up mockery and vdiffr to do tests of functions that use the network (like covidcast_signal) and tests of our plotting/mapping functions. They work great on simple examples.

I also added DEVELOP.md with instructions on what to run and a PR checklist.

I think it'll be easy to make a few different plot examples (by saving a few real data frames) and save those as the key plotting tests. We could also add tests for issues like #134 when they're fixed.

cc @JedGrabman @ryantibs, so you can see how it will look to write tests of new features you're working on.

@capnrefsmmat capnrefsmmat marked this pull request as ready for review November 1, 2020 23:07
@capnrefsmmat capnrefsmmat requested a review from ryantibs November 1, 2020 23:07
@capnrefsmmat
Copy link
Contributor Author

There are a lot more tests we should write, but I likely won't have time to write more for a while. So it's probably best if we merge this now, and then file an issue with a list of things we should add tests for. Then the testing framework will be in place for everyone to use for their new PRs, and we can fill in the testing gaps over the next few weeks.

@ryantibs
Copy link
Member

ryantibs commented Nov 2, 2020

This looks great, thank you @capnrefsmmat for starting us off with some tests! I won't be able to review this in any level of detail in the next few days, too bogged down with other things. Are any of @nmdefries @JedGrabman @sarah-colq @sgsmob @undefx @sangwon-hyun @nloliveira @capolitsch @brookslogan @bnaras available?

@sgsmob
Copy link
Contributor

sgsmob commented Nov 2, 2020

I can't assign myself to review this but I will

Copy link
Contributor

@sgsmob sgsmob left a comment

Choose a reason for hiding this comment

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

This will be a great asset to this repo!

Not entirely sure how to validate an initial commit of the charts but I think they are probably ok. Will approve once some more comments are added.

rmarkdown,
gridExtra
gridExtra,
testthat,
Copy link
Contributor

Choose a reason for hiding this comment

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

Please alphabetize these lists

expected)
})

test_that("basic lagged correlations", {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a comment explaining the purpose of this test.

expected)
})

test_that("lags are in correct direction", {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a comment explaining the purpose of this test.

library(covidcast)
library(mockery)

test_that("covidcast_meta", {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a comment explaining this test

stub(covidcast_meta, ".request",
list(message = "argle-bargle"))

expect_error(covidcast_meta())
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this allow specification of which error is expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not if covidcast_meta() uses stop(), which does not specify a specific error type -- unless you regexp-match against the error message.

I've just changed covidcast_meta() to use abort() with a specific error class, so we can catch and handle it, and the test can verify it was raised correctly.

# https://github.com/r-lib/vdiffr/issues/71
context("plot")

test_that("simple line graph", {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please leave a comment describing the purpose of this test

))
})

test_that("state line graphs", {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please leave a comment describing the purpose of this test

range = c(0, 10)))
})

test_that("simple state choropleths", {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please leave a comment describing the purpose of this test

library(covidcast)
library(dplyr)

test_that("aggregate and shift", {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please leave comments describing the purpose of the tests in this file

value = c(4, 6, 5, 1, 3, 2)),
class = c("covidcast_signal_long", "data.frame")))

# Now try it long in the first place. Currently fails because wide format does
Copy link
Contributor

Choose a reason for hiding this comment

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

If these tests are not working, they should just be removed from this file entirely.

@capnrefsmmat
Copy link
Contributor Author

capnrefsmmat commented Nov 3, 2020

Pushed fixes. Rather than adding a bunch of comments to the tests, I tried to change their names so that when you read them, they're meaningful, such as

test_that("covidcast_meta raises error when API signals one", {

Also the plotting tests don't really have deep purposes besides making plots with different options, so we know if those options break or change; I added an explanation at the top of the test file.

@capnrefsmmat
Copy link
Contributor Author

Also, regarding the commented-out test code in test-wrangle.R: I can use skip() to skip that instead of commenting out, but that also prints a message every time you run the tests. The issue is that I want to change the code to make that test pass, but it doesn't yet; would you prefer the code be removed entirely and returned when the issues is fixed, leave it commented out, or have it skipped and noisily complain to encourage people to fix the wrangling code?

@sgsmob
Copy link
Contributor

sgsmob commented Nov 3, 2020

Also, regarding the commented-out test code in test-wrangle.R: I can use skip() to skip that instead of commenting out, but that also prints a message every time you run the tests. The issue is that I want to change the code to make that test pass, but it doesn't yet; would you prefer the code be removed entirely and returned when the issues is fixed, leave it commented out, or have it skipped and noisily complain to encourage people to fix the wrangling code?

Adding a TODO in the comments preceding the commented out tests would be sufficient to leave them there commented out.

@capnrefsmmat capnrefsmmat merged commit 9bf67da into main Nov 3, 2020
@taylor-arnold taylor-arnold deleted the r-tests branch March 19, 2021 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants