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", {
)
}
.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) {
# should work for fitted models
#--- should work for fitted models --- #
# print()
log_txt <- capture.output({
ret <- print(model)
})
.have_same_handle(ret, model)
.has_expected_content_for_fitted_model(log_txt)
# show()
log_txt <- capture.output({
ret <- show(model)
})
expect_null(ret)
.has_expected_content_for_fitted_model(log_txt)
# summary()
log_text <- capture.output({
ret <- summary(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()
# print()
log_txt <- capture.output({
ret <- print(model)
})
.has_expected_content_for_finalized_model(log_txt)
# show()
.have_same_handle(ret, model)
log_txt <- capture.output({
ret <- show(model)
})
expect_null(ret)
.has_expected_content_for_finalized_model(log_txt)
# summary()
log_txt <- capture.output({
ret <- summary(model)
})
.have_same_handle(ret, model)
.has_expected_content_for_finalized_model(log_txt)
}
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