-
Notifications
You must be signed in to change notification settings - Fork 0
test: add basic tests for run & main.R
#3
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ab915c4
Squashed 'code/MOSuite/' content from commit c09ee39
kelly-sovacool e4b8775
Merge commit 'ab915c41b469557433e9325ca936213692f2b3ad' as 'code/MOSu…
kelly-sovacool e049aaa
style: air
kelly-sovacool c11ae4b
refactor: load local MOSuite
kelly-sovacool 832a009
refactor: switch to minimal docker container
kelly-sovacool bfac01d
fix: absolute path to MOSuite code
kelly-sovacool 7979afb
`air format` (GitHub Actions)
github-actions[bot] dd1bfdb
ci: remove test workflow
kelly-sovacool 7aba3a8
chore: Merge branch 'auto-sync-subtree' of github.com:NIDAP-Community…
kelly-sovacool 96ff4b0
chore: update CHANGELOG.md
kelly-sovacool f6b78f7
chore: vendor MOSuite pkg
kelly-sovacool d8a8317
chore: update CHANGELOG.md
kelly-sovacool 4e5b0f9
ci: add basic tests for main.R
kelly-sovacool 31342bf
Merge branch 'main' into tests
kelly-sovacool c4df0c9
ci: set permissions to contents: read
kelly-sovacool a8f7647
docs: add tests badge
kelly-sovacool fac1c2a
test: fix setup fixture tests
kelly-sovacool File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| name: tests | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main, dev] | ||
| pull_request: | ||
| branches: [main, dev] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| tests: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
|
|
||
| - name: Parse environment.json and set Docker image | ||
| id: docker_image | ||
| run: | | ||
| IMAGE=$(jq -r '.base_image' .codeocean/environment.json) | ||
| IMAGE=${IMAGE//codeocean/nciccbr} | ||
| echo "image=$IMAGE" >> $GITHUB_OUTPUT | ||
| echo "Using Docker image: $IMAGE" | ||
|
|
||
| - name: Run tests in Docker | ||
| run: | | ||
| docker run --rm \ | ||
| -v ${{ github.workspace }}:/workspace \ | ||
| -w /workspace \ | ||
| ${{ steps.docker_image.outputs.image }} \ | ||
| Rscript tests/testthat.R | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| testthat::test_that("basic test setup is valid", { | ||
| cwd <- getwd() | ||
| repo_root_script <- normalizePath(dirname(cwd)) | ||
|
|
||
| fixture_file <- file.path( | ||
| repo_root_script, | ||
| "..", | ||
| "code", | ||
| "MOSuite", | ||
| "tests", | ||
| "testthat", | ||
| "data", | ||
| "moo.rds" | ||
| ) | ||
|
|
||
| code_main <- file.path(repo_root_script, "..", "code", "main.R") | ||
| code_run <- file.path(repo_root_script, "..", "code", "run") | ||
|
|
||
| testthat::expect_true(file.exists(fixture_file)) | ||
| testthat::expect_true(file.exists(code_main)) | ||
| testthat::expect_true(file.exists(code_run)) | ||
|
|
||
| testthat::skip_if_not_installed("readr") | ||
| testthat::expect_no_error({ | ||
| moo <- readr::read_rds(fixture_file) | ||
| testthat::expect_gt(length(class(moo)), 0) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| library(testthat) | ||
| test_dir(here::here('tests/testthat/')) | ||
|
kelly-sovacool marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| setup_cli_workspace <- function(prefix = "mosuite_plot_expr_heatmap_test_") { | ||
| workspace <- tempfile(prefix) | ||
| dir.create(workspace) | ||
|
|
||
| code_dir <- file.path(workspace, "code") | ||
| data_dir <- file.path(workspace, "data") | ||
| results_dir <- file.path(workspace, "results") | ||
| dir.create(code_dir, recursive = TRUE) | ||
| dir.create(data_dir, recursive = TRUE) | ||
| dir.create(file.path(results_dir, "figures"), recursive = TRUE) | ||
| dir.create(file.path(results_dir, "moo"), recursive = TRUE) | ||
|
|
||
| repo_root <- normalizePath( | ||
| file.path(testthat::test_path(), "..", ".."), | ||
| mustWork = TRUE | ||
| ) | ||
|
|
||
| test_data_file <- file.path( | ||
| repo_root, | ||
| "code", | ||
| "MOSuite", | ||
| "tests", | ||
| "testthat", | ||
| "data", | ||
| "moo.rds" | ||
| ) | ||
|
|
||
| expect_true( | ||
| file.exists(test_data_file), | ||
| info = paste("Test data file should exist at", test_data_file) | ||
| ) | ||
| file.copy(test_data_file, file.path(data_dir, "moo.rds"), overwrite = TRUE) | ||
|
|
||
| file.copy( | ||
| file.path(repo_root, "code", "main.R"), | ||
| file.path(code_dir, "main.R"), | ||
| overwrite = TRUE | ||
| ) | ||
|
|
||
| # Keep main.R behavior the same while pointing to this checkout's MOSuite package. | ||
| main_copy <- file.path(code_dir, "main.R") | ||
| main_lines <- readLines(main_copy) | ||
| main_lines <- gsub( | ||
| 'devtools::load_all("/code/MOSuite")', | ||
| sprintf( | ||
| 'devtools::load_all("%s")', | ||
| file.path(repo_root, "code", "MOSuite") | ||
| ), | ||
| main_lines, | ||
| fixed = TRUE | ||
| ) | ||
| writeLines(main_lines, main_copy) | ||
|
|
||
| list( | ||
| workspace = workspace, | ||
| code_dir = code_dir, | ||
| results_dir = results_dir, | ||
| repo_root = repo_root | ||
| ) | ||
| } | ||
|
|
||
| expect_plot_created <- function(results_dir) { | ||
| plot_path <- file.path(results_dir, "figures", "heatmap", "expr_heatmap.png") | ||
| expect_true(file.exists(plot_path), info = "Heatmap plot should be created") | ||
| expect_true( | ||
| file.info(plot_path)$size > 0, | ||
| info = "Heatmap plot should be non-empty" | ||
| ) | ||
| } | ||
|
|
||
| common_cli_args <- c( | ||
| "--count_type=clean", | ||
| "--display_gene_names=FALSE", | ||
| "--display_sample_names=TRUE" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| test_that("main.R CLI creates expression heatmap plot", { | ||
| setup <- setup_cli_workspace("mosuite_plot_expr_heatmap_test_") | ||
| on.exit(unlink(setup$workspace, recursive = TRUE), add = TRUE) | ||
|
|
||
| old_wd <- getwd() | ||
| setwd(setup$code_dir) | ||
| on.exit(setwd(old_wd), add = TRUE) | ||
|
|
||
| exit_code <- system2("Rscript", args = c("main.R", common_cli_args)) | ||
| expect_equal(exit_code, 0, info = "main.R should execute without error") | ||
|
|
||
| expect_plot_created(setup$results_dir) | ||
| }) | ||
|
|
||
| test_that("run wrapper executes and creates expression heatmap plot", { | ||
| setup <- setup_cli_workspace("mosuite_plot_expr_heatmap_run_test_") | ||
| on.exit(unlink(setup$workspace, recursive = TRUE), add = TRUE) | ||
|
|
||
| file.copy( | ||
| file.path(setup$repo_root, "code", "run"), | ||
| file.path(setup$code_dir, "run"), | ||
| overwrite = TRUE | ||
| ) | ||
|
|
||
| old_wd <- getwd() | ||
| setwd(setup$code_dir) | ||
| on.exit(setwd(old_wd), add = TRUE) | ||
|
|
||
| exit_code <- system2("bash", args = c("run", common_cli_args)) | ||
| expect_equal(exit_code, 0, info = "run script should execute without error") | ||
|
|
||
| expect_plot_created(setup$results_dir) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.