Skip to content

Commit

Permalink
Fix more test cases
Browse files Browse the repository at this point in the history
Signed-off-by: Liang Zhang <[email protected]>
  • Loading branch information
psychelzh committed Jul 20, 2024
1 parent a5a4a9c commit 8497758
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 100 deletions.
133 changes: 63 additions & 70 deletions tests/testthat/test_basic-cases.R
Original file line number Diff line number Diff line change
@@ -1,91 +1,84 @@
skip_if_not(check_source())
test_that("Works when single game on different projects", {
targets::tar_dir({
targets::tar_script({
library(targets)
tar_prep_iquizoo(
contents = tibble::tibble(
project_id = bit64::as.integer64(c(519355469824389, 519355011072389)),
game_id = bit64::as.integer64(238239294447813)
),
what = "scores"
)
})
targets::tar_make(reporter = "silent", callr_function = NULL)
expect_equal(
unique(targets::tar_read(scores_238239294447813)$project_id),
bit64::as.integer64(c(519355469824389, 519355011072389))
targets::tar_test("Works when single game on different projects", {
targets::tar_script({
library(targets)
tar_prep_iquizoo(
contents = tibble::tibble(
project_id = bit64::as.integer64(c(519355469824389, 519355011072389)),
game_id = bit64::as.integer64(238239294447813)
),
what = "scores"
)
})
targets::tar_make(reporter = "silent", callr_function = NULL)
expect_equal(
unique(targets::tar_read(scores_238239294447813)$project_id),
bit64::as.integer64(c(519355469824389, 519355011072389))
)
})

test_that("`combine` work properly", {
targets::tar_dir({
targets::tar_script({
library(targets)
params <- tibble::tribble(
~organization_name, ~project_name,
"北京师范大学测试用账号", "难度测试"
)
tar_prep_iquizoo(
params,
combine = objects()
)
})
expect_contains(
targets::tar_manifest(callr_function = NULL)$name,
objects()
targets::tar_test("`combine` work properly", {
targets::tar_script({
library(targets)
params <- tibble::tribble(
~organization_name, ~project_name,
"北京师范大学(测试)", "元认知测试"
)
tar_prep_iquizoo(
params,
combine = objects(),
cache = cachem::cache_mem()
)
})
expect_contains(
targets::tar_manifest(callr_function = NULL)$name,
objects()
)
params <- tibble::tribble(
~organization_name, ~project_name,
"北京师范大学测试用账号", "难度测试"
"北京师范大学(测试)", "元认知测试"
)
tar_prep_iquizoo(params, combine = "bad") |>
expect_error(class = "tarflow_bad_combine")
})

test_that("Serialize check (no roundtrip error)", {
targets::tar_test("Serialize check (no roundtrip error)", {
withr::local_envvar(c(TARFLOW_CACHE = "memory"))
targets::tar_dir({
targets::tar_script({
library(targets)
params <- tibble::tribble(
~organization_name, ~project_name,
"四川省双流棠湖中学高中部", "棠湖中学英才计划测训体验账号"
)
tar_prep_iquizoo(params)[1]
})
targets::tar_make(reporter = "silent", callr_function = NULL)
expect_identical(
targets::tar_read(contents_origin),
fetch_iquizoo(
read_file(setup_templates()$contents),
params = unname(as.list(
tibble::tribble(
~organization_name, ~project_name,
"四川省双流棠湖中学高中部", "棠湖中学英才计划测训体验账号"
)
))
)
targets::tar_script({
library(targets)
params <- tibble::tribble(
~organization_name, ~project_name,
"四川省双流棠湖中学高中部", "棠湖中学英才计划测训体验账号"
)
tar_prep_iquizoo(params)[1]
})
targets::tar_make(reporter = "silent", callr_function = NULL)
expect_identical(
targets::tar_read(contents_origin),
fetch_iquizoo(
read_file(setup_templates()$contents),
params = unname(as.list(
tibble::tribble(
~organization_name, ~project_name,
"四川省双流棠湖中学高中部", "棠湖中学英才计划测训体验账号"
)
))
)
)
})

test_that("Ensure project date is used", {
targets::tar_dir({
targets::tar_script({
library(targets)
tar_prep_iquizoo(
contents = data.frame(
project_id = bit64::as.integer64(132121231360389),
game_id = bit64::as.integer64(268008982646879)
),
what = "scores",
combine = "scores"
)
})
targets::tar_make(reporter = "silent", callr_function = NULL)
nrow(targets::tar_read(scores)) |> expect_gt(0)
targets::tar_test("Ensure project date is used", {
targets::tar_script({
library(targets)
tar_prep_iquizoo(
contents = data.frame(
project_id = bit64::as.integer64(132121231360389),
game_id = bit64::as.integer64(268008982646879)
),
what = "scores",
combine = "scores"
)
})
targets::tar_make(reporter = "silent", callr_function = NULL)
nrow(targets::tar_read(scores)) |> expect_gt(0)
})
30 changes: 16 additions & 14 deletions tests/testthat/test_basic-workflow.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
skip_if_not(check_source())
test_that("Workflow works", {
targets::tar_test("Workflow works", {
skip_if_not_installed("preproc.iquizoo")
targets::tar_dir({
targets::tar_script({
library(targets)
params <- tibble::tribble(
~organization_name, ~project_name,
"北京师范大学", "4.19-4.20夜晚睡眠test"
)
tarflow.iquizoo::tar_prep_iquizoo(params, combine = "scores")
})
expect_silent(targets::tar_make(reporter = "silent", callr_function = NULL))
expect_snapshot_value(targets::tar_objects(), style = "json2")
expect_snapshot_value(targets::tar_read(users), style = "json2")
expect_snapshot_value(targets::tar_read(scores), style = "json2")
targets::tar_script({
library(targets)
params <- tibble::tribble(
~organization_name, ~project_name,
"北京师范大学", "4.19-4.20夜晚睡眠test"
)
tarflow.iquizoo::tar_prep_iquizoo(
params,
combine = "scores",
cache = cachem::cache_mem()
)
})
targets::tar_make(reporter = "silent", callr_function = NULL)
expect_snapshot_value(targets::tar_objects(), style = "json2")
expect_snapshot_value(targets::tar_read(users), style = "json2")
expect_snapshot_value(targets::tar_read(scores), style = "json2")
})
28 changes: 12 additions & 16 deletions tests/testthat/test_check-progress.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
skip_if_not(check_source())
test_that("Ensure `check_progress = FALSE` work", {
targets::tar_dir({
targets::tar_script({
library(targets)
tar_prep_iquizoo(
contents = data.frame(
project_id = bit64::as.integer64(132121231360389),
game_id = bit64::as.integer64(268008982646879)
),
what = "scores",
check_progress = FALSE
)
})
targets::tar_make(reporter = "silent", callr_function = NULL)
expect_true(
all(!startsWith(targets::tar_objects(), "progress_hash"))
targets::tar_test("Ensure `check_progress = FALSE` work", {
targets::tar_script({
library(targets)
tar_prep_iquizoo(
contents = data.frame(
project_id = bit64::as.integer64(132121231360389),
game_id = bit64::as.integer64(268008982646879)
),
what = "scores",
check_progress = FALSE
)
})
targets::tar_make(reporter = "silent", callr_function = NULL)
expect_true(all(!startsWith(targets::tar_objects(), "progress_hash")))
})

0 comments on commit 8497758

Please sign in to comment.