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

[R-package] remove uses of testthat::context() in tests (#4915)

parent ab788291
...@@ -2,8 +2,6 @@ VERBOSITY <- as.integer( ...@@ -2,8 +2,6 @@ VERBOSITY <- as.integer(
Sys.getenv("LIGHTGBM_TEST_VERBOSITY", "-1") Sys.getenv("LIGHTGBM_TEST_VERBOSITY", "-1")
) )
context("Predictor")
test_that("Predictor$finalize() should not fail", { test_that("Predictor$finalize() should not fail", {
X <- as.matrix(as.integer(iris[, "Species"]), ncol = 1L) X <- as.matrix(as.integer(iris[, "Species"]), ncol = 1L)
y <- iris[["Sepal.Length"]] y <- iris[["Sepal.Length"]]
......
...@@ -2,8 +2,6 @@ VERBOSITY <- as.integer( ...@@ -2,8 +2,6 @@ VERBOSITY <- as.integer(
Sys.getenv("LIGHTGBM_TEST_VERBOSITY", "-1") Sys.getenv("LIGHTGBM_TEST_VERBOSITY", "-1")
) )
context("lightgbm()")
ON_WINDOWS <- .Platform$OS.type == "windows" ON_WINDOWS <- .Platform$OS.type == "windows"
UTF8_LOCALE <- all(grepl( UTF8_LOCALE <- all(grepl(
...@@ -326,9 +324,6 @@ test_that("lightgbm() does not write model to disk if save_name=NULL", { ...@@ -326,9 +324,6 @@ test_that("lightgbm() does not write model to disk if save_name=NULL", {
expect_equal(files_before, files_after) expect_equal(files_before, files_after)
}) })
context("training continuation")
test_that("training continuation works", { test_that("training continuation works", {
dtrain <- lgb.Dataset( dtrain <- lgb.Dataset(
train$data train$data
...@@ -360,8 +355,6 @@ test_that("training continuation works", { ...@@ -360,8 +355,6 @@ test_that("training continuation works", {
expect_lt(abs(err_bst - err_bst2), 0.01) expect_lt(abs(err_bst - err_bst2), 0.01)
}) })
context("lgb.cv()")
test_that("cv works", { test_that("cv works", {
dtrain <- lgb.Dataset(train$data, label = train$label) dtrain <- lgb.Dataset(train$data, label = train$label)
params <- list( params <- list(
...@@ -593,8 +586,6 @@ test_that("lgb.cv() respects eval_train_metric argument", { ...@@ -593,8 +586,6 @@ test_that("lgb.cv() respects eval_train_metric argument", {
) )
}) })
context("lgb.train()")
test_that("lgb.train() works as expected with multiple eval metrics", { test_that("lgb.train() works as expected with multiple eval metrics", {
metrics <- c("binary_error", "auc", "binary_logloss") metrics <- c("binary_error", "auc", "binary_logloss")
bst <- lgb.train( bst <- lgb.train(
...@@ -2139,8 +2130,6 @@ test_that("lgb.cv() updates params based on keyword arguments", { ...@@ -2139,8 +2130,6 @@ test_that("lgb.cv() updates params based on keyword arguments", {
}) })
context("linear learner")
test_that("lgb.train() fit on linearly-relatead data improves when using linear learners", { test_that("lgb.train() fit on linearly-relatead data improves when using linear learners", {
set.seed(708L) set.seed(708L)
.new_dataset <- function() { .new_dataset <- function() {
...@@ -2380,8 +2369,6 @@ test_that("lgb.train() works with linear learners when Dataset has categorical f ...@@ -2380,8 +2369,6 @@ test_that("lgb.train() works with linear learners when Dataset has categorical f
expect_true(bst_lin_last_mse < bst_last_mse) expect_true(bst_lin_last_mse < bst_last_mse)
}) })
context("interaction constraints")
test_that("lgb.train() throws an informative error if interaction_constraints is not a list", { test_that("lgb.train() throws an informative error if interaction_constraints is not a list", {
dtrain <- lgb.Dataset(train$data, label = train$label) dtrain <- lgb.Dataset(train$data, label = train$label)
params <- list(objective = "regression", interaction_constraints = "[1,2],[3]") params <- list(objective = "regression", interaction_constraints = "[1,2],[3]")
...@@ -2482,8 +2469,6 @@ test_that(paste0("lgb.train() gives same results when using interaction_constrai ...@@ -2482,8 +2469,6 @@ test_that(paste0("lgb.train() gives same results when using interaction_constrai
}) })
context("monotone constraints")
.generate_trainset_for_monotone_constraints_tests <- function(x3_to_categorical) { .generate_trainset_for_monotone_constraints_tests <- function(x3_to_categorical) {
n_samples <- 3000L n_samples <- 3000L
x1_positively_correlated_with_y <- runif(n = n_samples, min = 0.0, max = 1.0) x1_positively_correlated_with_y <- runif(n = n_samples, min = 0.0, max = 1.0)
......
...@@ -2,8 +2,6 @@ VERBOSITY <- as.integer( ...@@ -2,8 +2,6 @@ VERBOSITY <- as.integer(
Sys.getenv("LIGHTGBM_TEST_VERBOSITY", "-1") Sys.getenv("LIGHTGBM_TEST_VERBOSITY", "-1")
) )
context("Test models with custom objective")
data(agaricus.train, package = "lightgbm") data(agaricus.train, package = "lightgbm")
data(agaricus.test, package = "lightgbm") data(agaricus.test, package = "lightgbm")
dtrain <- lgb.Dataset(agaricus.train$data, label = agaricus.train$label) dtrain <- lgb.Dataset(agaricus.train$data, label = agaricus.train$label)
......
...@@ -2,8 +2,6 @@ VERBOSITY <- as.integer( ...@@ -2,8 +2,6 @@ VERBOSITY <- as.integer(
Sys.getenv("LIGHTGBM_TEST_VERBOSITY", "-1") Sys.getenv("LIGHTGBM_TEST_VERBOSITY", "-1")
) )
context("testing lgb.Dataset functionality")
data(agaricus.train, package = "lightgbm") data(agaricus.train, package = "lightgbm")
train_data <- agaricus.train$data[seq_len(1000L), ] train_data <- agaricus.train$data[seq_len(1000L), ]
train_label <- agaricus.train$label[seq_len(1000L)] train_label <- agaricus.train$label[seq_len(1000L)]
......
...@@ -2,8 +2,6 @@ VERBOSITY <- as.integer( ...@@ -2,8 +2,6 @@ VERBOSITY <- as.integer(
Sys.getenv("LIGHTGBM_TEST_VERBOSITY", "-1") Sys.getenv("LIGHTGBM_TEST_VERBOSITY", "-1")
) )
context("Learning to rank")
# numerical tolerance to use when checking metric values # numerical tolerance to use when checking metric values
TOLERANCE <- 1e-06 TOLERANCE <- 1e-06
......
...@@ -2,8 +2,6 @@ VERBOSITY <- as.integer( ...@@ -2,8 +2,6 @@ VERBOSITY <- as.integer(
Sys.getenv("LIGHTGBM_TEST_VERBOSITY", "-1") Sys.getenv("LIGHTGBM_TEST_VERBOSITY", "-1")
) )
context("Booster")
ON_WINDOWS <- .Platform$OS.type == "windows" ON_WINDOWS <- .Platform$OS.type == "windows"
TOLERANCE <- 1e-6 TOLERANCE <- 1e-6
...@@ -31,8 +29,6 @@ test_that("Booster$finalize() should not fail", { ...@@ -31,8 +29,6 @@ test_that("Booster$finalize() should not fail", {
expect_true(lgb.is.null.handle(bst$.__enclos_env__$private$handle)) expect_true(lgb.is.null.handle(bst$.__enclos_env__$private$handle))
}) })
context("lgb.get.eval.result")
test_that("lgb.get.eval.result() should throw an informative error if booster is not an lgb.Booster", { test_that("lgb.get.eval.result() should throw an informative error if booster is not an lgb.Booster", {
bad_inputs <- list( bad_inputs <- list(
matrix(1.0:10.0, 2L, 5L) matrix(1.0:10.0, 2L, 5L)
...@@ -124,8 +120,6 @@ test_that("lgb.get.eval.result() should throw an informative error for incorrect ...@@ -124,8 +120,6 @@ test_that("lgb.get.eval.result() should throw an informative error for incorrect
}, regexp = "Only the following eval_names exist for dataset.*\\: \\[l2\\]", fixed = FALSE) }, regexp = "Only the following eval_names exist for dataset.*\\: \\[l2\\]", fixed = FALSE)
}) })
context("lgb.load()")
test_that("lgb.load() gives the expected error messages given different incorrect inputs", { test_that("lgb.load() gives the expected error messages given different incorrect inputs", {
set.seed(708L) set.seed(708L)
data(agaricus.train, package = "lightgbm") data(agaricus.train, package = "lightgbm")
...@@ -394,8 +388,6 @@ test_that("If a string and a file are both passed to lgb.load() the file is used ...@@ -394,8 +388,6 @@ test_that("If a string and a file are both passed to lgb.load() the file is used
expect_identical(pred, pred2) expect_identical(pred, pred2)
}) })
context("Booster")
test_that("Creating a Booster from a Dataset should work", { test_that("Creating a Booster from a Dataset should work", {
set.seed(708L) set.seed(708L)
data(agaricus.train, package = "lightgbm") data(agaricus.train, package = "lightgbm")
...@@ -692,8 +684,6 @@ test_that("Booster$params should include dataset params, before and after Booste ...@@ -692,8 +684,6 @@ test_that("Booster$params should include dataset params, before and after Booste
expect_identical(bst$params, expected_params) expect_identical(bst$params, expected_params)
}) })
context("save_model")
test_that("Saving a model with different feature importance types works", { test_that("Saving a model with different feature importance types works", {
set.seed(708L) set.seed(708L)
data(agaricus.train, package = "lightgbm") data(agaricus.train, package = "lightgbm")
...@@ -1032,8 +1022,6 @@ test_that("lgb.cv() correctly handles passing through params to the model file", ...@@ -1032,8 +1022,6 @@ test_that("lgb.cv() correctly handles passing through params to the model file",
}) })
context("saveRDS.lgb.Booster() and readRDS.lgb.Booster()")
test_that("params (including dataset params) should be stored in .rds file for Booster", { test_that("params (including dataset params) should be stored in .rds file for Booster", {
data(agaricus.train, package = "lightgbm") data(agaricus.train, package = "lightgbm")
dtrain <- lgb.Dataset( dtrain <- lgb.Dataset(
...@@ -1069,8 +1057,6 @@ test_that("params (including dataset params) should be stored in .rds file for B ...@@ -1069,8 +1057,6 @@ test_that("params (including dataset params) should be stored in .rds file for B
) )
}) })
context("saveRDS and readRDS work on Booster")
test_that("params (including dataset params) should be stored in .rds file for Booster", { test_that("params (including dataset params) should be stored in .rds file for Booster", {
data(agaricus.train, package = "lightgbm") data(agaricus.train, package = "lightgbm")
dtrain <- lgb.Dataset( dtrain <- lgb.Dataset(
......
context("lgb.convert_with_rules()")
test_that("lgb.convert_with_rules() rejects inputs that are not a data.table or data.frame", { test_that("lgb.convert_with_rules() rejects inputs that are not a data.table or data.frame", {
bad_inputs <- list( bad_inputs <- list(
matrix(1.0:10.0, 2L, 5L) matrix(1.0:10.0, 2L, 5L)
......
context("lgb.importance")
test_that("lgb.importance() should reject bad inputs", { test_that("lgb.importance() should reject bad inputs", {
bad_inputs <- list( bad_inputs <- list(
.Machine$integer.max .Machine$integer.max
......
...@@ -2,8 +2,6 @@ VERBOSITY <- as.integer( ...@@ -2,8 +2,6 @@ VERBOSITY <- as.integer(
Sys.getenv("LIGHTGBM_TEST_VERBOSITY", "-1") Sys.getenv("LIGHTGBM_TEST_VERBOSITY", "-1")
) )
context("lgb.interpete")
.sigmoid <- function(x) { .sigmoid <- function(x) {
1.0 / (1.0 + exp(-x)) 1.0 / (1.0 + exp(-x))
} }
......
...@@ -2,8 +2,6 @@ VERBOSITY <- as.integer( ...@@ -2,8 +2,6 @@ VERBOSITY <- as.integer(
Sys.getenv("LIGHTGBM_TEST_VERBOSITY", "-1") Sys.getenv("LIGHTGBM_TEST_VERBOSITY", "-1")
) )
context("lgb.plot.importance()")
test_that("lgb.plot.importance() should run without error for well-formed inputs", { test_that("lgb.plot.importance() should run without error for well-formed inputs", {
data(agaricus.train, package = "lightgbm") data(agaricus.train, package = "lightgbm")
train <- agaricus.train train <- agaricus.train
......
...@@ -2,8 +2,6 @@ VERBOSITY <- as.integer( ...@@ -2,8 +2,6 @@ VERBOSITY <- as.integer(
Sys.getenv("LIGHTGBM_TEST_VERBOSITY", "-1") Sys.getenv("LIGHTGBM_TEST_VERBOSITY", "-1")
) )
context("lgb.plot.interpretation")
.sigmoid <- function(x) { .sigmoid <- function(x) {
1.0 / (1.0 + exp(-x)) 1.0 / (1.0 + exp(-x))
} }
......
...@@ -2,8 +2,6 @@ VERBOSITY <- as.integer( ...@@ -2,8 +2,6 @@ VERBOSITY <- as.integer(
Sys.getenv("LIGHTGBM_TEST_VERBOSITY", "-1") Sys.getenv("LIGHTGBM_TEST_VERBOSITY", "-1")
) )
context("lgb.unloader")
test_that("lgb.unloader works as expected", { test_that("lgb.unloader works as expected", {
data(agaricus.train, package = "lightgbm") data(agaricus.train, package = "lightgbm")
train <- agaricus.train train <- agaricus.train
......
context(".METRICS_HIGHER_BETTER()")
test_that(".METRICS_HIGHER_BETTER() should be well formed", { test_that(".METRICS_HIGHER_BETTER() should be well formed", {
metrics <- .METRICS_HIGHER_BETTER() metrics <- .METRICS_HIGHER_BETTER()
metric_names <- names(.METRICS_HIGHER_BETTER()) metric_names <- names(.METRICS_HIGHER_BETTER())
......
context("feature penalties")
data(agaricus.train, package = "lightgbm") data(agaricus.train, package = "lightgbm")
data(agaricus.test, package = "lightgbm") data(agaricus.test, package = "lightgbm")
train <- agaricus.train train <- agaricus.train
...@@ -47,8 +44,6 @@ test_that("Feature penalties work properly", { ...@@ -47,8 +44,6 @@ test_that("Feature penalties work properly", {
expect_length(var_gain[[length(var_gain)]], 0L) expect_length(var_gain[[length(var_gain)]], 0L)
}) })
context("parameter aliases")
test_that(".PARAMETER_ALIASES() returns a named list of character vectors, where names are unique", { test_that(".PARAMETER_ALIASES() returns a named list of character vectors, where names are unique", {
param_aliases <- .PARAMETER_ALIASES() param_aliases <- .PARAMETER_ALIASES()
expect_identical(class(param_aliases), "list") expect_identical(class(param_aliases), "list")
......
context("lgb.params2str")
test_that("lgb.params2str() works as expected for empty lists", { test_that("lgb.params2str() works as expected for empty lists", {
out_str <- lgb.params2str( out_str <- lgb.params2str(
params = list() params = list()
...@@ -37,8 +35,6 @@ test_that("lgb.params2str() passes through duplicated params", { ...@@ -37,8 +35,6 @@ test_that("lgb.params2str() passes through duplicated params", {
expect_equal(out_str, "objective=regression bagging_fraction=0.8 bagging_fraction=0.5") expect_equal(out_str, "objective=regression bagging_fraction=0.8 bagging_fraction=0.5")
}) })
context("lgb.check.eval")
test_that("lgb.check.eval works as expected with no metric", { test_that("lgb.check.eval works as expected with no metric", {
params <- lgb.check.eval( params <- lgb.check.eval(
params = list(device = "cpu") params = list(device = "cpu")
...@@ -84,8 +80,6 @@ test_that("lgb.check.eval drops duplicate metrics and preserves order", { ...@@ -84,8 +80,6 @@ test_that("lgb.check.eval drops duplicate metrics and preserves order", {
expect_identical(params[["metric"]], list("l1", "l2", "rmse")) expect_identical(params[["metric"]], list("l1", "l2", "rmse"))
}) })
context("lgb.check.wrapper_param")
test_that("lgb.check.wrapper_param() uses passed-in keyword arg if no alias found in params", { test_that("lgb.check.wrapper_param() uses passed-in keyword arg if no alias found in params", {
kwarg_val <- sample(seq_len(100L), size = 1L) kwarg_val <- sample(seq_len(100L), size = 1L)
params <- lgb.check.wrapper_param( params <- lgb.check.wrapper_param(
......
...@@ -2,8 +2,6 @@ VERBOSITY <- as.integer( ...@@ -2,8 +2,6 @@ VERBOSITY <- as.integer(
Sys.getenv("LIGHTGBM_TEST_VERBOSITY", "-1") Sys.getenv("LIGHTGBM_TEST_VERBOSITY", "-1")
) )
context("Case weights are respected")
test_that("Gamma regression reacts on 'weight'", { test_that("Gamma regression reacts on 'weight'", {
n <- 100L n <- 100L
set.seed(87L) set.seed(87L)
......
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