Update R pre-commit package version and fix broken tests#64
Conversation
This reverts commit 128edb9.
|
|
||
|
|
There was a problem hiding this comment.
I couldn't find any documentation of this change, but it seems that the latest version of styler bundled with pre-commit is now enforcing a max of two newlines between code blocks. (See here for failing pre-commit logs.) It's possible we could choose to update our styler config to override this setting, but I personally agree that two newlines should be the maximum amount of space between code blocks, so I decided to just implement it across the files that are currently using a max of four newlines.
| @@ -0,0 +1,70 @@ | |||
| # lookup values/data are correct | |||
There was a problem hiding this comment.
This is an example of a snapshot file -- expect_snapshot_value() generates it automatically the first time it runs, and then on subsequent runs it compares the output of the lookup_agency() function to this file.
| lookup_agency(2014:2019, "12064"), | ||
| "cf6dcb93bf" | ||
|
|
||
| local_edition(3) # Enable snapshot testing |
There was a problem hiding this comment.
This is required since the new snapshot tests are part of the 3rd edition of testthat, which is opt-in only. I'm choosing to only opt-in for this one test, since I suspect we'll need to migrate other tests to meet the new standard and I don't want to bother with that right now.
| return_linter = NULL, | ||
| commented_code_linter = NULL, | ||
| pipe_consistency_linter = pipe_consistency_linter(c("auto")) |
There was a problem hiding this comment.
These defaults have all changed in the latest version of lintr. It might be worth conforming to the new lintr defaults at some point, but I don't want to deal with it right now, so I'm just reverting to the previous defaults.
| hooks: | ||
| - id: check-added-large-files | ||
| args: ['--maxkb=200'] | ||
| args: ['--maxkb=500'] |
There was a problem hiding this comment.
One of the snapshot test files is slightly larger than 200kb. We probably shouldn't make a habit of committing large files to the repo on a regular basis, but I think one medium-sized snapshot file is fine, so I'm bumping this limit to allow my PR to pass this check.
kyrasturgill
left a comment
There was a problem hiding this comment.
Everything makes sense to me! Thanks for the thorough explanation of these updates.
Background
This PR implements two fixes for problems with our automated checks that are preventing us from merging PRs:
digest). This PR updates our R pre-commit package version to get it working with R 4.5.x.lookup_agency()function are failing for reasons that I can't quite figure out. This PR switches to a more modern version of the snapshot test that resolves the error and will provide better output if it ever fails again in the future. (See the section below for more details.)Failing snapshot tests
We use two snapshot tests in order to test that the
lookup_agency()function returns exactly the same output for two medium-sized queries. Those tests are currently implemented using thetestthatassertion functionexpect_known_hash():ptaxsim/tests/testthat/test-lookup.R
Lines 229 to 236 in eb1e3e8
For some reason, these two
lookup_agency()calls return a different hash on CI than they do locally (see here for example CI logs). The hash matches the expected value in the test when I run it on my local machine, but the hash is different when the test runs on thetest-coverageGitHub workflow.I spent a few hours trying to figure out the source of the discrepancy but I couldn't quite get it. During my investigation, I wrote a script to confirm that the local and CI dataframes have exactly the same contents but different object hashes. In order to run this script, you'll need to manually download the following CI artifacts and save them to the corresponding filename in your
ptaxsim/directory (I didn't bother scripting this download because it requires a GitHub auth token):agency-2014-2019-ci.zip: https://github.com/ccao-data/ptaxsim/actions/runs/20830893132/artifacts/5068218666agency-summary-ci.zip: https://github.com/ccao-data/ptaxsim/actions/runs/20830893132/artifacts/5068218740Click here to expand a hidden section containing the script code
We shouldn't even really be using
expect_known_hash()for these tests anymore, because it is deprecated in the latest version oftestthat. Instead,testthatnow recommends usingexpect_snapshot_output()andexpect_snapshot_value()for snapshot tests. These new tests are not only recommended, they also provide verbose error output that shows exactly which rows are mismatching in the case of a snapshotted dataframe. This is nice for ourlookup_agency()tests -- it's very difficult to debug a test failure based on the object hash changing (as my script demonstrates above), but since the newexpect_snapshot_*()tests work with archived output rather than object hashes, they will be able to show us exactly why the output differs from the snapshot if the test fails in the future.This snapshotting stuff may be unfamiliar so I'm happy to talk it through in person if it would be helpful!