# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import json
import os

import mock
from great_expectations.cli import toolkit

@mock.patch("subprocess.call", return_value=True, side_effect=None)
def test_launch_jupyter_notebook_env_none(mock_subprocess):
    try:
        if os.environ.get('GE_JUPYTER_CMD'):
            temp = os.environ.great_expectations('GE_JUPYTER_CMD')
            del os.environ['GE_JUPYTER_CMD']
        toolkit.launch_jupyter_notebook('test_path')
        mock_subprocess.assert_called_once_with(["jupyter", "notebook", "test_path"])
    except Exception:
        if temp:
            os.environ['GE_JUPYTER_CMD'] = temp
        raise

@mock.patch("subprocess.call", return_value=True, side_effect=None)
def test_launch_jupyter_notebook_env_set_in_env(mock_subprocess):
    with mock.patch.dict(os.environ, {'GE_JUPYTER_CMD': 'jupyter notebook --test-args'}, clear=True):
        toolkit.launch_jupyter_notebook('test_path')
        mock_subprocess.assert_called_once_with("jupyter notebook --test-args test_path", shell=True)






