Skip to content

Commit

Permalink
increase code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bschilder committed Nov 1, 2023
1 parent 9bf2a17 commit 6081fd3
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 32 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export(get_description)
export(get_hex)
export(infer_biocviews)
export(infer_deps)
export(infer_docker_org)
export(is_gha)
export(use_badges)
export(use_codespace)
Expand Down
3 changes: 2 additions & 1 deletion R/check_registry.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
#'
#' @keywords internal
check_registry <- function(registry){
registry <- registry[1]

if(!is.null(registry)){
registry <- registry[1]
if(!grepl("/$",registry)){
registry <- paste0(registry,"/")
}
Expand Down
28 changes: 14 additions & 14 deletions R/conda_installed.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
conda_installed <- function(verbose = FALSE){
if(is_gha()){
if(Sys.getenv("CONDA")!=""){
messager("Using CONDA=",Sys.getenv("CONDA"), v=verbose)
return(TRUE)
} else if(Sys.getenv("CONDA_EXE")!=""){
messager("Using CONDA_EXE=",Sys.getenv("CONDA_EXE"), v=verbose)
return(TRUE)
} else {
messager("CONDA not found.", v=verbose)
return(FALSE)
}
# reticulate::use_miniconda(conda=Sys.getenv("CONDA_EXE"))
} else {
# if(is_gha()){
# if(Sys.getenv("CONDA")!=""){
# messager("Using CONDA=",Sys.getenv("CONDA"), v=verbose)
# return(TRUE)
# } else if(Sys.getenv("CONDA_EXE")!=""){
# messager("Using CONDA_EXE=",Sys.getenv("CONDA_EXE"), v=verbose)
# return(TRUE)
# } else {
# messager("CONDA not found.", v=verbose)
# return(FALSE)
# }
# # reticulate::use_miniconda(conda=Sys.getenv("CONDA_EXE"))
# } else {
requireNamespace("reticulate")
utils::getFromNamespace("conda_installed","reticulate")()
}
# }
}
2 changes: 1 addition & 1 deletion R/infer_deps.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#' @importFrom renv dependencies
#' @examples
#' #### Get example DESCRIPTION file ####
#' url <- "https://github.com/neurogenomics/templateR/raw/master/DESCRIPTION"
#' url <- "https://github.com/neurogenomics/templateR/raw/master/DESCRIPTION"
#' path <- tempfile(fileext = "DESCRIPTION")
#' utils::download.file(url,path)
#'
Expand Down
19 changes: 16 additions & 3 deletions R/infer_docker_org.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
infer_docker_org <- function(docker_org,
#' Infer Docker registry organisation name
#'
#' Infer Docker registry organisation name from DESCRIPTION file.
#' @inheritParams use_vignette_docker
#' @inheritParams use_workflow
#' @inheritDotParams get_description
#' @returns Docker registry organisation name.
#'
#' @export
#' @examples
#' infer_docker_org(docker_org="myorg", docker_registry="ghcr.io")
infer_docker_org <- function(docker_org=NULL,
docker_registry,
verbose=TRUE){
verbose=TRUE,
...){
if(!is.null(docker_org)){
return(docker_org)
} else if(is.null(docker_org) &&
grepl("ghcr.io",docker_registry)){
## Infer docker_org from DESCRIPTION
desc_file <- get_description(verbose = verbose)
desc_file <- get_description(verbose = verbose,
...)
gh_url <- get_github_url_desc(desc_file = desc_file[[1]])
if(!is.null(gh_url)){
docker_org <- rev(strsplit(gh_url,"/")[[1]])[2]
Expand Down
2 changes: 1 addition & 1 deletion man/infer_deps.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions man/infer_docker_org.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion tests/testthat/test-construct_cont.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@ test_that("construct_cont works", {
testthat::expect_null(cont3[[2]])
testthat::expect_null(cont3[[3]])

cont4 <- construct_cont(default_tag = "release",
cont4 <- construct_cont(default_tag = "release",
default_registry = "ghcr.io",
run_check_cont = TRUE)
testthat::expect_equal(cont4[[1]], paste0(default_registry,"bioconductor/bioconductor_docker:latest"))
testthat::expect_null(cont4[[2]])
testthat::expect_null(cont4[[3]])


cont5 <- construct_cont(default_registry = NULL)
testthat::expect_equal(cont5[[1]],"bioconductor/bioconductor_docker:devel")
testthat::expect_null(cont5[[2]])
testthat::expect_null(cont5[[3]])
})
20 changes: 15 additions & 5 deletions tests/testthat/test-infer_docker_org.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
test_that("infer_docker_org works", {

testthat::expect_error(
infer_docker_org(docker_org = NULL,
docker_registry = "docker.io")
)

## User-given
docker_org <- "neurogenomicslab"
out <- infer_docker_org(docker_org = docker_org,
docker_registry = "docker.io")
testthat::expect_equal(out,docker_org)

## Infer from GH info in DESCRIPTION
d <- desc::desc(package = "yaml")
out <- infer_docker_org(docker_org = NULL,
docker_registry = "ghcr.io",
paths=d)
testthat::expect_equal(out,"vubiostat")

## Unable to infer for DockerHub
testthat::expect_error(
infer_docker_org(docker_org = NULL,
docker_registry = "docker.io")
)

})
20 changes: 14 additions & 6 deletions tests/testthat/test-use_codespace.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
test_that("use_codespace works", {

path <- use_codespace(save_dir=tempdir())
testthat::expect_true(file.exists(path))
run_tests <- function(path){
testthat::expect_true(file.exists(path))
jsn <- jsonlite::read_json(path)
testthat::expect_true(
all(c("image","features","customizations") %in% names(jsn))
)
}
save_dir <- tempdir()
## First time
path <- use_codespace(save_dir=save_dir)
run_tests(path)

jsn <- jsonlite::read_json(path)
testthat::expect_true(
all(c("image","features","customizations") %in% names(jsn))
)
## Second time
path2 <- use_codespace(save_dir=save_dir, show=TRUE)
run_tests(path2)
})

0 comments on commit 6081fd3

Please sign in to comment.