From e227abc57a30a27ea2a91b3ae80c3d26d4d6b7f0 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Sun, 15 Jan 2023 09:34:54 -0600 Subject: [PATCH] [R] avoid leaving test files behind (#8685) --- .gitignore | 6 ++++++ R-package/tests/testthat/test_dmatrix.R | 2 +- R-package/tests/testthat/test_model_compatibility.R | 7 ++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index f6ab297e0..3a606c847 100644 --- a/.gitignore +++ b/.gitignore @@ -143,3 +143,9 @@ demo/**/*.txt .hypothesis __MACOSX/ model*.json + +# R tests +*.libsvm +*.rds +Rplots.pdf +*.zip diff --git a/R-package/tests/testthat/test_dmatrix.R b/R-package/tests/testthat/test_dmatrix.R index da1180f5e..b27ba302b 100644 --- a/R-package/tests/testthat/test_dmatrix.R +++ b/R-package/tests/testthat/test_dmatrix.R @@ -70,7 +70,7 @@ test_that("xgb.DMatrix: saving, loading", { # from a libsvm text file tmp <- c("0 1:1 2:1", "1 3:1", "0 1:1") - tmp_file <- 'tmp.libsvm' + tmp_file <- tempfile(fileext = ".libsvm") writeLines(tmp, tmp_file) dtest4 <- xgb.DMatrix(tmp_file, silent = TRUE) expect_equal(dim(dtest4), c(3, 4)) diff --git a/R-package/tests/testthat/test_model_compatibility.R b/R-package/tests/testthat/test_model_compatibility.R index cb8c432fa..a52e08f76 100644 --- a/R-package/tests/testthat/test_model_compatibility.R +++ b/R-package/tests/testthat/test_model_compatibility.R @@ -59,11 +59,12 @@ test_that("Models from previous versions of XGBoost can be loaded", { bucket <- 'xgboost-ci-jenkins-artifacts' region <- 'us-west-2' file_name <- 'xgboost_r_model_compatibility_test.zip' - zipfile <- file.path(getwd(), file_name) - model_dir <- file.path(getwd(), 'models') + zipfile <- tempfile(fileext = ".zip") + extract_dir <- tempdir() download.file(paste('https://', bucket, '.s3-', region, '.amazonaws.com/', file_name, sep = ''), destfile = zipfile, mode = 'wb', quiet = TRUE) - unzip(zipfile, overwrite = TRUE) + unzip(zipfile, exdir = extract_dir, overwrite = TRUE) + model_dir <- file.path(extract_dir, 'models') pred_data <- xgb.DMatrix(matrix(c(0, 0, 0, 0), nrow = 1, ncol = 4))