-
Notifications
You must be signed in to change notification settings - Fork 1
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
Reviewing the tests at the tiltIndicator package #578
Comments
@AnneSchoenauer, a great place to learn about tests is here but I'll explain them a bit in this comment. Tests always live in the folder tests/testthat/. If you're browsing them on GitHub the URL is a bit more complicated: https://github.com/2DegreesInvesting/tiltIndicator/tree/main/tests/testthat You'll see many tests but you should mainly focus only on the test-files which names match In the beginning they will look intimidating, but thinks of each test as a reprex. plus an encoded expectation. A reprex is a tiny reproducible example that you construct to show a specific behaviour of the code. Typically you inspect the result of the reprex by looking at it. A test only extends a reprex by adding code that inspects the result automatically -- i.e. an expectation. If the expectation is met nothing happens but if it is not met then it trows a failure message. For example, consider this test: test_that("outputs expected columns at company level", {
companies <- example_companies()
scenarios <- example_scenarios()
inputs <- example_inputs()
product <- sector_profile_upstream_at_product_level(companies, scenarios, inputs)
out <- any_at_company_level(product)
expected <- cols_at_company_level()
expect_equal(names(out)[seq_along(expected)], expected)
}) Here I remove the test-related code to show you that it's just a reprex: devtools::load_all()
#> ℹ Loading tiltIndicator
companies <- example_companies()
scenarios <- example_scenarios()
inputs <- example_inputs()
product <- sector_profile_upstream_at_product_level(companies, scenarios, inputs)
out <- any_at_company_level(product)
expected <- cols_at_company_level()
# Compare
names(out)[seq_along(expected)]
#> [1] "companies_id" "grouped_by" "risk_category" "value"
# Same
expected
#> [1] "companies_id" "grouped_by" "risk_category" "value" Created on 2023-11-06 with reprex v2.0.2 So you may try guess what each test does by reading the test-title. In the example above the title is Learning moreI recorded ds-incubators about reprex and also about tests. https://bit.ly/ds-incubator-videos
![]()
![]() |
@maurolepore Great! Thanks a lot! I blocked some time for Thursday to walk through all the material :) Looking forward to it! |
Warn you that looking at tests will burn your brain :-) A more fun and focused way to test the package from your perspective would be to formulate a number of key conceptual questions, then try create a reprex that answers your question using the package and a tiny dataset (often 1-2 rows of data are the most useful. More than that and the output gets too large to understand). Then you can give me your reprexes and I can turn them into formal tests. |
After thinking and reviewing the output files I think it is good to have the following tests. @maurolepore this is only an overview ticket for me now. I will create little tickets and reprex so that you know on what we need to work on.
|
Dear @Tilmon following this conversation here could you please think about potential tests that we need in the tiltIndicator package to ensure that the code mirrors the methodology that we came up with. |
Here is a 10' video to help you review the tests. A tip to quickly overview all tests is to go to a repo and search for the string "test_that(". For example: https://github.com/search?q=repo%3A2DegreesInvesting%2FtiltIndicator%20%22test_that(%22&type=code That will match all the test-titles so you can quickly skim the intent of all our tests and then explore only the ones you want. Remember to expand the links "Show xxx more tests" |
Thanks so much, @maurolepore ! @AnneSchoenauer , FYI, as discussed, I checked that all tests I applied in summer as part of the data prep are now also reflected in tiltIndicator and tiltIndicatorAfter. |
Hi @Tilmon, should I close this issue if completed? |
@kalashsinghal good idea, I'll close it! |
@maurolepore, we discussed a while ago on how best I can review the tiltIndicator package, and we said it would be good if I go through the tests that you already implemented and I see if there are tests missing. I would like to do this in the next weeks. Could you please let me know where to best look for the test best? We also talked about the challenges that there are functions in function in functions and therefore it is hard for me to understand if the code really implements the methodology that we came up with. However, I understood that if I make sure that we have all tests implemented that we need that it is okay that I don't see exactly the functions that implement the code right?
Thanks a lot!
All the best
Anne
The text was updated successfully, but these errors were encountered: