From 3d0606e9d796364bb64232966e487d8926a4ff4f Mon Sep 17 00:00:00 2001 From: Haoming Chen Date: Wed, 9 Mar 2022 11:30:37 -0800 Subject: [PATCH] Run tests in a temporary directory Fix some tests to run in a temporary directory in case the root directory is not writable. Note that most of tests are already running in the temporary directory, so this PR just make them consistent. --- tests/cpp/data/test_simple_dmatrix.cc | 3 ++- tests/cpp/data/test_sparse_page_dmatrix.cc | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/cpp/data/test_simple_dmatrix.cc b/tests/cpp/data/test_simple_dmatrix.cc index 60bb181cc8a3..e709605c9c6d 100644 --- a/tests/cpp/data/test_simple_dmatrix.cc +++ b/tests/cpp/data/test_simple_dmatrix.cc @@ -194,7 +194,8 @@ TEST(SimpleDMatrix, FromCSC) { } TEST(SimpleDMatrix, FromFile) { - std::string filename = "test.libsvm"; + dmlc::TemporaryDirectory tempdir; + std::string filename = tempdir.path + "test.libsvm"; CreateBigTestData(filename, 3 * 5); // Add an empty row at the end of the matrix { diff --git a/tests/cpp/data/test_sparse_page_dmatrix.cc b/tests/cpp/data/test_sparse_page_dmatrix.cc index 2cdef6641635..b5ed00fb4f8a 100644 --- a/tests/cpp/data/test_sparse_page_dmatrix.cc +++ b/tests/cpp/data/test_sparse_page_dmatrix.cc @@ -26,7 +26,7 @@ void TestSparseDMatrixLoadFile() { data::fileiter::Next, std::numeric_limits::quiet_NaN(), 1, - "cache"}; + tmpdir.path + "cache"}; ASSERT_EQ(m.Info().num_col_, 5); ASSERT_EQ(m.Info().num_row_, 64);