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

Replacing 'testthat' functions #2987 #3067

Merged
merged 43 commits into from
May 17, 2024

Conversation

Its-Maniaco
Copy link
Contributor

@Its-Maniaco Its-Maniaco commented Nov 15, 2022

This PR replaces the testthat function in mainstream files.
Addresses #2987

@Its-Maniaco
Copy link
Contributor Author

@Aariq @moki1202 @infotroph I tried replacing testthat function with appropriate replacement. Once I get a 👍 from you guys I will proceed with other functions as well.

@moki1202
Copy link
Collaborator

@Its-Maniaco This change looks pretty good to me! The arguments structure for the replaced function looks good too. But let's not count on my statement just yet 😉 . Once you get a green light from the other reviewers please make sure you've added the packageName to the respective description file and pushed the newly generated .Rd (documentation) file.

@Aariq
Copy link
Collaborator

Aariq commented Nov 15, 2022

This is fine as a drop-in replacement—you've got the pattern right. I don't understand what is going on in this particular instance though. The point of assert_that() (or expect_true()) is to throw an error when a condition isn't met. Wrapping it in try() makes it not throw an error. So in this particular instance, I think something like this would make more sense:

eq_units <- PEcAn.utils::units_are_equivalent(ncvar_unit, var_correct_unit)
if(!eq_units) {
  glue::glue("NetCDF unit '{ncvar_unit}' not equivalent to expected unit '{var_correct_unit}'.")
}

@Aariq
Copy link
Collaborator

Aariq commented Nov 15, 2022

Actually, it should probably use PEcAn.logger() to print the message.

eq_units <- PEcAn.utils::units_are_equivalent(ncvar_unit, var_correct_unit)
if(!eq_units) {
  PEcAn.logger::logger.error(
    glue::glue("NetCDF unit '{ncvar_unit}' not equivalent to expected unit '{var_correct_unit}'.")
  )
}

Errors from PEcAn.logger aren't R errors (I know, confusing) and don't exit out of the function. They just print the message with a timestamp and the word "ERROR"

@moki1202
Copy link
Collaborator

@Its-Maniaco any follow up to this?

@Its-Maniaco
Copy link
Contributor Author

@Aariq @moki1202
try2 <- purrr::partial(try, silent = TRUE)
test_dims <- list( try2(testthat::expect_type(dimensions, "list")),
can this part be replace with something similar to if(!is.list(dimensions)){stop("dimension is not of type list")}

@Aariq
Copy link
Collaborator

Aariq commented Nov 30, 2022

@Aariq @moki1202
try2 <- purrr::partial(try, silent = TRUE)
test_dims <- list( try2(testthat::expect_type(dimensions, "list")),
can this part be replace with something similar to if(!is.list(dimensions)){stop("dimension is not of type list")}

This is from check_met_input_file(), yeah? I think what the current code is trying to do is not to fail fast (which is what your suggestion would do), but rather to collect all the validation errors into one place as text (test_dims_summary$dim_errors) and return them as part of the results object. This is where something from assertthat would likely be a better "drop-in" replacement—maybe validate_that()?

@Aariq
Copy link
Collaborator

Aariq commented Nov 30, 2022

Remember to also move testthat from "Imports" to "Suggests" in the relevant DESCRIPTION files

@Its-Maniaco
Copy link
Contributor Author

@Aariq try2(testthat::expect_match( ncdf4::ncatt_get(nc, "time", "units")[["value"]],time_regex)) time_regex I could not figure out a replacement for this.

@meetagrawal09 meetagrawal09 mentioned this pull request Jan 24, 2023
13 tasks
@Its-Maniaco
Copy link
Contributor Author

@Aariq @moki1202 @infotroph Is there anything else needed before this PR gets merged?

@infotroph
Copy link
Member

Looks like you'll need to run ./scripts/generate_dependencies.R and commit the changes it creates

@mdietze
Copy link
Member

mdietze commented Mar 30, 2023

Check is failing because of a need to run make document. Tests is failing on load.cfmet.R -- @Its-Maniaco I think you'll want to take a closer look at those issues

@mdietze
Copy link
Member

mdietze commented Apr 26, 2023

@Its-Maniaco pinging you to hopefully finish up this PR

@mdietze
Copy link
Member

mdietze commented Sep 3, 2023

@Its-Maniaco wanted to check in about your plans / ability to finish up this PR?

@mdietze
Copy link
Member

mdietze commented Jan 18, 2024

@Its-Maniaco currently getting a test failure in load.cfmet.R

@infotroph infotroph enabled auto-merge May 16, 2024 23:19
@infotroph infotroph added this pull request to the merge queue May 16, 2024
Merged via the queue into PecanProject:develop with commit d2847e9 May 17, 2024
13 checks passed
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.

5 participants