Learn R Programming

mighty.component (version 0.2.0)

get_test_component: Create a test component

Description

Retrieve and render a component as a mighty_component_test object, for unit tests with code coverage. See mighty_component_test for the workflow.

Requires the callr and covr packages.

Usage

get_test_component(
  component,
  params = list(),
  repos = NULL,
  check_coverage = TRUE,
  teardown_env = parent.frame()
)

Value

A mighty_component_test object.

Arguments

component

character(1) Component name. If repos is NULL, path to a component file.

params

named list of parameters passed to $render(). See the component's @param tags (component$params).

repos

Where to look. One of:

  • NULL (default): component is a file path.

  • character vector of repo specs, in priority order. See mighty_repo().

  • A mighty_repo_class object.

  • A list of repo specs or mighty_repo_class objects, in priority order.

  • A mighty_repos() collection.

Character vectors and lists are converted once with mighty_repos().

check_coverage

logical(1) If TRUE (default), $check_coverage() runs when teardown_env ends. It raises an error if any line has not run.

teardown_env

Environment that controls when the coverage check runs. Defaults to the calling environment, e.g. the test_that() block.

See Also

get_rendered_component(), mighty_component_test

Examples

Run this code
if (FALSE) { # rlang::is_installed(c("admiral", "callr", "covr", "dplyr"))
path <- system.file("examples", "ady.mustache", package = "mighty.component")
x <- get_test_component(
  component = path,
  params = list(domain = "adae", variable = "ASTDY", date = "ASTDT"),
  check_coverage = FALSE
)

adae <- data.frame(
  TRTSDT = as.Date("2024-01-01"),
  ASTDT = as.Date(c("2024-01-01", "2024-01-10"))
)

x$assign("adae", adae)$eval()
x$get("adae")
x$percent_coverage
x$close()
}

Run the code above in your browser using DataLab