patrick

Parameterized testing in R is kind of cool!

https://github.com/google/patrick

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.5%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

Parameterized testing in R is kind of cool!

Basic Info
  • Host: GitHub
  • Owner: google
  • License: apache-2.0
  • Language: R
  • Default Branch: main
  • Homepage:
  • Size: 93.8 KB
Statistics
  • Stars: 142
  • Watchers: 4
  • Forks: 16
  • Open Issues: 7
  • Releases: 6
Created almost 8 years ago · Last pushed over 1 year ago
Metadata Files
Readme Changelog Contributing License Code of conduct Citation

README.md

R-CMD-check CRAN <!-- badges: end -->

Introducing patrick

This package is an extension to testthat that enables parameterized unit testing in R.

Installing

The release version of patrick is available on CRAN. Install it in the usual manner:

install.packages("patrick")

The development version of patrick is currently only available on GitHub. Install it using devtools.

devtools::install_github("google/patrick")

To use patrick as a testing tool within your package, add it to your list of Suggests within your package's DESCRIPTION.

Suggests: patrick

Use

Many packages within R employ the following pattern when writing tests:

``` testthat("Data is a successfully converted: numeric", { input <- convert(numericdata) expect_type(input, "double") })

testthat("Data is a successfully converted: character", { input <- convert(characterdata) expect_type(input, "character") }) ```

While explicit, recycling a test pattern like this is prone to user error and other issues, as it is a violation of the classic DNRY rule (do not repeat yourself). patrick eliminates this problem by creating test parameters.

with_parameters_test_that("Data is successfully converted:", { input <- convert(test_data) expect_type(input, type) }, test_data = list(numeric_data, character_data), type = c("double", "character"), .test_name = type )

Parameterized tests behave exactly the same as standard testthat tests. Per usual, you call all of your tests with devtools::test, and they'll also run during package checks. Each executes independently and then your test report will produce a single report. A complete name for each test will be formed using the initial test description and the strings in the .test_name parameter.

Small sets of cases can be reasonably passed as parameters to with_parameters_test_that. This becomes less readable when the number of cases increases. To help mitigate this issue, patrick provides a case generator helper function.

with_parameters_test_that("Data is successfully converted:", { input <- convert(test_data) expect_type(input, type) }, cases( double = list(test_data = numeric_data, type = "double"), character = list(test_data = character_data, type = "character") ) )

More complicated testing cases can be constructed using data frames. This is usually best handled within a helper function and in a helper-<test>.R file.

``` makecases <- function() { tibble::tribble( ~ .testname, ~ expr, ~ numeric_value, "sin", sin(pi / 4), 1 / sqrt(2), "cos", cos(pi / 4), 1 / sqrt(2), "tan", tan(pi / 4), 1 ) }

withparameterstestthat( "trigonometric functions match identities", { testthat::expectequal(expr, numericvalue) }, .cases = makecases() ) ```

If you don't provide test names when generating cases, patrick will generate them automatically from the test data.

Inspiration

This package is inspired by parameterized testing packages in other languages, notably the parameterized library in Python.

Contributing

Please read the CONTRIBUTING.md for details on how to contribute to this project.

Disclaimer

This is not an officially supported Google product.

Owner

  • Name: Google
  • Login: google
  • Kind: organization
  • Email: opensource@google.com
  • Location: United States of America

Google ❤️ Open Source

GitHub Events

Total
  • Create event: 3
  • Release event: 1
  • Issues event: 4
  • Watch event: 6
  • Issue comment event: 16
  • Push event: 16
  • Pull request event: 6
  • Pull request review event: 7
  • Pull request review comment event: 7
  • Fork event: 4
Last Year
  • Create event: 3
  • Release event: 1
  • Issues event: 4
  • Watch event: 6
  • Issue comment event: 16
  • Push event: 16
  • Pull request event: 6
  • Pull request review event: 7
  • Pull request review comment event: 7
  • Fork event: 4

Committers

Last synced: 11 months ago

All Time
  • Total Commits: 76
  • Total Committers: 4
  • Avg Commits per committer: 19.0
  • Development Distribution Score (DDS): 0.184
Past Year
  • Commits: 23
  • Committers: 2
  • Avg Commits per committer: 11.5
  • Development Distribution Score (DDS): 0.348
Top Committers
Name Email Commits
Michael Quinn m****n@g****m 62
Michael Chirico c****m@g****m 12
amrrs a****a@g****m 1
Zé Vinícius j****a@g****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 11 months ago

All Time
  • Total issues: 17
  • Total pull requests: 16
  • Average time to close issues: 2 months
  • Average time to close pull requests: 3 days
  • Total issue authors: 7
  • Total pull request authors: 5
  • Average comments per issue: 2.47
  • Average comments per pull request: 0.75
  • Merged pull requests: 11
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 3
  • Pull requests: 8
  • Average time to close issues: about 2 months
  • Average time to close pull requests: 5 days
  • Issue authors: 3
  • Pull request authors: 2
  • Average comments per issue: 0.33
  • Average comments per pull request: 0.38
  • Merged pull requests: 4
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • MichaelChirico (4)
  • michaelquinn32 (4)
  • howardbaek (3)
  • hadley (2)
  • hechth (2)
  • eitsupi (1)
  • mobilegenome (1)
Pull Request Authors
  • MichaelChirico (6)
  • michaelquinn32 (6)
  • amrrs (1)
  • kant (1)
  • mirca (1)
Top Labels
Issue Labels
Pull Request Labels
duplicate (1)

Packages

  • Total packages: 3
  • Total downloads:
    • cran 4,892 last-month
  • Total docker downloads: 170
  • Total dependent packages: 9
    (may contain duplicates)
  • Total dependent repositories: 23
    (may contain duplicates)
  • Total versions: 17
  • Total maintainers: 1
proxy.golang.org: github.com/google/patrick
  • Versions: 6
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 5.5%
Average: 5.6%
Dependent repos count: 5.8%
Last synced: 11 months ago
cran.r-project.org: patrick

Parameterized Unit Testing

  • Versions: 7
  • Dependent Packages: 9
  • Dependent Repositories: 23
  • Downloads: 4,892 Last month
  • Docker Downloads: 170
Rankings
Stargazers count: 3.3%
Forks count: 4.6%
Dependent repos count: 5.7%
Dependent packages count: 6.1%
Average: 7.6%
Downloads: 8.5%
Docker downloads count: 17.1%
Maintainers (1)
Last synced: 11 months ago
conda-forge.org: r-patrick
  • Versions: 4
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Stargazers count: 30.8%
Dependent repos count: 34.0%
Forks count: 36.7%
Average: 38.2%
Dependent packages count: 51.2%
Last synced: 11 months ago

Dependencies

DESCRIPTION cran
  • R >= 3.1 depends
  • dplyr * imports
  • purrr * imports
  • rlang * imports
  • testthat * imports
  • tibble * imports
.github/workflows/R-CMD-check.yaml actions
  • actions/checkout v2 composite
  • r-lib/actions/check-r-package v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite