
import os
import os.path
import shutil
from mlflow import cli
from mlflow.utils import process
from mlflow.utils.file_utils import path_to_local_file_uri
from tests.integration.utils import invoke_cli_runner
import pytest

EXAMPLES_DIR = 'examples'


@pytest.mark.large
@pytest.mark.parametrize("directory, params", [
    ('h2o', []),
    ('hyperparam', ['-e', 'train']),
    ('hyperparam', ['-e', 'random']),
    ('hyperparam', ['-e', 'gpyopt']),
    ('hyperparam', ['-e', 'hyperopt', '-P', 'epochs=1']),
    ('lightgbm', ['-P', 'colsample-bytree=0.8', '-P', 'subsample=0.9']),
    ('prophet', []),
    ('pytorch', ['-P', 'epochs=2']),
    ('sklearn_logistic_regression', []),
    ('sklearn_elasticnet_wine', ['-P', 'alpha=0.5']),
    (os.path.join('sklearn_elasticnet_diabetes', 'linux'), []),
    (os.path.join('tensorflow', 'tf1'), ['-P', 'steps=10']),
    ('xgboost', ['-P', 'colsample-bytree=0.8', '-P', 'subsample=0.9'])
])
def test_mlflow_run_example(directory, params):
    cli_run_list = [os.path.join(EXAMPLES_DIR, directory)] + params
    invoke_cli_runner(cli.run, cli_run_list)


@pytest.mark.large
@pytest.mark.parametrize("directory, command", [
    ('docker', ['docker', 'build', '-t', 'mlflow-docker-example', '-f', 'Dockerfile', '.']),
    ('gluon', ['python', 'train.py']),
    ('keras', ['python', 'train.py']),
    ('lightgbm', ['python', 'train.py', '--colsample-bytree', '0.8', '--subsample', '0.9']),
    ('quickstart', ['python', 'mlflow_tracking.py']),
    ('remote_store', ['python', 'remote_server.py']),
    ('xgboost', ['python', 'train.py', '--colsample-bytree', '0.8', '--subsample', '0.9'])
])
def test_command_example(tmpdir, directory, command):
    os.environ['MLFLOW_TRACKING_URI'] = path_to_local_file_uri(str(tmpdir.join("mlruns")))
    cwd_dir = os.path.join(EXAMPLES_DIR, directory)

    try:
        process.exec_cmd(command,
                         cwd=cwd_dir)
    finally:
        shutil.rmtree(str(tmpdir))
        del os.environ['MLFLOW_TRACKING_URI']

@@ -1651,16 +1651,8 @@
 ple(
-tmpdir, 
 dire
@@ -1672,99 +1672,8 @@
 d):%0A
-    os.environ%5B'MLFLOW_TRACKING_URI'%5D = path_to_local_file_uri(str(tmpdir.join(%22mlruns%22)))%0A
     
@@ -1724,22 +1724,8 @@
 ry)%0A
-%0A    try:%0A    
     
@@ -1771,20 +1771,16 @@
         
-    
 cwd=cwd_
@@ -1788,98 +1788,4 @@
 ir)%0A
-    finally:%0A        shutil.rmtree(str(tmpdir))%0A        del os.environ%5B'MLFLOW_TRACKING_URI'%5D%0A

Fix examples test