Group CLI demo into subdirectory. (#6258)
CLI is not most developed interface. Putting them into correct directory can help new users to avoid it as most of the use cases are from a language binding.
This commit is contained in:
@@ -2,11 +2,13 @@ import os
|
||||
import subprocess
|
||||
import pytest
|
||||
import testing as tm
|
||||
import sys
|
||||
|
||||
|
||||
ROOT_DIR = tm.PROJECT_ROOT
|
||||
DEMO_DIR = os.path.join(ROOT_DIR, 'demo')
|
||||
PYTHON_DEMO_DIR = os.path.join(DEMO_DIR, 'guide-python')
|
||||
CLI_DEMO_DIR = os.path.join(DEMO_DIR, 'CLI')
|
||||
|
||||
|
||||
def test_basic_walkthrough():
|
||||
@@ -132,7 +134,7 @@ def test_callbacks_demo():
|
||||
|
||||
|
||||
def test_cli_regression_demo():
|
||||
reg_dir = os.path.join(DEMO_DIR, 'regression')
|
||||
reg_dir = os.path.join(CLI_DEMO_DIR, 'regression')
|
||||
script = os.path.join(reg_dir, 'mapfeat.py')
|
||||
cmd = ['python', script]
|
||||
subprocess.check_call(cmd, cwd=reg_dir)
|
||||
@@ -144,3 +146,15 @@ def test_cli_regression_demo():
|
||||
exe = os.path.join(tm.PROJECT_ROOT, 'xgboost')
|
||||
conf = os.path.join(reg_dir, 'machine.conf')
|
||||
subprocess.check_call([exe, conf], cwd=reg_dir)
|
||||
|
||||
|
||||
@pytest.mark.skipif(condition=sys.platform.startswith("win"),
|
||||
reason='Test requires sh execution.')
|
||||
def test_cli_binary_classification():
|
||||
cls_dir = os.path.join(CLI_DEMO_DIR, 'binary_classification')
|
||||
with tm.DirectoryExcursion(cls_dir, cleanup=True):
|
||||
subprocess.check_call(['./runexp.sh'])
|
||||
os.remove('0002.model')
|
||||
|
||||
# year prediction is not tested due to data size being too large.
|
||||
# rank is not tested as it requires unrar command.
|
||||
|
||||
@@ -251,6 +251,36 @@ def eval_error_metric(predt, dtrain: xgb.DMatrix):
|
||||
return 'CustomErr', np.sum(r)
|
||||
|
||||
|
||||
class DirectoryExcursion:
|
||||
def __init__(self, path: os.PathLike, cleanup=False):
|
||||
'''Change directory. Change back and optionally cleaning up the directory when exit.
|
||||
|
||||
'''
|
||||
self.path = path
|
||||
self.curdir = os.path.normpath(os.path.abspath(os.path.curdir))
|
||||
self.cleanup = cleanup
|
||||
self.files = {}
|
||||
|
||||
def __enter__(self):
|
||||
os.chdir(self.path)
|
||||
if self.cleanup:
|
||||
self.files = {
|
||||
os.path.join(root, f)
|
||||
for root, subdir, files in os.walk(self.path) for f in files
|
||||
}
|
||||
|
||||
def __exit__(self, *args):
|
||||
os.chdir(self.curdir)
|
||||
if self.cleanup:
|
||||
files = {
|
||||
os.path.join(root, f)
|
||||
for root, subdir, files in os.walk(self.path) for f in files
|
||||
}
|
||||
diff = files.difference(self.files)
|
||||
for f in diff:
|
||||
os.remove(f)
|
||||
|
||||
|
||||
CURDIR = os.path.normpath(os.path.abspath(os.path.dirname(__file__)))
|
||||
PROJECT_ROOT = os.path.normpath(
|
||||
os.path.join(CURDIR, os.path.pardir, os.path.pardir))
|
||||
|
||||
Reference in New Issue
Block a user