Skip to content

Commit

Permalink
Add pass/fail badge in plot from plot_object fixture.
Browse files Browse the repository at this point in the history
  • Loading branch information
Karan Desai committed Jun 17, 2016
1 parent 18e2f37 commit 74fa0e8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 59 deletions.
3 changes: 1 addition & 2 deletions tardis/tests/tests_slow/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@ def pytest_runtest_makereport(item, call):
# execute all other hooks to obtain the report object
outcome = yield
report = outcome.get_result()

if report.when == "call":
if "plot_object" in item.fixturenames:
plot_obj = item.funcargs["plot_object"]
plot_obj.upload()
plot_obj.upload(report)
report.extra = plot_obj.get_extras()


Expand Down
11 changes: 10 additions & 1 deletion tardis/tests/tests_slow/plot_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,21 @@ def add(self, plot, name):
"""
self._plots.append((plot, name))

def upload(self):
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})
elif report.failed:
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(
Expand Down
85 changes: 29 additions & 56 deletions tardis/tests/tests_slow/test_w7.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,31 +112,25 @@ def test_luminosity_inner(self):
self.result.luminosity_inner)

def test_spectrum(self, plot_object):
try:
assert_quantity_allclose(
self.reference['luminosity_density_nu'],
self.result.runner.spectrum.luminosity_density_nu)

assert_quantity_allclose(
self.reference['delta_frequency'],
self.result.runner.spectrum.delta_frequency)

assert_quantity_allclose(
self.reference['wavelength'],
self.result.runner.spectrum.wavelength)

assert_quantity_allclose(
self.reference['luminosity_density_lambda'],
self.result.runner.spectrum.luminosity_density_lambda)
except Exception as e:
plot = self.plot_spectrum(has_passed=False)
raise e
else:
plot = self.plot_spectrum(has_passed=True)

plot_object.add(plot, "spectrum")

def plot_spectrum(self, has_passed):
assert_quantity_allclose(
self.reference['luminosity_density_nu'],
self.result.runner.spectrum.luminosity_density_nu)

assert_quantity_allclose(
self.reference['delta_frequency'],
self.result.runner.spectrum.delta_frequency)

assert_quantity_allclose(
self.reference['wavelength'],
self.result.runner.spectrum.wavelength)

assert_quantity_allclose(
self.reference['luminosity_density_lambda'],
self.result.runner.spectrum.luminosity_density_lambda)

plot_object.add(self.plot_spectrum(), "spectrum")

def plot_spectrum(self):
plt.suptitle("Deviation in spectrum_quantities", fontweight="bold")
figure = plt.figure()

Expand All @@ -151,16 +145,8 @@ def plot_spectrum(self, has_passed):
self.result.runner.spectrum.luminosity_density_lambda.value /
self.reference['luminosity_density_lambda'].value)

if has_passed:
ldl_ax.text(0.8, 0.8, 'passed', transform=ldl_ax.transAxes,
bbox={'facecolor': 'green', 'alpha': 0.5, 'pad': 10})
ldl_ax.plot(self.reference['wavelength'], deviation,
color="green", marker=".")
else:
ldl_ax.text(0.8, 0.8, 'failed', transform=ldl_ax.transAxes,
bbox={'facecolor': 'red', 'alpha': 0.5, 'pad': 10})
ldl_ax.plot(self.reference['wavelength'], deviation,
color="red", marker=".")
ldl_ax.plot(self.reference['wavelength'], deviation,
color="blue", marker=".")

return figure

Expand All @@ -178,34 +164,21 @@ def test_montecarlo_properties(self):
self.result.montecarlo_nu)

def test_shell_temperature(self, plot_object):
try:
assert_quantity_allclose(
self.reference['t_rads'],
self.result.t_rads)
except Exception as e:
plot = self.plot_t_rads(has_passed=False)
raise e
else:
plot = self.plot_t_rads(has_passed=True)

plot_object.add(plot, "t_rads")

def plot_t_rads(self, has_passed):
assert_quantity_allclose(
self.reference['t_rads'],
self.result.t_rads)

plot_object.add(self.plot_t_rads(), "t_rads")

def plot_t_rads(self):
plt.suptitle("Shell temperature for packets", fontweight="bold")
figure = plt.figure()

ax = figure.add_subplot(111)
ax.set_xlabel("Shell id")
ax.set_ylabel("t_rads")

if has_passed:
ax.text(0.8, 0.8, 'passed', transform=ax.transAxes,
bbox={'facecolor': 'green', 'alpha': 0.5, 'pad': 10})
ax.plot(self.result.t_rads, color="green", marker=".")
else:
ax.text(0.8, 0.8, 'failed', transform=ax.transAxes,
bbox={'facecolor': 'red', 'alpha': 0.5, 'pad': 10})
ax.plot(self.result.t_rads, color="red", marker=".")
ax.plot(self.result.t_rads, color="blue", marker=".")
ax.axis([0, 28, 5000, 10000])

return figure

0 comments on commit 74fa0e8

Please sign in to comment.