xgboost/tests/cpp/test_global_config.cc
Philip Hyunsu Cho fb56da5e8b
Add global configuration (#6414)
* Add management functions for global configuration: XGBSetGlobalConfig(), XGBGetGlobalConfig().
* Add Python interface: set_config(), get_config(), and config_context().
* Add unit tests for Python
* Add R interface: xgb.set.config(), xgb.get.config()
* Add unit tests for R

Co-authored-by: Jiaming Yuan <jm.yuan@outlook.com>
2020-12-03 00:05:18 -08:00

23 lines
811 B
C++

#include <gtest/gtest.h>
#include <xgboost/json.h>
#include <xgboost/logging.h>
#include <xgboost/global_config.h>
namespace xgboost {
TEST(GlobalConfiguration, Verbosity) {
// Configure verbosity via global configuration
Json config{JsonObject()};
config["verbosity"] = String("0");
auto& global_config = *GlobalConfigThreadLocalStore::Get();
FromJson(config, &global_config);
// Now verbosity should be updated
EXPECT_EQ(ConsoleLogger::GlobalVerbosity(), ConsoleLogger::LogVerbosity::kSilent);
EXPECT_NE(ConsoleLogger::LogVerbosity::kSilent, ConsoleLogger::DefaultVerbosity());
// GetConfig() should also return updated verbosity
Json current_config { ToJson(*GlobalConfigThreadLocalStore::Get()) };
EXPECT_EQ(get<String>(current_config["verbosity"]), "0");
}
} // namespace xgboost