diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 5641b54..229d206 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -46,7 +46,7 @@ jobs: - name: Install lamindb run: | - pip install lamindb[bionty] + pip install lamindb[bionty,wetlab] - name: Log in to Lamin run: | diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index 049f20e..4c94a26 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -44,7 +44,7 @@ jobs: - name: Install lamindb run: | - pip install lamindb[bionty] + pip install lamindb[bionty,wetlab] - name: Log in to Lamin run: | diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d714ef..1ca1960 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,8 @@ * Define a current user and current instance with lamin-cli prior to testing and generating documentation in the CI (PR #23). +* Add a simple unit test which queries laminlabs/lamindata (PR #27). + ## BUG FIXES * Fixed the parsing of the env files in `~/.lamin` due to changes in the lamindb-setup Python package (PR #12). diff --git a/DESCRIPTION b/DESCRIPTION index 2209960..309f304 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -26,5 +26,8 @@ Imports: Suggests: anndata, quarto, - s3 (>= 1.1.0) + s3 (>= 1.1.0), + testthat (>= 3.0.0), + withr VignetteBuilder: quarto +Config/testthat/edition: 3 diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 0000000..16b645d --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,12 @@ +# This file is part of the standard setup for testthat. +# It is recommended that you do not modify it. +# +# Where should you do additional test configuration? +# Learn more about the roles of various files in: +# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview +# * https://testthat.r-lib.org/articles/special-files.html + +library(testthat) +library(laminr) + +test_check("laminr") diff --git a/tests/testthat/helper-setup_lamindata_instance.R b/tests/testthat/helper-setup_lamindata_instance.R new file mode 100644 index 0000000..66bfb60 --- /dev/null +++ b/tests/testthat/helper-setup_lamindata_instance.R @@ -0,0 +1,42 @@ +local_setup_lamindata_instance <- function(env = parent.frame()) { + root_dir <- withr::local_file(tempfile(), .local_envir = env) + withr::local_envvar(c(LAMIN_SETTINGS_DIR = root_dir), .local_envir = env) + + # create a temporary directory for the settings + lamin_dir <- file.path(root_dir, ".lamin") + dir.create(lamin_dir, recursive = TRUE, showWarnings = FALSE) + + # generate user settings + user_settings <- list( + email = "null", + password = "null", + access_token = "null", + api_key = "null", + uid = "00000000", + uuid = "null", + handle = "anonymous", + name = "null" + ) + user_lines <- paste0("lamin_user_", names(user_settings), "=", unlist(user_settings)) + writeLines(user_lines, file.path(lamin_dir, "current_user.env")) + + # generate instance settings + instance_settings <- list( + owner = "laminlabs", + name = "lamindata", + api_url = "https://us-east-1.api.lamin.ai", + storage_root = "s3://lamindata", + storage_region = "us-east-1", + db = "null", + schema_str = "bionty,wetlab", + schema_id = "097186c3e91c01ced47aa3e01a3c1515", + id = "037ba1e08d804f91a90275a47735076a", + git_repo = "null", + keep_artifacts_local = "False" + ) + instance_lines <- paste0("lamindb_instance_", names(instance_settings), "=", unlist(instance_settings)) + writeLines(instance_lines, file.path(lamin_dir, "current_instance.env")) + writeLines(instance_lines, file.path(lamin_dir, "instance--laminlabs--lamindata.env")) + + root_dir +} diff --git a/tests/testthat/test-connect_lamindata.R b/tests/testthat/test-connect_lamindata.R new file mode 100644 index 0000000..e27bc47 --- /dev/null +++ b/tests/testthat/test-connect_lamindata.R @@ -0,0 +1,21 @@ +skip_if_offline() + +test_that("Connecting to lamindata works", { + local_setup_lamindata_instance() + + # try to connect to lamindata + db <- connect("laminlabs/lamindata") + + # check whether schema was parsed and classes were created + expect_equal(db$Artifact$name, "artifact") + + # try to fetch a record + artifact <- db$Artifact$get("mePviem4DGM4SFzvLXf3") + + expect_equal(artifact$uid, "mePviem4DGM4SFzvLXf3") + expect_equal(artifact$suffix, ".csv") + + # try to fetch linked records + created_by <- artifact$created_by + expect_equal(created_by$handle, "sunnyosun") +})