def test_log_mpl_image(self):
    assert (os.path.exists(get_event_path(self.run_path, kind=V1ArtifactKind.IMAGE)) is False)
    assert (os.path.exists(get_asset_path(self.run_path, kind=V1ArtifactKind.IMAGE)) is False)
    (figure, axes) = (plt.figure(), plt.gca())
    circle1 = plt.Circle((0.2, 0.5), 0.2, color='r')
    circle2 = plt.Circle((0.8, 0.5), 0.2, color='g')
    axes.add_patch(circle1)
    axes.add_patch(circle2)
    plt.axis('scaled')
    plt.tight_layout()
    with patch('polyaxon.tracking.run.Run._log_has_events') as log_mpl_image:
        self.run.log_mpl_image(name='figure', data=figure, step=1, close=False)
    assert (log_mpl_image.call_count == 1)
    assert (plt.fignum_exists(figure.number) is True)
    self.event_logger.flush()
    assert (os.path.exists(get_asset_path(self.run_path, kind=V1ArtifactKind.IMAGE)) is True)
    assert (os.path.exists(get_event_path(self.run_path, kind=V1ArtifactKind.IMAGE)) is True)
    events_file = get_event_path(self.run_path, kind=V1ArtifactKind.IMAGE, name='figure')
    assert (os.path.exists(events_file) is True)
    results = V1Events.read(kind='image', name='figure', data=events_file)
    assert (len(results.df.values) == 1)
    asset_file = get_asset_path(self.run_path, kind=V1ArtifactKind.IMAGE, name='figure', step=1, ext='png')
    assert (os.path.exists(asset_file) is True)
    with patch('polyaxon.tracking.run.Run._log_has_events') as log_dashboard:
        self.run.log_mpl_image(name='figure', data=figure, step=2)
    assert (log_dashboard.call_count == 1)
    assert (plt.fignum_exists(figure.number) is False)
    self.event_logger.flush()
    assert (os.path.exists(get_asset_path(self.run_path, kind=V1ArtifactKind.IMAGE)) is True)
    assert (os.path.exists(get_event_path(self.run_path, kind=V1ArtifactKind.IMAGE)) is True)
    events_file = get_event_path(self.run_path, kind=V1ArtifactKind.IMAGE, name='figure')
    assert (os.path.exists(events_file) is True)
    results = V1Events.read(kind='image', name='figure', data=events_file)
    assert (len(results.df.values) == 2)
    asset_file = get_asset_path(self.run_path, kind=V1ArtifactKind.IMAGE, name='figure', step=1, ext='png')
    assert (os.path.exists(asset_file) is True)
def test_log_mpl_image(self):
    assert (os.path.exists(get_event_path(self.run_path, kind=V1ArtifactKind.IMAGE)) is False)
    assert (os.path.exists(get_asset_path(self.run_path, kind=V1ArtifactKind.IMAGE)) is False)
    (figure, axes) = (plt.figure(), plt.gca())
    circle1 = plt.Circle((0.2, 0.5), 0.2, color='r')
    circle2 = plt.Circle((0.8, 0.5), 0.2, color='g')
    axes.add_patch(circle1)
    axes.add_patch(circle2)
    plt.axis('scaled')
    plt.tight_layout()
    with patch('polyaxon.tracking.run.Run._log_has_events') as log_mpl_image:
        self.run.log_mpl_image(name='figure', data=figure, step=1, close=False)
    assert (log_mpl_image.call_count == 1)
    assert (plt.fignum_exists(figure.number) is True)
    self.event_logger.flush()
    assert (os.path.exists(get_asset_path(self.run_path, kind=V1ArtifactKind.IMAGE)) is True)
    assert (os.path.exists(get_event_path(self.run_path, kind=V1ArtifactKind.IMAGE)) is True)
    events_file = get_event_path(self.run_path, kind=V1ArtifactKind.IMAGE, name='figure')
    assert (os.path.exists(events_file) is True)
    results = V1Events.read(kind='image', name='figure', data=events_file)
    assert (len(results.df.values) == 1)
    asset_file = get_asset_path(self.run_path, kind=V1ArtifactKind.IMAGE, name='figure', step=1, ext='png')
    assert (os.path.exists(asset_file) is True)
    with patch('polyaxon.tracking.run.Run._log_has_events') as log_dashboard:
        self.run.log_mpl_image(name='figure', data=figure, step=2)
    assert (log_dashboard.call_count == 1)
    assert (plt.fignum_exists(figure.number) is False)
    self.event_logger.flush()
    assert (os.path.exists(get_asset_path(self.run_path, kind=V1ArtifactKind.IMAGE)) is True)
    assert (os.path.exists(get_event_path(self.run_path, kind=V1ArtifactKind.IMAGE)) is True)
    events_file = get_event_path(self.run_path, kind=V1ArtifactKind.IMAGE, name='figure')
    assert (os.path.exists(events_file) is True)
    results = V1Events.read(kind='image', name='figure', data=events_file)
    assert (len(results.df.values) == 2)
    asset_file = get_asset_path(self.run_path, kind=V1ArtifactKind.IMAGE, name='figure', step=1, ext='png')
    assert (os.path.exists(asset_file) is True)