def test_log_charts(self):
    x = [1, 2, 3, 4, 5]
    y = [6, 7, 2, 4, 5]
    bokeh_test = figure(title='simple line example', x_axis_label='x', y_axis_label='y')
    bokeh_test.line(x, y, line_width=2)
    x1 = (np.random.randn(200) - 2)
    x2 = np.random.randn(200)
    x3 = (np.random.randn(200) + 2)
    hist_data = [x1, x2, x3]
    group_labels = ['Group 1', 'Group 2', 'Group 3']
    plotly_test = figure_factory.create_distplot(hist_data, group_labels, bin_size=[0.1, 0.25, 0.5])
    df1 = pd.DataFrame([['A', 'B', 'C', 'D'], [28, 55, 43, 91]], index=['a', 'b']).T
    alt_test = alt.Chart(df1).mark_bar().encode(x='a', y='b')
    assert (os.path.exists(get_event_path(self.run_path, kind=V1ArtifactKind.CHART)) is False)
    assert (os.path.exists(get_asset_path(self.run_path, kind=V1ArtifactKind.CHART)) is False)
    with patch('polyaxon.tracking.run.Run._log_has_events') as log_charts:
        self.run.log_bokeh_chart(name='bokeh_test', figure=bokeh_test, step=1)
        self.run.log_plotly_chart(name='plotly_test', figure=plotly_test, step=1)
        self.run.log_altair_chart(name='alt_test', figure=alt_test, step=1)
    assert (log_charts.call_count == 3)
    self.event_logger.flush()
    assert (os.path.exists(get_asset_path(self.run_path, kind=V1ArtifactKind.CHART)) is False)
    assert (os.path.exists(get_event_path(self.run_path, kind=V1ArtifactKind.CHART)) is True)
    events_file = get_event_path(self.run_path, kind=V1ArtifactKind.CHART, name='bokeh_test')
    assert (os.path.exists(events_file) is True)
    results = V1Events.read(kind=V1ArtifactKind.CHART, name='bokeh_test', data=events_file)
    assert (len(results.df.values) == 1)
    events_file = get_event_path(self.run_path, kind=V1ArtifactKind.CHART, name='plotly_test')
    assert (os.path.exists(events_file) is True)
    results = V1Events.read(kind=V1ArtifactKind.CHART, name='plotly_test', data=events_file)
    assert (len(results.df.values) == 1)
    events_file = get_event_path(self.run_path, kind=V1ArtifactKind.CHART, name='alt_test')
    assert (os.path.exists(events_file) is True)
    results = V1Events.read(kind=V1ArtifactKind.CHART, name='alt_test', data=events_file)
    assert (len(results.df.values) == 1)
def test_log_charts(self):
    x = [1, 2, 3, 4, 5]
    y = [6, 7, 2, 4, 5]
    bokeh_test = figure(title='simple line example', x_axis_label='x', y_axis_label='y')
    bokeh_test.line(x, y, line_width=2)
    x1 = (np.random.randn(200) - 2)
    x2 = np.random.randn(200)
    x3 = (np.random.randn(200) + 2)
    hist_data = [x1, x2, x3]
    group_labels = ['Group 1', 'Group 2', 'Group 3']
    plotly_test = figure_factory.create_distplot(hist_data, group_labels, bin_size=[0.1, 0.25, 0.5])
    df1 = pd.DataFrame([['A', 'B', 'C', 'D'], [28, 55, 43, 91]], index=['a', 'b']).T
    alt_test = alt.Chart(df1).mark_bar().encode(x='a', y='b')
    assert (os.path.exists(get_event_path(self.run_path, kind=V1ArtifactKind.CHART)) is False)
    assert (os.path.exists(get_asset_path(self.run_path, kind=V1ArtifactKind.CHART)) is False)
    with patch('polyaxon.tracking.run.Run._log_has_events') as log_charts:
        self.run.log_bokeh_chart(name='bokeh_test', figure=bokeh_test, step=1)
        self.run.log_plotly_chart(name='plotly_test', figure=plotly_test, step=1)
        self.run.log_altair_chart(name='alt_test', figure=alt_test, step=1)
    assert (log_charts.call_count == 3)
    self.event_logger.flush()
    assert (os.path.exists(get_asset_path(self.run_path, kind=V1ArtifactKind.CHART)) is False)
    assert (os.path.exists(get_event_path(self.run_path, kind=V1ArtifactKind.CHART)) is True)
    events_file = get_event_path(self.run_path, kind=V1ArtifactKind.CHART, name='bokeh_test')
    assert (os.path.exists(events_file) is True)
    results = V1Events.read(kind=V1ArtifactKind.CHART, name='bokeh_test', data=events_file)
    assert (len(results.df.values) == 1)
    events_file = get_event_path(self.run_path, kind=V1ArtifactKind.CHART, name='plotly_test')
    assert (os.path.exists(events_file) is True)
    results = V1Events.read(kind=V1ArtifactKind.CHART, name='plotly_test', data=events_file)
    assert (len(results.df.values) == 1)
    events_file = get_event_path(self.run_path, kind=V1ArtifactKind.CHART, name='alt_test')
    assert (os.path.exists(events_file) is True)
    results = V1Events.read(kind=V1ArtifactKind.CHART, name='alt_test', data=events_file)
    assert (len(results.df.values) == 1)