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

Add options= to test(), convert most Rraw scripts #5845

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

MichaelChirico
Copy link
Member

Closes #5842.

Didn't touch tests.Rraw yet as there are 200+ existing calls to options(). Better to save that for a future clean-up. Converted the other scripts with a more manageable diff to demonstrate the new usage.

Copy link

codecov bot commented Dec 20, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.53%. Comparing base (566bff0) to head (50a6d17).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5845   +/-   ##
=======================================
  Coverage   97.53%   97.53%           
=======================================
  Files          80       80           
  Lines       14915    14915           
=======================================
  Hits        14547    14547           
  Misses        368      368           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ben-schwen
Copy link
Member

Looking great!

The only thing we might have to think about is where to put the options argument in a test(...) call. Current practice is AFAIC to have test(num, call, expected) so test(num, options=options, call, expected) differs from that.

@MichaelChirico
Copy link
Member Author

Looking great!

The only thing we might have to think about is where to put the options argument in a test(...) call. Current practice is AFAIC to have test(num, call, expected) so test(num, options=options, call, expected) differs from that.

yes, this is a new style. basically this is a "set up" step as it might be called in other unit testing frameworks. so I think it's important to have it up front for clarity. that doesn't have a parallel among current arguments. I might even put it before the test number, but definitely not after the test outcome parts.

@ben-schwen
Copy link
Member

yes, this is a new style. basically this is a "set up" step as it might be called in other unit testing frameworks. so I think it's important to have it up front for clarity. that doesn't have a parallel among current arguments. I might even put it before the test number, but definitely not after the test outcome parts.

I also thought about the setup step, so 2nd place makes definitely sense.

Pls, do not put it before the test number because in searching for tests I often use test(testnum if the test number occurs multiple times in tests.Rraw

@tdhock
Copy link
Member

tdhock commented Dec 20, 2023

I would like to see a similar test(testnum, my_computed_value, my_expected_value, env=list(SOME_ENV_VAR="VALUE")) -- I was recently working on #5807 which involves environment variables for getting default number of threads, and the tests would be much easier to understand/modify with such an enhancement to test.

@jangorecki
Copy link
Member

@tdhock I understand the use case, but if it is not as common as options, then I think it can be left to R's functions to set variables. Contrary R options are very common in tests, as Michael said, more than 200 times.

@MichaelChirico
Copy link
Member Author

I would like to see a similar test(testnum, my_computed_value, my_expected_value, env=list(SOME_ENV_VAR="VALUE")) -- I was recently working on #5807 which involves environment variables for getting default number of threads, and the tests would be much easier to understand/modify with such an enhancement to test.

I think it's perfectly reasonable, but let's save it for a follow-up issue to keep PRs sharp

@MichaelChirico
Copy link
Member Author

Here is a breakdown of the branches touching each test script as of now:

branch benchmark.Rraw froll.Rraw nafill.Rraw other.Rraw programming.Rraw types.Rraw
adapt
allow-env-dot-alias
assign_todos
benchmark
coerceAs
coerceAs_bit64
colselect
cutils2
frollapply
frollmax
frollmax2
frollmax3
frollmax4
frollmax5
frollmax7
frollmax8
frollmax9
fwrite_zlib_present
gforce_cumsum
is.valid
join-retain-more-keys
last_narm
nafill5
rbind_class_att
rollfuns
rollmedian
library(data.table)

tests = list.files(pattern = ".Rraw$", recursive = TRUE)
tests = setdiff(tests, "inst/tests/tests.Rraw")
branches_by_test = lapply(tests, function(test) {
  system2("git", c("log", "--all", "--format=%S", "--", test), stdout=TRUE) |>
    unique() |>
    sort() |>
    grep(pattern = "^refs/remotes/origin/", value=TRUE) |>
    gsub(pattern = "^refs/remotes/origin/", replacement = "") |>
    setdiff("test-options")
})

branch_link <- \(branch) paste0("[`", branch, "`](https://github.com/Rdatatable/data.table/tree/", branch, ")")

for (ii in seq_along(tests)) {
  branches = branches_by_test[[ii]]
  cat(sprintf(" - `%s`: %s\n", tests[ii], paste(branch_link(branches), collapse = " ")))
}

branch_data <- data.table(file = rep(tests, lengths(branches_by_test)), branch = unlist(branches_by_test)) |>
  dcast(branch ~ basename(file), fun.aggregate = \(x) if (length(x)) "" else "", value.var = "branch")
branch_data[, branch := branch_link(branch)]
knitr::kable(branch_data)

data.table spacing style

document in Rd

Add options= to test()

document in Rd

missed staged chunk

convert most Rraw scripts to use test(options=)

Merge branch 'master' into test-options

Merge remote-tracking branch 'origin/test-options' into test-options
data.table spacing style

document in Rd

Add options= to test()

document in Rd

missed staged chunk

convert most Rraw scripts to use test(options=)

Merge branch 'master' into test-options

Merge remote-tracking branch 'origin/test-options' into test-options
@MichaelChirico MichaelChirico changed the base branch from master to test-options-simple-files March 20, 2024 05:58
Copy link
Member Author

MichaelChirico commented Mar 20, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @MichaelChirico and the rest of your teammates on Graphite Graphite

Base automatically changed from test-options-simple-files to master March 21, 2024 11:21
@MichaelChirico MichaelChirico marked this pull request as draft March 26, 2024 00:01
@MichaelChirico MichaelChirico modified the milestones: 1.16.0, 1.17.0 Jul 10, 2024
@MichaelChirico MichaelChirico removed this from the 1.17.0 milestone Dec 3, 2024
@MichaelChirico MichaelChirico added this to the 1.18.0 milestone Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

test() should get an options= argument to transparently & temporarily set options for a test
4 participants