Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tianlh
LightGBM-DCU
Commits
1a3afd2d
Unverified
Commit
1a3afd2d
authored
May 25, 2022
by
James Lamb
Committed by
GitHub
May 25, 2022
Browse files
[R-package] silence logs in print(), show(), summary() tests (#5237)
parent
f2e1ad6f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
8 deletions
+48
-8
R-package/tests/testthat/test_lgb.Booster.R
R-package/tests/testthat/test_lgb.Booster.R
+48
-8
No files found.
R-package/tests/testthat/test_lgb.Booster.R
View file @
1a3afd2d
...
@@ -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"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment