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

[R-package] [ci] silence more logs in tests (fixes #4862) #5250

Merged
merged 1 commit into from
May 31, 2022
Merged
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
40 changes: 23 additions & 17 deletions R-package/tests/testthat/test_basic.R
Original file line number Diff line number Diff line change
Expand Up @@ -561,13 +561,15 @@ test_that("lgb.cv() raises an informative error for unrecognized objectives", {
, label = train$label
)
expect_error({
bst <- lgb.cv(
data = dtrain
, params = list(
objective_type = "not_a_real_objective"
, verbosity = VERBOSITY
capture.output({
bst <- lgb.cv(
data = dtrain
, params = list(
objective_type = "not_a_real_objective"
, verbosity = VERBOSITY
)
)
)
}, type = "message")
}, regexp = "Unknown objective type name: not_a_real_objective")
})

Expand Down Expand Up @@ -723,13 +725,15 @@ test_that("lgb.train() raises an informative error for unrecognized objectives",
, label = train$label
)
expect_error({
bst <- lgb.train(
data = dtrain
, params = list(
objective_type = "not_a_real_objective"
, verbosity = VERBOSITY
capture.output({
bst <- lgb.train(
data = dtrain
, params = list(
objective_type = "not_a_real_objective"
, verbosity = VERBOSITY
)
)
)
}, type = "message")
}, regexp = "Unknown objective type name: not_a_real_objective")
})

Expand Down Expand Up @@ -2441,11 +2445,13 @@ test_that("lgb.train() w/ linear learner fails already-constructed dataset with
)
dtrain$construct()
expect_error({
bst_linear <- lgb.train(
data = dtrain
, nrounds = 10L
, params = utils::modifyList(params, list(linear_tree = TRUE))
)
capture.output({
bst_linear <- lgb.train(
data = dtrain
, nrounds = 10L
, params = utils::modifyList(params, list(linear_tree = TRUE))
)
}, type = "message")
}, regexp = "Cannot change linear_tree after constructed Dataset handle")
})

Expand Down
4 changes: 3 additions & 1 deletion R-package/tests/testthat/test_dataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,9 @@ test_that("cpp errors should be raised as proper R errors", {
, init_score = seq_len(10L)
)
expect_error({
dtrain$construct()
capture.output({
dtrain$construct()
}, type = "message")
}, regexp = "Initial score size doesn't match data size")
})

Expand Down
46 changes: 29 additions & 17 deletions R-package/tests/testthat/test_lgb.Booster.R
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,11 @@ test_that("Saving a model with unknown importance type fails", {

UNSUPPORTED_IMPORTANCE <- 2L
expect_error({
model_string <- bst$save_model_to_string(feature_importance_type = UNSUPPORTED_IMPORTANCE)
capture.output({
model_string <- bst$save_model_to_string(
feature_importance_type = UNSUPPORTED_IMPORTANCE
)
}, type = "message")
}, "Unknown importance type")
})

Expand Down Expand Up @@ -964,10 +968,12 @@ test_that("Booster$new() raises informative errors for malformed inputs", {

# unrecognized objective
expect_error({
Booster$new(
params = list(objective = "not_a_real_objective")
, train_set = dtrain
)
capture.output({
Booster$new(
params = list(objective = "not_a_real_objective")
, train_set = dtrain
)
}, type = "message")
}, regexp = "Unknown objective type name: not_a_real_objective")

# train_set is not a Dataset
Expand All @@ -986,10 +992,12 @@ test_that("Booster$new() raises informative errors for malformed inputs", {

# model file doesn't exist
expect_error({
Booster$new(
params = list()
, modelfile = "file-that-does-not-exist.model"
)
capture.output({
Booster$new(
params = list()
, modelfile = "file-that-does-not-exist.model"
)
}, type = "message")
}, regexp = "Could not open file-that-does-not-exist.model")

# model file doesn't contain a valid LightGBM model
Expand All @@ -999,18 +1007,22 @@ test_that("Booster$new() raises informative errors for malformed inputs", {
, con = model_file
)
expect_error({
Booster$new(
params = list()
, modelfile = model_file
)
capture.output({
Booster$new(
params = list()
, modelfile = model_file
)
}, type = "message")
}, regexp = "Unknown model format or submodel type in model file")

# malformed model string
expect_error({
Booster$new(
params = list()
, model_str = "a\nb\n"
)
capture.output({
Booster$new(
params = list()
, model_str = "a\nb\n"
)
}, type = "message")
}, regexp = "Model file doesn't specify the number of classes")

# model string isn't character or raw
Expand Down