Skip to content

Commit f9f9d81

Browse files
committed
updating troublesome unit tests
1 parent 2d2e6f8 commit f9f9d81

5 files changed

Lines changed: 48 additions & 14 deletions

File tree

.github/workflows/R-CMD-check.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ jobs:
6161
), "configure")
6262
Sys.chmod("configure", mode = "0755")
6363
writeLines(c(
64-
'@echo off',
65-
'"%R_HOME%/bin/Rscript" -e "basilisk::configureBasiliskEnv()"'
64+
'#!/bin/sh',
65+
'"${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "basilisk::configureBasiliskEnv()"'
6666
), "configure.win")
6767
shell: Rscript {0}
6868

tests/testthat/helper-immLynx.R

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,37 @@ skip_if_no_python <- function() {
6868
skip_if_no_transformers <- function() {
6969
skip_if_no_python()
7070
}
71+
72+
# Cache for module import checks (avoids repeated basiliskRun calls)
73+
.module_check_cache <- new.env(parent = emptyenv())
74+
75+
# Check if a Python module can actually be imported (catches shared lib issues)
76+
can_import_module <- function(module_name) {
77+
if (!is.null(.module_check_cache[[module_name]])) {
78+
return(.module_check_cache[[module_name]])
79+
}
80+
result <- tryCatch({
81+
basilisk::basiliskRun(env = immLynx:::immLynxEnv, fun = function(mod) {
82+
reticulate::import(mod)
83+
TRUE
84+
}, mod = module_name)
85+
}, error = function(e) FALSE)
86+
.module_check_cache[[module_name]] <- result
87+
result
88+
}
89+
90+
# Skip if tcrdist (parasail shared library) can't be loaded
91+
skip_if_no_tcrdist <- function() {
92+
skip_if_no_python()
93+
if (!can_import_module("tcrdist.repertoire")) {
94+
testthat::skip("tcrdist/parasail shared library not loadable")
95+
}
96+
}
97+
98+
# Skip if metaclonotypist can't be loaded
99+
skip_if_no_metaclonotypist <- function() {
100+
skip_if_no_python()
101+
if (!can_import_module("metaclonotypist")) {
102+
testthat::skip("metaclonotypist shared library not loadable")
103+
}
104+
}

tests/testthat/test-calculate_helpers.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ test_that("calculate.tcrDist function has correct default parameters", {
131131
})
132132

133133
test_that("calculate.tcrDist returns distance results for beta chain", {
134-
skip_if_no_python()
134+
skip_if_no_tcrdist()
135135

136136
df <- data.frame(
137137
count = rep(1L, 5),

tests/testthat/test-runMetaclonotypist.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ test_that("runMetaclonotypist rejects data.frame with all NA sequences", {
9696
test_that("runMetaclonotypist adds metaclone column to Seurat object", {
9797
skip_if_not_installed("Seurat")
9898
skip_if_not_installed("immApex")
99-
skip_if_no_python()
99+
skip_if_no_metaclonotypist()
100100

101101
data("immLynx_example", package = "immLynx")
102102

@@ -110,7 +110,7 @@ test_that("runMetaclonotypist adds metaclone column to Seurat object", {
110110
test_that("runMetaclonotypist returns data.frame when return_seurat=FALSE", {
111111
skip_if_not_installed("Seurat")
112112
skip_if_not_installed("immApex")
113-
skip_if_no_python()
113+
skip_if_no_metaclonotypist()
114114

115115
data("immLynx_example", package = "immLynx")
116116

@@ -127,7 +127,7 @@ test_that("runMetaclonotypist returns data.frame when return_seurat=FALSE", {
127127
test_that("runMetaclonotypist handles custom column name", {
128128
skip_if_not_installed("Seurat")
129129
skip_if_not_installed("immApex")
130-
skip_if_no_python()
130+
skip_if_no_metaclonotypist()
131131

132132
data("immLynx_example", package = "immLynx")
133133

@@ -139,7 +139,7 @@ test_that("runMetaclonotypist handles custom column name", {
139139
})
140140

141141
test_that("runMetaclonotypist accepts data.frame input", {
142-
skip_if_no_python()
142+
skip_if_no_metaclonotypist()
143143
skip("metaclonotypist Python library IndexError with small datasets")
144144

145145
tcr_data <- data.frame(
@@ -159,7 +159,7 @@ test_that("runMetaclonotypist accepts data.frame input", {
159159
test_that("runMetaclonotypist produces messages during execution", {
160160
skip_if_not_installed("Seurat")
161161
skip_if_not_installed("immApex")
162-
skip_if_no_python()
162+
skip_if_no_metaclonotypist()
163163

164164
data("immLynx_example", package = "immLynx")
165165

tests/testthat/test-runTCRdist.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ test_that("runTCRdist .add_allele handles vector input", {
9999
test_that("runTCRdist returns correct structure", {
100100
skip_if_not_installed("Seurat")
101101
skip_if_not_installed("immApex")
102-
skip_if_no_python()
102+
skip_if_no_tcrdist()
103103

104104
data("immLynx_example", package = "immLynx")
105105

@@ -114,7 +114,7 @@ test_that("runTCRdist returns correct structure", {
114114
test_that("runTCRdist returns distance matrix of correct dimensions", {
115115
skip_if_not_installed("Seurat")
116116
skip_if_not_installed("immApex")
117-
skip_if_no_python()
117+
skip_if_no_tcrdist()
118118

119119
data("immLynx_example", package = "immLynx")
120120

@@ -128,7 +128,7 @@ test_that("runTCRdist returns distance matrix of correct dimensions", {
128128
test_that("runTCRdist handles add_to_object parameter for Seurat", {
129129
skip_if_not_installed("Seurat")
130130
skip_if_not_installed("immApex")
131-
skip_if_no_python()
131+
skip_if_no_tcrdist()
132132

133133
data("immLynx_example", package = "immLynx")
134134

@@ -142,7 +142,7 @@ test_that("runTCRdist handles add_to_object parameter for Seurat", {
142142
test_that("runTCRdist handles both chains", {
143143
skip_if_not_installed("Seurat")
144144
skip_if_not_installed("immApex")
145-
skip_if_no_python()
145+
skip_if_no_tcrdist()
146146

147147
data("immLynx_example", package = "immLynx")
148148

@@ -155,7 +155,7 @@ test_that("runTCRdist handles both chains", {
155155
test_that("runTCRdist tcr_data has correct format", {
156156
skip_if_not_installed("Seurat")
157157
skip_if_not_installed("immApex")
158-
skip_if_no_python()
158+
skip_if_no_tcrdist()
159159

160160
data("immLynx_example", package = "immLynx")
161161

@@ -174,7 +174,7 @@ test_that("runTCRdist tcr_data has correct format", {
174174
test_that("runTCRdist produces messages during execution", {
175175
skip_if_not_installed("Seurat")
176176
skip_if_not_installed("immApex")
177-
skip_if_no_python()
177+
skip_if_no_tcrdist()
178178

179179
data("immLynx_example", package = "immLynx")
180180

0 commit comments

Comments
 (0)