@pytest.mark.filterwarnings('ignore::FutureWarning')
def test_log_mpl_images(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)
    figures = []
    for i in range(5):
        figure = plt.figure()
        plt.plot([(i * 1), (i * 2), (i * 3)], label=('Plot ' + str(i)))
        plt.xlabel('X')
        plt.xlabel('Y')
        plt.legend()
        plt.tight_layout()
        figures.append(figure)
    with patch('polyaxon.tracking.run.Run._log_has_events') as log_mpl_image:
        self.run.log_mpl_image(name='figure', data=figures, step=1, close=False)
    assert (log_mpl_image.call_count == 1)
    assert all([(plt.fignum_exists(figure.number) is True) for figure in figures])
    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)
    with patch('polyaxon.tracking.run.Run._log_has_events') as log_mpl_image:
        self.run.log_mpl_image(name='figure', data=figures, step=2)
    assert (log_mpl_image.call_count == 1)
    assert all([(plt.fignum_exists(figure.number) is False) for figure in figures])
    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)
@pytest.mark.filterwarnings('ignore::FutureWarning')
def test_log_mpl_images(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)
    figures = []
    for i in range(5):
        figure = plt.figure()
        plt.plot([(i * 1), (i * 2), (i * 3)], label=('Plot ' + str(i)))
        plt.xlabel('X')
        plt.xlabel('Y')
        plt.legend()
        plt.tight_layout()
        figures.append(figure)
    with patch('polyaxon.tracking.run.Run._log_has_events') as log_mpl_image:
        self.run.log_mpl_image(name='figure', data=figures, step=1, close=False)
    assert (log_mpl_image.call_count == 1)
    assert all([(plt.fignum_exists(figure.number) is True) for figure in figures])
    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)
    with patch('polyaxon.tracking.run.Run._log_has_events') as log_mpl_image:
        self.run.log_mpl_image(name='figure', data=figures, step=2)
    assert (log_mpl_image.call_count == 1)
    assert all([(plt.fignum_exists(figure.number) is False) for figure in figures])
    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)