Skip to content

Commit

Permalink
Add tests and bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwarkentin committed Aug 12, 2024
1 parent 5639f07 commit 6934c15
Show file tree
Hide file tree
Showing 22 changed files with 214 additions and 13 deletions.
17 changes: 10 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Package: openmpp
Title: Programmatic Interface to OpenM++
Version: 0.0.0.9000
Version: 0.0.1
Authors@R:
person("Matthew T.", "Warkentin", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-8730-3511"))
Description: A programmatic interface to the OpenM++ microsimulation platform.
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2.9000
Depends:
R (>= 4.1.0)
Imports:
Expand All @@ -30,6 +30,11 @@ BugReports: https://github.com/oncology-outcomes/openmpp/issues
Collate:
'APIConnections.R'
'Admin.R'
'Utils.R'
'ClassModel.R'
'ClassModelRun.R'
'ClassModelRunSet.R'
'ClassWorkset.R'
'Downloads.R'
'ModelExtras.R'
'ModelMetadata.R'
Expand All @@ -39,11 +44,6 @@ Collate:
'ModelWorkset.R'
'OutputTables.R'
'Parameters.R'
'Utils.R'
'R6ClassModel.R'
'R6ClassModelRun.R'
'R6ClassModelRunSet.R'
'R6ClassWorkset.R'
'RunMicrodata.R'
'RunModels.R'
'RunOptions.R'
Expand All @@ -53,3 +53,6 @@ Collate:
'User.R'
'openmpp-package.R'
'zzz.R'
Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export(get_upload_filetree)
export(get_upload_log)
export(get_upload_logs_all)
export(get_upload_logs_model)
export(get_user_files)
export(get_user_views)
export(get_workset)
export(get_workset_param)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 15 additions & 1 deletion R/User.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#' Manage OpenM++ User Settings
#' Manage OpenM++ User Files or Settings
#'
#' Functions for getting, setting, and deleting user configuration settings.
#'
#' @param data Data used for the body of the request.
#' @param ext Comma-separated string of file extensions. Default is `"*"` which
#' returns all files.
#' @param path Optional file path. Default is `""` (empty) and returns the
#' entire tree of user files.
#' @inheritParams get_model
#' @inheritParams get_workset_param
#' @inheritParams get_run_microdata
Expand Down Expand Up @@ -40,3 +44,13 @@ delete_user_views <- function(model) {
httr2::req_perform()
invisible()
}

#' @rdname get_user_views
#' @export
get_user_files <- function(ext = "*", path = "") {
api_path <- glue::glue('/api/files/file-tree/{ext}/path/{path}')
OpenMpp$API$build_request() |>
httr2::req_url_path(api_path) |>
httr2::req_perform() |>
httr2::resp_body_json()
}
11 changes: 10 additions & 1 deletion man/get_user_views.Rd

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

2 changes: 1 addition & 1 deletion man/load_model.Rd

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

2 changes: 1 addition & 1 deletion man/load_model_run.Rd

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

2 changes: 1 addition & 1 deletion man/load_model_runs.Rd

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

2 changes: 1 addition & 1 deletion man/load_workset.Rd

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

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(openmpp)

test_check("openmpp")
12 changes: 12 additions & 0 deletions tests/testthat/test-APIConnections.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
test_that("Should fail with no API connection", {
expect_error(get_models())
expect_error(get_models_list())
})

test_that("Should work with no API connection", {
skip_on_cran()
skip_on_ci()
use_OpenMpp_remote()
expect_no_error(get_models())
expect_no_error(get_models_list())
})
26 changes: 26 additions & 0 deletions tests/testthat/test-ClassModel.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
test_that("Tests OpenMppModel class", {
skip_on_cran()
skip_on_ci()

# Setup
use_OpenMpp_remote()
model_name <- get_models()$Name[[1]]
model <- load_model(model_name)

# Test
expect_type(model, 'environment')
expect_s3_class(model, c("OpenMppModel", "R6"), TRUE)
expect_s3_class(model$TablesInfo, 'data.frame')
expect_s3_class(model$ParamsInfo, 'data.frame')
expect_s3_class(model$ModelTasks, 'data.frame')
expect_s3_class(model$ModelRuns, 'data.frame')
expect_s3_class(model$ModelScenarios, 'data.frame')
expect_s3_class(model$ModelWorksets, 'data.frame')
expect_type(model$ModelMetadata, 'list')
expect_type(model$ModelVersion, 'character')
expect_type(model$ModelName, 'character')
expect_type(model$ModelDigest, 'character')
expect_type(model$OpenMppType, 'character')
expect_equal(model$OpenMppType, 'Model')
expect_output(model$print())
})
37 changes: 37 additions & 0 deletions tests/testthat/test-ClassModelRun.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
test_that("Tests OpenMppModelRun class", {
skip_on_cran()
skip_on_ci()

# Setup
use_OpenMpp_remote()
model_name <- get_models()$Name[[1]]
run_name <- get_model_runs(model_name)$Name[[1]]
run <- load_model_run(model_name, run_name)

# Tests
expect_no_error(load_run(model_name, run_name))
expect_type(run, 'environment')
expect_s3_class(run, c("OpenMppModelRun", "OpenMppModel", "R6"), TRUE)
expect_s3_class(run$TablesInfo, 'data.frame')
expect_s3_class(run$ParamsInfo, 'data.frame')
expect_s3_class(run$ModelTasks, 'data.frame')
expect_s3_class(run$ModelRuns, 'data.frame')
expect_s3_class(run$ModelScenarios, 'data.frame')
expect_s3_class(run$ModelWorksets, 'data.frame')
expect_type(run$Parameters, 'environment')
expect_type(run$Tables, 'environment')
expect_type(run$ModelMetadata, 'list')
expect_type(run$RunMetadata, 'list')
expect_type(run$ModelVersion, 'character')
expect_type(run$ModelName, 'character')
expect_type(run$RunName, 'character')
expect_type(run$ModelDigest, 'character')
expect_type(run$RunDigest, 'character')
expect_type(run$RunStamp, 'character')
expect_type(run$RunStatus, 'character')
expect_type(run$RunStatusInfo, 'list')
expect_type(run$OpenMppType, 'character')
expect_type(run$RunDigest, 'character')
expect_equal(run$OpenMppType, 'ModelRun')
expect_output(run$print())
})
27 changes: 27 additions & 0 deletions tests/testthat/test-ClassModelRunSet.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
test_that("Tests OpenMppModelRunSet class", {
skip_on_cran()
skip_on_ci()

# Setup
use_OpenMpp_remote()
model_name <- get_models()$Name[[1]]
run_name <- get_model_runs(model_name)$Name[[1]]
runset <- load_model_runs(model_name, c(run_name, run_name))

# Tests
expect_no_error(load_runs(model_name, c(run_name, run_name)))
expect_type(runset, 'environment')
expect_s3_class(runset, c("OpenMppModelRunSet", "R6"), TRUE)
expect_type(runset$Tables, 'environment')
expect_type(runset$RunMetadatas, 'list')
expect_type(runset$RunStatuses, 'character')
expect_type(runset$RunStamps, 'character')
expect_type(runset$RunDigests, 'character')
expect_type(runset$RunNames, 'character')
expect_type(runset$OpenMppType, 'character')
expect_equal(runset$OpenMppType, 'ModelRunSet')
expect_type(runset$ModelVersion, 'character')
expect_type(runset$ModelName, 'character')
expect_type(runset$ModelDigest, 'character')
expect_output(runset$print())
})
33 changes: 33 additions & 0 deletions tests/testthat/test-ClassWorkset.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
test_that("Tests OpenMppWorkset class", {
skip_on_cran()
skip_on_ci()

# Setup
use_OpenMpp_remote()
model_name <- get_models()$Name[[1]]
workset_name <- get_worksets(model_name)$Name[[1]]
workset <- load_workset(model_name, workset_name)

# Tests
expect_no_error(load_scenario(model_name, workset_name))
expect_type(workset, 'environment')
expect_s3_class(workset, c("OpenMppWorkset", "OpenMppModel", "R6"), TRUE)
expect_s3_class(workset$TablesInfo, 'data.frame')
expect_s3_class(workset$ParamsInfo, 'data.frame')
expect_s3_class(workset$ModelTasks, 'data.frame')
expect_s3_class(workset$ModelRuns, 'data.frame')
expect_s3_class(workset$ModelScenarios, 'data.frame')
expect_s3_class(workset$ModelWorksets, 'data.frame')
expect_type(workset$Parameters, 'environment')
expect_type(workset$ModelMetadata, 'list')
expect_type(workset$WorksetMetadata, 'list')
expect_type(workset$ModelVersion, 'character')
expect_type(workset$ModelName, 'character')
expect_type(workset$WorksetName, 'character')
expect_type(workset$ModelDigest, 'character')
expect_type(workset$OpenMppType, 'character')
expect_type(workset$BaseRunDigest, 'character')
expect_type(workset$ReadOnly, 'logical')
expect_equal(workset$OpenMppType, 'Workset')
expect_output(workset$print())
})
6 changes: 6 additions & 0 deletions tests/testthat/test-ModelMetadata.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test_that("Get model", {
skip_on_cran()
skip_on_ci()
model_name <- get_models()$Name[[1]]
expect_type(get_model(model_name), 'list')
})
7 changes: 7 additions & 0 deletions tests/testthat/test-ModelRuns.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test_that("Test model run accessors", {
skip_on_cran()
skip_on_ci()
model_name <- get_models()$Name[[1]]
run_name <- get_model_runs(model_name)$Name[[1]]
expect_type(get_run(model_name, run_name), 'list')
})
7 changes: 7 additions & 0 deletions tests/testthat/test-ModelWorkset.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test_that("Get workset", {
skip_on_cran()
skip_on_ci()
model_name <- get_models()$Name[[1]]
workset_name <- get_worksets(model_name)$Name[[1]]
expect_type(get_workset(model_name, workset_name), 'list')
})
7 changes: 7 additions & 0 deletions tests/testthat/test-RunOptions.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test_that("Test run options", {
skip_on_cran()
skip_on_ci()
opts <- opts_run()
expect_s3_class(opts, c("OpenMppRunOpts", "list"))
expect_output(print(opts))
})

0 comments on commit 6934c15

Please sign in to comment.