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

TealAppDriver skips tests when shinytest2 or rvest are not installed #1432

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

averissimo
Copy link
Contributor

Copy link
Contributor

github-actions bot commented Dec 18, 2024

badge

Code Coverage Summary

Filename                          Stmts    Miss  Cover    Missing
------------------------------  -------  ------  -------  ----------------------------------------------------------------------------------------------------------------------------------------
R/checkmate.R                        24       0  100.00%
R/dummy_functions.R                  67      11  83.58%   41, 43, 85-93
R/get_rcode_utils.R                  12       0  100.00%
R/include_css_js.R                   22      17  22.73%   12-38, 76-82
R/init.R                             99      42  57.58%   150-159, 161, 173-194, 219-222, 229-235, 238-239, 241
R/landing_popup_module.R             25      25  0.00%    61-87
R/module_bookmark_manager.R         158     127  19.62%   47-68, 88-138, 143-144, 156, 203, 238-315
R/module_data_summary.R             203      37  81.77%   26-54, 68, 78, 232, 263-267
R/module_filter_data.R               64       2  96.88%   22-23
R/module_filter_manager.R           230      57  75.22%   56-62, 73-82, 90-95, 108-112, 117-118, 291-314, 340, 367, 379, 386-387
R/module_init_data.R                 74       0  100.00%
R/module_nested_tabs.R              227      85  62.56%   40-136, 168, 193-195, 312, 346
R/module_snapshot_manager.R         216     146  32.41%   89-95, 104-113, 121-133, 152-153, 170-180, 184-199, 201-208, 215-230, 234-238, 240-246, 249-262, 265-273, 303-317, 320-331, 334-340, 354
R/module_teal_data.R                149      76  48.99%   44-150
R/module_teal_lockfile.R            131      44  66.41%   32-36, 44-56, 59-61, 75, 85-87, 99-101, 109-118, 121, 123, 125-126, 160-161
R/module_teal_with_splash.R          12      12  0.00%    22-38
R/module_teal.R                     195      87  55.38%   48-143, 158, 184-185, 224
R/module_transform_data.R           110       4  96.36%   20, 59, 129-130
R/modules.R                         278      71  74.46%   171-175, 230-233, 356-376, 384, 534-540, 553-561, 576-624, 657, 669-677
R/reporter_previewer_module.R        19       2  89.47%   30, 34
R/show_rcode_modal.R                 24      24  0.00%    17-42
R/tdata.R                            14      14  0.00%    19-61
R/teal_data_module-eval_code.R       24       0  100.00%
R/teal_data_module-within.R           7       0  100.00%
R/teal_data_module.R                 20       0  100.00%
R/teal_data_utils.R                  10       0  100.00%
R/teal_reporter.R                    68       6  91.18%   69, 77, 125-126, 129, 146
R/teal_slices-store.R                29       0  100.00%
R/teal_slices.R                      63       0  100.00%
R/teal_transform_module.R            45       0  100.00%
R/TealAppDriver.R                   353     353  0.00%    55-738
R/utils.R                           245      38  84.49%   391-440
R/validate_inputs.R                  32       0  100.00%
R/validations.R                      58      37  36.21%   110-377
R/zzz.R                              15      11  26.67%   4-18
TOTAL                              3322    1328  60.02%

Diff against main

Filename      Stmts    Miss  Cover
----------  -------  ------  --------
TOTAL             0       0  +100.00%

Results for commit: 72cc3d8

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

Copy link
Contributor

github-actions bot commented Dec 18, 2024

Unit Tests Summary

  1 files   27 suites   10m 26s ⏱️
275 tests 257 ✅ 18 💤 0 ❌
501 runs  483 ✅ 18 💤 0 ❌

Results for commit 72cc3d8.

♻️ This comment has been updated with latest results.

Copy link
Contributor

github-actions bot commented Dec 18, 2024

Unit Test Performance Difference

Test Suite $Status$ Time on main $±Time$ $±Tests$ $±Skipped$ $±Failures$ $±Errors$
module_teal 💔 $146.12$ $+2.96$ $0$ $0$ $0$ $0$
shinytest2-reporter 💔 $65.61$ $+1.22$ $0$ $0$ $0$ $0$

Results for commit 91be1ca

♻️ This comment has been updated with latest results.

Comment on lines +14 to +15
if (!requireNamespace(.x, quietly = TRUE)) {
if (use_testthat) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about inverting the order of the if else clause, so if there is no testthat and it is not in use the TealAppDriver class won't check for the suggested package used for testing (this uses && shortcut) .

Here is my suggestion (indentation would need to change accordingly):

Suggested change
if (!requireNamespace(.x, quietly = TRUE)) {
if (use_testthat) {
if (use_testthat && !requireNamespace(.x, quietly = TRUE)) {

Copy link
Contributor Author

@averissimo averissimo Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I misunderstanding or would we still need an else if after for the current else clause with your suggestion?

if (use_testthat && !requireNamespace(.x, quietly = TRUE)) {
  testthat::skip(sprintf("%s is not installed", .x))
} else if (!requireNamespace(.x, quietly = TRUE)) {
  stop("Please install '", .x, "' package to use this class.", call. = FALSE)
}

I dislike the repetition of the suggestion, maybe a tiny bit more than the nested if clause

Given it's a personal style, if you feel the suggestion is better I'll make the change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that we could remove the else from the current code to make it a bit leaner

      if (!requireNamespace(.x, quietly = TRUE)) {
        if (use_testthat) {
          testthat::skip(sprintf("%s is not installed", .x))
        }
        stop("Please install '", .x, "' package to use this class.", call. = FALSE)
      }

Second note: for a moment I considered the following, but the tryCatch would be too broad and from all the options I dislike this the most

if (!requireNamespace(.x, quietly = TRUE)) {
  tryCatch(
    testthat::skip(sprintf("%s is not installed", .x)),
    error = function(err) stop("Please install '", .x, "' package to use this class.", call. = FALSE)
  )
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking this code will be executed mostly by developers checking & testing the package, so that should be checked first as it can lead to speed improvements and code readability. I think t

I would expect developers to know they need to install a package if it cannot be loaded and a message reported this.
What do you think about this simplification?

      if (requireNamespace("testthat", quietly = TRUE) && testthat::is_testing() identical(Sys.getenv("RTESTS"), "true")) {
          lapply(c("shinytest2", "rvest"), testthat::skip_if_not_installed)
      }

The identical(Sys.getenv("RTESTS"), "true") is to ensure that when one does devtools::check it is triggered (but can be omitted).

I tested several snippets but I'm not happy with any regarding readability, perhaps it would be easier if we had a little helper/uril function to solve this that we can reuse across packages.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some needed context that I forgot to add to the original post. This chunk of code serves dual-purposes:

  1. On {teal} if the developer uses the class manually, but didn't install the *OPTIONAL* dependencies
  2. On {tmc}, {tmg}, and other (possibly), as TealAppDriver depends on {teal} Suggested packages to work, but cannot be added to DESCRIPTION to {tmc}, {tmg}, {...}
    • It doesn't make sense (and will trigger a CRAN) warning if we just add them to Suggest and not use it in the package itself

That's why we need skip and stop conditions. To be complete, I've also added testthat to that small list.

      if (requireNamespace("testthat", quietly = TRUE) && testthat::is_testing() identical(Sys.getenv("RTESTS"), "true")) {
          lapply(c("shinytest2", "rvest"), testthat::skip_if_not_installed)
      }

This suggestion will allow the creation of the class if we don't have {testthat} installed. Almost an impossibility, but it could happen.

Copy link
Contributor

@llrs-roche llrs-roche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code works well, but I am not sure about the readability (but I also don't think my proposal is easier to read)...

Comment on lines +14 to +15
if (!requireNamespace(.x, quietly = TRUE)) {
if (use_testthat) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking this code will be executed mostly by developers checking & testing the package, so that should be checked first as it can lead to speed improvements and code readability. I think t

I would expect developers to know they need to install a package if it cannot be loaded and a message reported this.
What do you think about this simplification?

      if (requireNamespace("testthat", quietly = TRUE) && testthat::is_testing() identical(Sys.getenv("RTESTS"), "true")) {
          lapply(c("shinytest2", "rvest"), testthat::skip_if_not_installed)
      }

The identical(Sys.getenv("RTESTS"), "true") is to ensure that when one does devtools::check it is triggered (but can be omitted).

I tested several snippets but I'm not happy with any regarding readability, perhaps it would be easier if we had a little helper/uril function to solve this that we can reuse across packages.

@llrs-roche llrs-roche self-assigned this Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants