-
-
Notifications
You must be signed in to change notification settings - Fork 419
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Embed plot thumbnails in report through extras.html
- Loading branch information
Karan Desai
committed
Jun 17, 2016
1 parent
2b497a1
commit 18e2f37
Showing
2 changed files
with
22 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,45 @@ | ||
import tempfile | ||
|
||
from pytest_html import extras | ||
import tardis | ||
|
||
|
||
class PlotUploader(object): | ||
def __init__(self): | ||
def __init__(self, request): | ||
self.request = request | ||
self._plots = list() | ||
self.plot_links = list() | ||
self.plot_html = list() | ||
self.dokuwiki_url = self.request.config.dokureport.dokuwiki_url | ||
|
||
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): | ||
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( | ||
self.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) | ||
) | ||
|
||
thumbnail_html = """ | ||
<div class="image" style="float: left"> | ||
<a href="#"> | ||
<img src= "{0}lib/exe/fetch.php?media=plots:{1}_{2}.png" /> | ||
</a> | ||
</div> | ||
""".format(self.dokuwiki_url, tardis.__githash__[0:7], name) | ||
|
||
self.plot_html.append(extras.html(thumbnail_html)) | ||
plot_file.close() | ||
|
||
def get_extras(self): | ||
return self.plot_links | ||
return self.plot_html |