From 6d925d6ea144cc45c849abbadccffd74393e9946 Mon Sep 17 00:00:00 2001 From: Robrecht Cannoodt Date: Thu, 10 Oct 2024 15:08:27 +0200 Subject: [PATCH 1/5] Add a simple unit test which queries laminlabs/lamindata --- .github/workflows/R-CMD-check.yaml | 2 +- .github/workflows/pkgdown.yaml | 2 +- CHANGELOG.md | 2 + DESCRIPTION | 4 +- tests/testthat.R | 12 +++++ tests/testthat/test-connect_lamindata.R | 58 +++++++++++++++++++++++++ 6 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 tests/testthat.R create mode 100644 tests/testthat/test-connect_lamindata.R 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 05ed44c..6c037a9 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..caabc7d 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 #xx). + ## 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..2d19413 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -26,5 +26,7 @@ Imports: Suggests: anndata, quarto, - s3 (>= 1.1.0) + s3 (>= 1.1.0), + testthat (>= 3.0.0) 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/test-connect_lamindata.R b/tests/testthat/test-connect_lamindata.R new file mode 100644 index 0000000..a20d9c0 --- /dev/null +++ b/tests/testthat/test-connect_lamindata.R @@ -0,0 +1,58 @@ +test_that("Connecting to lamindata works", { + temp_lamin_dir <- tempfile() + temp_lamin_dir2 <- file.path(temp_lamin_dir, ".lamin") + dir.create(temp_lamin_dir2, recursive = TRUE, showWarnings = FALSE) + Sys.setenv(LAMIN_SETTINGS_DIR = temp_lamin_dir) + on.exit({ + unlink(temp_lamin_dir, recursive = TRUE) + Sys.unsetenv("LAMIN_SETTINGS_DIR") + }) + + # 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(temp_lamin_dir2, "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(temp_lamin_dir2, "current_instance.env")) + writeLines(instance_lines, file.path(temp_lamin_dir2, "instance--laminlabs--lamindata.env")) + + # 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") +}) From b28a945050813006bbd5b8676b76d2f4505fa1c7 Mon Sep 17 00:00:00 2001 From: Robrecht Cannoodt Date: Thu, 10 Oct 2024 15:08:51 +0200 Subject: [PATCH 2/5] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index caabc7d..1ca1960 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,7 +35,7 @@ * 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 #xx). +* Add a simple unit test which queries laminlabs/lamindata (PR #27). ## BUG FIXES From 7b865d80402ab88ea361516d8af74eb476ff73d4 Mon Sep 17 00:00:00 2001 From: Robrecht Cannoodt Date: Thu, 10 Oct 2024 19:26:31 +0200 Subject: [PATCH 3/5] Add `skip_if_offline` --- tests/testthat/test-connect_lamindata.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/testthat/test-connect_lamindata.R b/tests/testthat/test-connect_lamindata.R index a20d9c0..9079967 100644 --- a/tests/testthat/test-connect_lamindata.R +++ b/tests/testthat/test-connect_lamindata.R @@ -1,3 +1,5 @@ +skip_if_offline() + test_that("Connecting to lamindata works", { temp_lamin_dir <- tempfile() temp_lamin_dir2 <- file.path(temp_lamin_dir, ".lamin") From f214c6354611f1c7082e06b3810508f379ee451a Mon Sep 17 00:00:00 2001 From: Robrecht Cannoodt Date: Thu, 10 Oct 2024 19:44:31 +0200 Subject: [PATCH 4/5] use text figures --- DESCRIPTION | 3 +- .../helper-setup_lamindata_instance.R | 42 +++++++++++++++++++ tests/testthat/test-connect_lamindata.R | 41 +----------------- 3 files changed, 45 insertions(+), 41 deletions(-) create mode 100644 tests/testthat/helper-setup_lamindata_instance.R diff --git a/DESCRIPTION b/DESCRIPTION index 2d19413..309f304 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,6 +27,7 @@ Suggests: anndata, quarto, s3 (>= 1.1.0), - testthat (>= 3.0.0) + testthat (>= 3.0.0), + withr VignetteBuilder: quarto Config/testthat/edition: 3 diff --git a/tests/testthat/helper-setup_lamindata_instance.R b/tests/testthat/helper-setup_lamindata_instance.R new file mode 100644 index 0000000..3c67fe4 --- /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 +} \ No newline at end of file diff --git a/tests/testthat/test-connect_lamindata.R b/tests/testthat/test-connect_lamindata.R index a20d9c0..d9a25d2 100644 --- a/tests/testthat/test-connect_lamindata.R +++ b/tests/testthat/test-connect_lamindata.R @@ -1,44 +1,5 @@ test_that("Connecting to lamindata works", { - temp_lamin_dir <- tempfile() - temp_lamin_dir2 <- file.path(temp_lamin_dir, ".lamin") - dir.create(temp_lamin_dir2, recursive = TRUE, showWarnings = FALSE) - Sys.setenv(LAMIN_SETTINGS_DIR = temp_lamin_dir) - on.exit({ - unlink(temp_lamin_dir, recursive = TRUE) - Sys.unsetenv("LAMIN_SETTINGS_DIR") - }) - - # 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(temp_lamin_dir2, "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(temp_lamin_dir2, "current_instance.env")) - writeLines(instance_lines, file.path(temp_lamin_dir2, "instance--laminlabs--lamindata.env")) + local_setup_lamindata_instance() # try to connect to lamindata db <- connect("laminlabs/lamindata") From ebd8b955c3db1f537c41505a9531f40854448463 Mon Sep 17 00:00:00 2001 From: Robrecht Cannoodt Date: Thu, 10 Oct 2024 19:45:19 +0200 Subject: [PATCH 5/5] add newline --- tests/testthat/helper-setup_lamindata_instance.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/helper-setup_lamindata_instance.R b/tests/testthat/helper-setup_lamindata_instance.R index 3c67fe4..66bfb60 100644 --- a/tests/testthat/helper-setup_lamindata_instance.R +++ b/tests/testthat/helper-setup_lamindata_instance.R @@ -39,4 +39,4 @@ local_setup_lamindata_instance <- function(env = parent.frame()) { writeLines(instance_lines, file.path(lamin_dir, "instance--laminlabs--lamindata.env")) root_dir -} \ No newline at end of file +}