-
Notifications
You must be signed in to change notification settings - Fork 27
Try some basic unit tests #217
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
Conversation
|
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 |
|
Ok, I've successfully set up mockery and vdiffr to do tests of functions that use the network (like I also added 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. |
Set up vdiffr and mockery to do testing of plots and mocking of network requests.
|
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. |
|
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? |
|
I can't assign myself to review this but I will |
sgsmob
left a comment
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 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, |
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.
Please alphabetize these lists
| expected) | ||
| }) | ||
|
|
||
| test_that("basic lagged correlations", { |
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.
Please add a comment explaining the purpose of this test.
| expected) | ||
| }) | ||
|
|
||
| test_that("lags are in correct direction", { |
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.
Please add a comment explaining the purpose of this test.
| library(covidcast) | ||
| library(mockery) | ||
|
|
||
| test_that("covidcast_meta", { |
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.
Please add a comment explaining this test
| stub(covidcast_meta, ".request", | ||
| list(message = "argle-bargle")) | ||
|
|
||
| expect_error(covidcast_meta()) |
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.
Does this allow specification of which error is expected?
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.
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", { |
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.
Please leave a comment describing the purpose of this test
| )) | ||
| }) | ||
|
|
||
| test_that("state line graphs", { |
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.
Please leave a comment describing the purpose of this test
| range = c(0, 10))) | ||
| }) | ||
|
|
||
| test_that("simple state choropleths", { |
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.
Please leave a comment describing the purpose of this test
| library(covidcast) | ||
| library(dplyr) | ||
|
|
||
| test_that("aggregate and shift", { |
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.
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 |
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.
If these tests are not working, they should just be removed from this file entirely.
|
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. |
|
Also, regarding the commented-out test code in |
Adding a TODO in the comments preceding the commented out tests would be sufficient to leave them there commented out. |
WIP. Will write some more tests Soonish to see what happens (and how well our CI works).