diff --git a/tardis/tests/tests_slow/conftest.py b/tardis/tests/tests_slow/conftest.py index 8df7bae1928..6990cc84b7d 100644 --- a/tardis/tests/tests_slow/conftest.py +++ b/tardis/tests/tests_slow/conftest.py @@ -1,15 +1,13 @@ import os -import glob import shutil import tempfile import yaml import numpy as np import pytest -from pytest_html import extras from astropy import units as u from tardis.tests.tests_slow.report import DokuReport -import tardis +from tardis.tests.tests_slow.plot_helpers import PlotUploader def pytest_configure(config): @@ -56,46 +54,11 @@ def pytest_runtest_makereport(item, call): @pytest.fixture(scope="function") def plot_object(request): - class PlotUploader(object): - def __init__(self): - self._plots = list() - self.plot_links = list() - - def add(self, plot, name): - """ - Accept a `matplotlib.pyplot.figure` and add it to self._plots. - """ - self._plots.append((plot, name)) - - def upload(self): - """ - Upload the content in self._plots to dokuwiki. - """ - dokuwiki_url = request.config.dokureport.dokuwiki_url - for plot, name in self._plots: - plot_file = tempfile.NamedTemporaryFile(suffix=".png") - plot.savefig(plot_file.name) - - request.config.dokureport.doku_conn.medias.add( - "plots:{0}_{1}.png".format(tardis.__githash__[0:7], name), - plot_file.name - ) - self.plot_links.append(extras.url( - "{0}lib/exe/fetch.php?media=plots:{1}_{2}.png".format( - dokuwiki_url, tardis.__githash__[0:7], name - ), name) - ) - plot_file.close() - - def get_extras(self): - return self.plot_links plot_obj = PlotUploader() setattr(request.node, "plot_obj", plot_obj) def fin(): - # Adding plots in this manner is temporary. - plot_obj.add() - plot_obj.upload() + plot_obj.upload(request) request.addfinalizer(fin) return plot_obj diff --git a/tardis/tests/tests_slow/plot_helpers.py b/tardis/tests/tests_slow/plot_helpers.py new file mode 100644 index 00000000000..b8e3bab1727 --- /dev/null +++ b/tardis/tests/tests_slow/plot_helpers.py @@ -0,0 +1,38 @@ +import tempfile +from pytest_html import extras +import tardis + + +class PlotUploader(object): + def __init__(self): + self._plots = list() + self.plot_links = list() + + def add(self, plot, name): + """ + Accept a `matplotlib.pyplot.figure` and add it to self._plots. + """ + self._plots.append((plot, name)) + + def upload(self, request): + """ + Upload the content in self._plots to dokuwiki. + """ + dokuwiki_url = request.config.dokureport.dokuwiki_url + for plot, name in self._plots: + plot_file = tempfile.NamedTemporaryFile(suffix=".png") + plot.savefig(plot_file.name) + + request.config.dokureport.doku_conn.medias.add( + "plots:{0}_{1}.png".format(tardis.__githash__[0:7], name), + plot_file.name + ) + self.plot_links.append(extras.url( + "{0}lib/exe/fetch.php?media=plots:{1}_{2}.png".format( + dokuwiki_url, tardis.__githash__[0:7], name + ), name) + ) + plot_file.close() + + def get_extras(self): + return self.plot_links