Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a simple unit test which queries laminlabs/lamindata #27

Merged
merged 7 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:

- name: Install lamindb
run: |
pip install lamindb[bionty]
pip install lamindb[bionty,wetlab]

- name: Log in to Lamin
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:

- name: Install lamindb
run: |
pip install lamindb[bionty]
pip install lamindb[bionty,wetlab]

- name: Log in to Lamin
run: |
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
5 changes: 4 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 12 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -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")
42 changes: 42 additions & 0 deletions tests/testthat/helper-setup_lamindata_instance.R
Original file line number Diff line number Diff line change
@@ -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
}
21 changes: 21 additions & 0 deletions tests/testthat/test-connect_lamindata.R
Original file line number Diff line number Diff line change
@@ -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")
})
Loading