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

Capture pointblank validation steps in level-2/3 stubs #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 R/pointblank.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ get_pb_lines <- function(convo, level) {
funs <- funs[!no_funs]

edit_expect <- function(stub, fun) {
stub_prep <- paste0("(", "matches('", "^([A-Za-z]_){", level-1 ,"}", stub, "')")
stub_prep <- paste0("(", "matches('", "^([A-Za-z]+_){", level-1 ,"}", stub, "')")
stub_prep <- ifelse(!grepl("\\(\\)", fun), paste0(stub_prep, ", "), stub_prep)
final <- sub("\\(", stub_prep, fun)
return(final)
Expand Down
52 changes: 52 additions & 0 deletions tests/testthat/test-pb.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,37 @@ agent_yaml2 <-
set_tbl(df2)
agent_obj2 <- create_pb_agent(convo2, df2, level = 2)


# validation checks with flipped schema (measure in level 2/3) ---------------

dt_msr_in_lvl3 <- data.frame(car_name_id = numeric(), car_name_name = character(),
passenger_name_cnt = numeric())
dt_msr_in_lvl2 <- data.frame(car_id = numeric(), passenger_name_first = character(),
passenger_cnt = numeric())


cnv_msr_in_lvl3 <- structure(list(
level1 = list(car = NULL,
passenger = NULL),
level2 = list(name = NULL),
level3 = list(id = list(valid = "col_is_numeric()"),
cnt = list(valid = "col_is_numeric()"),
name = NULL)),
class = c("convo", "list"))

cnv_msr_in_lvl2 <- structure(list(
level1 = list(car = NULL,
passenger = NULL),
level2 = list(id = list(valid = "col_is_numeric()"),
cnt = list(valid = "col_is_numeric()"),
name = NULL),
level3 = list(last = NULL,
first = NULL)),
class = c("convo", "list"))

cagent3 <- create_pb_agent(cnv_msr_in_lvl2, dt_msr_in_lvl2, level = 2)
cagent2 <- create_pb_agent(cnv_msr_in_lvl3, dt_msr_in_lvl3, level = 3)

# tests when validation checks at level 1 ----
test_that(
"YAML agent find correct variables and data checks ", {
Expand Down Expand Up @@ -79,4 +110,25 @@ test_that(
}
)

# tests for validation checks with flipped schema (measure in level 2/3) ---------------

test_that("Level 2 and 3 data frames match their respective convos", {
expect_equal(evaluate_convo(cnv_msr_in_lvl2, names(dt_msr_in_lvl2)) %>% unlist(),
character())
expect_equal(evaluate_convo(cnv_msr_in_lvl3, names(dt_msr_in_lvl3)) %>% unlist(),
character())
})

test_that("columns are captured for level 3 checks in pointblank", {
expect_equal(nrow(cagent3$validation_set), 2)
expect_setequal(sort(unlist(cagent3$validation_set$column)),
c("car_id", "passenger_cnt"))
})

test_that("columns are captured for level 2 checks in pointblank", {
expect_equal(nrow(cagent2$validation_set), 2)
expect_setequal(sort(unlist(cagent2$validation_set$column)),
c("car_name_id", "passenger_name_cnt"))
})