-
-
Notifications
You must be signed in to change notification settings - Fork 419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Link images of comparison plots in DokuReport using hookwrapper. #590
Changes from 9 commits
c4b2889
362bca0
c276de0
d4576a0
2b497a1
18e2f37
fbe8568
1430e41
e428796
027d8d1
8646bfe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import tempfile | ||
|
||
from pytest_html import extras | ||
import tardis | ||
|
||
|
||
class PlotUploader(object): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd add an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
def __init__(self, request): | ||
self.request = request | ||
self._plots = 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you please do |
||
""" | ||
self._plots.append((plot, name)) | ||
|
||
def upload(self, report): | ||
""" | ||
Upload the content in self._plots to dokuwiki. | ||
""" | ||
for plot, name in self._plots: | ||
plot_file = tempfile.NamedTemporaryFile(suffix=".png") | ||
axes = plot.axes[0] | ||
|
||
if report.passed: | ||
axes.text(0.8, 0.8, 'passed', transform=axes.transAxes, | ||
bbox={'facecolor': 'green', 'alpha': 0.5, 'pad': 10}) | ||
else: | ||
axes.text(0.8, 0.8, 'failed', transform=axes.transAxes, | ||
bbox={'facecolor': 'red', 'alpha': 0.5, 'pad': 10}) | ||
|
||
plot.savefig(plot_file.name) | ||
|
||
self.request.config.dokureport.doku_conn.medias.add( | ||
"plots:{0}_{1}.png".format(tardis.__githash__[0:7], name), | ||
plot_file.name | ||
) | ||
|
||
thumbnail_html = """ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you define this HTML snippet as a constant at the top? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✅ Done. |
||
<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_html |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,6 +144,11 @@ def _generate_report(self, session): | |
) | ||
) | ||
report_content += doc.unicode(indent=2) | ||
|
||
# Quick hack for preventing log to be placed in narrow left out space | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As this line only affects the result part of the whole log I'd move it so it only works on |
||
report_content = report_content.replace( | ||
u'class="log"', u'class="log" style="clear: both"' | ||
) | ||
return report_content | ||
|
||
def _save_report(self, report_content): | ||
|
@@ -186,7 +191,6 @@ def pytest_terminal_summary(self, terminalreporter): | |
self.dokuwiki_url, tardis.__githash__[0:7] | ||
) | ||
) | ||
|
||
else: | ||
terminalreporter.write_sep( | ||
"-", "Connection not established, upload failed.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wo don't need this line anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yeganer I'm further simplifying to:
... in the next commit