-
Notifications
You must be signed in to change notification settings - Fork 0
test: create tests #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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,29 @@ | ||
| name: tests | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ main, dev ] | ||
| pull_request: | ||
| branches: [ main, dev ] | ||
|
|
||
| jobs: | ||
| tests: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
|
|
||
| - 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
Binary file not shown.
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(file.path('tests', 'testthat'), stop_on_failure = 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,146 @@ | ||
| test_that("code/run executes successfully with default CLI arguments", { | ||
| # Create temporary workspace | ||
| workspace <- tempfile("mosuite_diff_counts_test_") | ||
| dir.create(workspace) | ||
| on.exit(unlink(workspace, recursive = TRUE), add = TRUE) | ||
|
|
||
| # Set up directory structure | ||
| code_dir <- file.path(workspace, "code") | ||
| data_dir <- file.path(workspace, "data") | ||
| results_dir <- file.path(code_dir, "..", "results") | ||
| dir.create(code_dir) | ||
| dir.create(data_dir) | ||
| dir.create(results_dir) | ||
|
|
||
| # Get test data from package tests directory | ||
| repo_root <- normalizePath(file.path(dirname(getwd()), "..")) | ||
| test_data_file <- file.path(repo_root, "tests", "data", "moo-filt.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")) | ||
|
|
||
| # Copy main.R and run script to workspace | ||
| file.copy( | ||
| file.path(repo_root, "code", "main.R"), | ||
| file.path(code_dir, "main.R") | ||
| ) | ||
| file.copy( | ||
| file.path(repo_root, "code", "run"), | ||
| file.path(code_dir, "run") | ||
| ) | ||
|
|
||
| # Run the script from code directory | ||
| old_wd <- getwd() | ||
| setwd(code_dir) | ||
| on.exit(setwd(old_wd), add = TRUE) | ||
|
|
||
| # Execute run script with default CLI arguments | ||
| exit_code <- system2( | ||
| "bash", | ||
| args = c( | ||
| "run", | ||
| "--covariates_colnames=Group", | ||
| "--contrast_colname=Group", | ||
| "--contrasts=B-A" | ||
| ) | ||
| ) | ||
|
|
||
| # Check for successful execution | ||
| expect_equal(exit_code, 0, info = "run script should execute without error") | ||
| expect_true( | ||
| file.exists(file.path(results_dir, "moo", "moo-diff.rds")), | ||
| info = "Output file moo-diff.rds should be created" | ||
| ) | ||
|
|
||
| # Validate output is a valid MOO object | ||
| moo <- readr::read_rds(file.path(results_dir, "moo", "moo-diff.rds")) | ||
| expect_true( | ||
| S7::S7_inherits(moo, MOSuite::multiOmicDataSet), | ||
| info = "Output should be an S7 multiOmicDataSet object" | ||
| ) | ||
|
|
||
| # Validate diff results exist | ||
| expect_true( | ||
| "diff" %in% names(moo@analyses), | ||
| info = "Output should have diff results in moo@analyses" | ||
| ) | ||
| }) | ||
|
|
||
| test_that("code/run executes with custom CLI arguments", { | ||
| # Create temporary workspace | ||
| workspace <- tempfile("mosuite_diff_counts_custom_test_") | ||
| dir.create(workspace) | ||
| on.exit(unlink(workspace, recursive = TRUE), add = TRUE) | ||
|
|
||
| # Set up directory structure | ||
| code_dir <- file.path(workspace, "code") | ||
| data_dir <- file.path(workspace, "data") | ||
| results_dir <- file.path(code_dir, "..", "results") | ||
| dir.create(code_dir) | ||
| dir.create(data_dir) | ||
| dir.create(results_dir) | ||
|
|
||
| # Get test data from package tests directory | ||
| repo_root <- normalizePath(file.path(dirname(getwd()), "..")) | ||
| test_data_file <- file.path(repo_root, "tests", "data", "moo-filt.rds") | ||
|
|
||
| # Copy test data to workspace | ||
| file.copy(test_data_file, file.path(data_dir, "moo.rds")) | ||
|
|
||
| # Copy main.R and run script to workspace | ||
| file.copy( | ||
| file.path(repo_root, "code", "main.R"), | ||
| file.path(code_dir, "main.R") | ||
| ) | ||
| file.copy( | ||
| file.path(repo_root, "code", "run"), | ||
| file.path(code_dir, "run") | ||
| ) | ||
|
|
||
| # Run the script from code directory | ||
| old_wd <- getwd() | ||
| setwd(code_dir) | ||
| on.exit(setwd(old_wd), add = TRUE) | ||
|
|
||
| # Execute run script with custom CLI arguments | ||
| exit_code <- system2( | ||
| "bash", | ||
| args = c( | ||
| "run", | ||
| "--count_type=filt", | ||
| "--covariates_colnames=Group", | ||
| "--contrast_colname=Group", | ||
| "--contrasts=C-A", | ||
| "--input_in_log_counts=FALSE", | ||
| "--return_mean_and_sd=TRUE", | ||
| "--voom_normalization_method=quantile" | ||
| ) | ||
| ) | ||
|
|
||
| # Check for successful execution | ||
| expect_equal( | ||
| exit_code, | ||
| 0, | ||
| info = "run script with custom args should execute without error" | ||
| ) | ||
| expect_true( | ||
| file.exists(file.path(results_dir, "moo", "moo-diff.rds")), | ||
| info = "Output file moo-diff.rds should be created with custom args" | ||
| ) | ||
|
|
||
| # Validate output is a valid MOO object | ||
| moo <- readr::read_rds(file.path(results_dir, "moo", "moo-diff.rds")) | ||
| expect_true( | ||
| S7::S7_inherits(moo, MOSuite::multiOmicDataSet), | ||
| info = "Output should be an S7 multiOmicDataSet object" | ||
| ) | ||
|
|
||
| # Validate diff results exist | ||
| expect_true( | ||
| "diff" %in% names(moo@analyses), | ||
| info = "Output should have diff results in moo@analyses" | ||
| ) | ||
| }) |
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.
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium test