Unverified Commit 1a3afd2d authored by James Lamb's avatar James Lamb Committed by GitHub
Browse files

[R-package] silence logs in print(), show(), summary() tests (#5237)

parent f2e1ad6f
...@@ -1255,24 +1255,64 @@ test_that("Booster's print, show, and summary work correctly", { ...@@ -1255,24 +1255,64 @@ test_that("Booster's print, show, and summary work correctly", {
) )
} }
.has_expected_content_for_fitted_model <- function(printed_txt) {
expect_true(any(grepl("^LightGBM Model", printed_txt)))
expect_true(any(grepl("^Fitted to dataset", printed_txt)))
}
.has_expected_content_for_finalized_model <- function(printed_txt) {
expect_true(any(grepl("^LightGBM Model$", printed_txt)))
expect_true(any(grepl("Booster handle is invalid", printed_txt)))
}
.check_methods_work <- function(model) { .check_methods_work <- function(model) {
# should work for fitted models #--- should work for fitted models --- #
ret <- print(model)
# print()
log_txt <- capture.output({
ret <- print(model)
})
.have_same_handle(ret, model) .have_same_handle(ret, model)
ret <- show(model) .has_expected_content_for_fitted_model(log_txt)
# show()
log_txt <- capture.output({
ret <- show(model)
})
expect_null(ret) expect_null(ret)
ret <- summary(model) .has_expected_content_for_fitted_model(log_txt)
# summary()
log_text <- capture.output({
ret <- summary(model)
})
.have_same_handle(ret, model) .have_same_handle(ret, model)
.has_expected_content_for_fitted_model(log_txt)
# should not fail for finalized models #--- should not fail for finalized models ---#
model$finalize() model$finalize()
ret <- print(model)
# print()
log_txt <- capture.output({
ret <- print(model)
})
.has_expected_content_for_finalized_model(log_txt)
# show()
.have_same_handle(ret, model) .have_same_handle(ret, model)
ret <- show(model) log_txt <- capture.output({
ret <- show(model)
})
expect_null(ret) expect_null(ret)
ret <- summary(model) .has_expected_content_for_finalized_model(log_txt)
# summary()
log_txt <- capture.output({
ret <- summary(model)
})
.have_same_handle(ret, model) .have_same_handle(ret, model)
.has_expected_content_for_finalized_model(log_txt)
} }
data("mtcars") data("mtcars")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment