def test_ipython_notebook_funcs(): from dtale.views import DtaleData getter = namedtuple('get', 'ok') def mock_requests_get(url, verify=True): return getter(True) df = pd.DataFrame([1, 2, 3]) with ExitStack() as stack: mock_iframe = stack.enter_context( mock.patch('IPython.display.IFrame', mock.Mock())) stack.enter_context(mock.patch('requests.get', mock_requests_get)) stack.enter_context( mock.patch('dtale.views.in_ipython_frontend', return_value=True)) stack.enter_context( mock.patch('dtale.global_state.DATA', return_value={9999: df})) instance = DtaleData(9999, 'http://localhost:9999') instance.notebook_correlations(col1='col1', col2='col2') mock_iframe.assert_called_once() url_parser = get_url_parser() [path, query] = mock_iframe.call_args[0][0].split('?') assert path == 'http://localhost:9999/dtale/popup/correlations/9999' assert dict(url_parser(query)) == dict(col1='col1', col2='col2') instance.notebook_charts(x='col1', y='col2', group=['col3', 'col4'], agg='count') [path, query] = mock_iframe.call_args[0][0].split('?') assert path == 'http://localhost:9999/charts/9999' assert dict(url_parser(query)) == dict(chart_type='line', agg='count', group='["col3", "col4"]', x='col1', y='["col2"]', cpg='false') instance.notebook_charts(x='col1', y='col2', agg='count') [_path, query] = mock_iframe.call_args[0][0].split('?') assert dict(url_parser(query)) == dict(chart_type='line', agg='count', x='col1', y='["col2"]', cpg='false') instance.notebook_charts(x='col1', y='col2', group=['col3', 'col4']) [_path, query] = mock_iframe.call_args[0][0].split('?') assert dict(url_parser(query)) == dict(chart_type='line', x='col1', y='["col2"]', group='["col3", "col4"]', cpg='false')
def test_ipython_notebook_funcs(): from dtale.views import DtaleData getter = namedtuple('get', 'ok') def mock_requests_get(url, verify=True): return getter(True) df = pd.DataFrame([1, 2, 3]) with ExitStack() as stack: mock_iframe = stack.enter_context( mock.patch('IPython.display.IFrame', mock.Mock())) stack.enter_context(mock.patch('requests.get', mock_requests_get)) stack.enter_context( mock.patch('dtale.views.in_ipython_frontend', return_value=True)) stack.enter_context( mock.patch('dtale.views.DATA', return_value={9999: df})) instance = DtaleData(9999, 'http://localhost:9999') instance.notebook_correlations(col1='col1', col2='col2') mock_iframe.assert_called_once() assert mock_iframe.call_args[0][ 0] == 'http://localhost:9999/dtale/popup/correlations/9999?col1=col1&col2=col2' instance.notebook_charts('col1', 'col2', group=['col3', 'col4'], aggregation='count') charts_url = 'http://localhost:9999/dtale/popup/charts/9999?aggregation=count&group=col3,col4&x=col1&y=col2' assert mock_iframe.call_args[0][0] == charts_url instance.notebook_charts('col1', 'col2', aggregation='count') charts_url = 'http://localhost:9999/dtale/popup/charts/9999?aggregation=count&x=col1&y=col2' assert mock_iframe.call_args[0][0] == charts_url instance.notebook_charts('col1', 'col2', group=['col3', 'col4']) charts_url = 'http://localhost:9999/dtale/popup/charts/9999?group=col3,col4&x=col1&y=col2' assert mock_iframe.call_args[0][0] == charts_url
def test_ipython_notebook_funcs(): from dtale.views import DtaleData getter = namedtuple("get", "ok") def mock_requests_get(url, verify=True): return getter(True) df = pd.DataFrame([1, 2, 3]) with ExitStack() as stack: mock_iframe = stack.enter_context( mock.patch("IPython.display.IFrame", mock.Mock())) stack.enter_context(mock.patch("requests.get", mock_requests_get)) stack.enter_context( mock.patch("dtale.views.in_ipython_frontend", return_value=True)) stack.enter_context( mock.patch("dtale.global_state.DATA", return_value={9999: df})) instance = DtaleData(9999, "http://localhost:9999") instance.notebook_correlations(col1="col1", col2="col2") mock_iframe.assert_called_once() url_parser = get_url_parser() [path, query] = mock_iframe.call_args[0][0].split("?") assert path == "http://localhost:9999/dtale/popup/correlations/9999" assert dict(url_parser(query)) == dict(col1="col1", col2="col2") instance.notebook_charts(x="col1", y="col2", group=["col3", "col4"], agg="count") [path, query] = mock_iframe.call_args[0][0].split("?") assert path == "http://localhost:9999/charts/9999" assert dict(url_parser(query)) == dict( chart_type="line", agg="count", group='["col3", "col4"]', x="col1", y='["col2"]', cpg="false", animate="false", ) instance.notebook_charts(x="col1", y="col2", agg="count") [_path, query] = mock_iframe.call_args[0][0].split("?") assert dict(url_parser(query)) == dict( chart_type="line", agg="count", x="col1", y='["col2"]', cpg="false", animate="false", ) instance.notebook_charts(x="col1", y="col2", group=["col3", "col4"]) [_path, query] = mock_iframe.call_args[0][0].split("?") assert dict(url_parser(query)) == dict( chart_type="line", x="col1", y='["col2"]', group='["col3", "col4"]', cpg="false", animate="false", )