tests/testthat/test-rule_works_on_tbl.R

describe("rule_works_on_tbl", {
  it ("works with numeric checks",{
    rules <- validator(x > 1, y < x, x == 0)
    con <- dbplyr::src_memdb()
    
    d <- data.frame(x = 1, y = 2)
    tbl_d <- dplyr::copy_to(con, d, overwrite=TRUE)
    
    res <- rule_works_on_tbl(tbl_d, rules)
    expect_equal(res, c(TRUE, TRUE, TRUE))
  })
  
  it ("fails on function not on db",{
    f <- function(x) x
    rules <- validator(x > 1, f(x) > 0)
    con <- dbplyr::src_memdb()
    
    d <- data.frame(x = 1, y = 2)
    tbl_d <- dplyr::copy_to(con, d, overwrite=TRUE)
    
    res <- rule_works_on_tbl(tbl_d, rules)
    expect_equal(res, c(TRUE, FALSE))
  })
})

Try the validatedb package in your browser

Any scripts or data that you put into this service are public.

validatedb documentation built on Oct. 6, 2021, 5:17 p.m.