Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/tests.yml
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@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

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium test

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
35 changes: 35 additions & 0 deletions tests/test-setup.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env Rscript

cat("Testing basic test setup...\n")

cwd <- getwd()
cat("Current directory:", cwd, "\n")

repo_root_script <- normalizePath(dirname(cwd))
cat("Calculated repo_root:", repo_root_script, "\n")

fixture_file <- file.path(
repo_root_script,
"..",
"code",
"MOSuite",
"tests",
"testthat",
"data",
"moo.rds"
)
cat("\nLooking for fixture data at:", fixture_file, "\n")
cat("Fixture data exists:", file.exists(fixture_file), "\n")

code_main <- file.path(repo_root_script, "..", "code", "main.R")
code_run <- file.path(repo_root_script, "..", "code", "run")
cat("code/main.R exists:", file.exists(code_main), "\n")
cat("code/run exists:", file.exists(code_run), "\n")

if (file.exists(fixture_file)) {
cat("\nTrying to load fixture MOO object...\n")
library(readr)
moo <- readr::read_rds(fixture_file)
cat("Fixture MOO loaded successfully!\n")
cat("MOO class:", class(moo), "\n")
}
Comment thread
kelly-sovacool marked this conversation as resolved.
Outdated
2 changes: 2 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
library(testthat)
test_dir(here::here('tests/testthat/'))
Comment thread
kelly-sovacool marked this conversation as resolved.
75 changes: 75 additions & 0 deletions tests/testthat/helper-cli.R
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"
)
33 changes: 33 additions & 0 deletions tests/testthat/test-main.R
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)
})
Loading