Skip to content

Commit

Permalink
tests: skip umamba dependent tests when offline
Browse files Browse the repository at this point in the history
  • Loading branch information
luciorq committed Dec 5, 2024
1 parent 462658f commit a362b0f
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 15 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: condathis
Title: Run Any CLI Tool on a Conda Environment
Version: 0.0.7.9005
Version: 0.0.7.9006
Authors@R: c(
person("Lucio", "Queiroz", , "luciorqueiroz@gmail.com", role = c("aut", "cre", "cph"),
comment = c(ORCID = "0000-0002-6090-1834")),
Expand Down
7 changes: 6 additions & 1 deletion tests/testthat/setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,10 @@ withr::local_envvar(
`APPDATA` = fs::path_temp("tmp", "home", "data"),
`R_USER_DATA_DIR` = fs::path_temp("tmp", "home", "data"),
`XDG_DATA_HOME` = fs::path_temp("tmp", "home", "data")
)
),
.local_envir = testthat::teardown_env()
)
if (isFALSE(fs::dir_exists(fs::path_temp("tmp", "home")))) {
fs::dir_create(fs::path_temp("tmp", "home"))
}

2 changes: 1 addition & 1 deletion tests/testthat/test-check_connection.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
test_that("GitHub is reachable", {
testthat::skip_if_offline()
testthat::skip_on_ci()
testthat::skip_on_cran()
testthat::skip_on_ci()

github_url <- "https://github.com"
con_res <- check_connection(url_to_check = github_url)
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-create_base_env.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
testthat::test_that("Create base env", {
testthat::skip_if_offline()
testthat::skip_on_cran()

if (fs::dir_exists(fs::path(get_install_dir(), "envs", "condathis-env"))) {
fs::dir_delete(fs::path(get_install_dir(), "envs", "condathis-env"))
}
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-create_env.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ testthat::test_that("create_env invalid method arg", {
})

testthat::test_that("conda env is created", {
testthat::skip_if_offline()
testthat::skip_on_cran()

px_res <- create_env(
Expand Down Expand Up @@ -144,6 +145,7 @@ testthat::test_that("conda env is created", {
})

testthat::test_that("Create conda env from file", {
testthat::skip_if_offline()
testthat::skip_on_cran()

px_res <- create_env(
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-create_nested_env.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
test_that("create nested environment", {
testthat::skip_if_offline()
testthat::skip_on_cran()

create_res <- create_env(
packages = NULL,
env_name = "test-nested-env",
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-env_exists.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
test_that("env_exists missing env_name", {
testthat::skip_if_offline()
testthat::skip_on_cran()

expect_error(env_exists())
expect_equal(env_exists(NULL), FALSE)
expect_equal(env_exists(NA), FALSE)
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-install_micromamba.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
test_that("Micromamba installation", {
testthat::skip_if_offline()
testthat::skip_on_cran()
withr::local_path(new = list(), action = "replace")
umamba_bin_path <- install_micromamba(force = FALSE)
testthat::expect_true(fs::file_exists(umamba_bin_path))
})

test_that("Micromamba already installed", {
testthat::skip_if_offline()
testthat::skip_on_cran()
testthat::expect_message(
object = {
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-is_micromamba_available_for_arch.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# tests/testthat/test-is_micromamba_available_for_arch.R
library(testthat)

test_that("is_micromamba_available_for_arch handles custom sys_arch input correctly", {
# Test case for Linux-x86_64
expect_equal(is_micromamba_available_for_arch("Linux-x86_64"), "linux-64")
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-list_packages.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
test_that("list packages on absent environment", {
testthat::skip_if_offline()
testthat::skip_on_cran()

testthat::expect_error(
object = {
list_packages(env_name = "non-existing-env")
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-native_cmd.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
test_that("Native run conda command", {
testthat::skip_if_offline()
testthat::skip_on_cran()

px_res <- native_cmd("--help", verbose = FALSE)
expect_equal(
object = px_res$status,
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-parse_strategy_verbose.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@ testthat::test_that("Parse verbose strategy", {
parse_strategy_verbose("TRUE"),
class = "condathis_error_invalid_verbose"
)


testthat::expect_equal(parse_strategy_verbose(strategy = c("silent", " full")), list(cmd = FALSE, output = FALSE))
})
19 changes: 11 additions & 8 deletions tests/testthat/test-run_output_file.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
library(testthat)

create_env(env_name = "condathis-test-env", verbose = FALSE)
# create_env(env_name = "condathis-test-env", verbose = FALSE)

test_that("Output redirection to file", {
testthat::skip_if_offline()
testthat::skip_on_cran()

create_env(env_name = "condathis-test-env", verbose = "silent")
temp_output_file <- fs::file_temp("test_output", ext = "txt")
px_res <- run(
Expand All @@ -23,9 +24,9 @@ test_that("Output redirection to file", {
NULL
)
fs::file_delete(temp_output_file)
})
# })

test_that("Internal output", {
# test_that("Internal output", {
px_res <- run(
"echo", "Hello World!",
env_name = "condathis-test-env",
Expand All @@ -39,9 +40,9 @@ test_that("Internal output", {
testthat::expect_true(
object = stringr::str_detect(px_res$stdout, "Hello World!"),
)
})
# })

test_that("Error/warning redirection to file", {
# test_that("Error/warning redirection to file", {
temp_output_file <- fs::file_temp("test_stderr", ext = "txt")
px_res <- run(
"ls", "-lah", "MissingFILE",
Expand All @@ -61,7 +62,9 @@ test_that("Error/warning redirection to file", {
NULL
)
fs::file_delete(temp_output_file)
remove_env(env_name = "condathis-test-env", verbose = FALSE)
})

# remove_env(env_name = "condathis-test-env", verbose = FALSE)


remove_env(env_name = "condathis-test-env", verbose = FALSE)

0 comments on commit a362b0f

Please sign in to comment.