Skip to content

Commit

Permalink
Add fixture for base directory of saving plots.
Browse files Browse the repository at this point in the history
- Use this fixture in TestW7, by creating per-setup
  subdirectories (currently only W7, would be enhanced
  by parametrization later).

- Directories are named as per git commit hashes.
  • Loading branch information
Karan Desai committed May 24, 2016
1 parent b7dc464 commit fa303e6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
14 changes: 14 additions & 0 deletions tardis/tests/tests_slow/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import numpy as np
import pytest
from astropy import units as u
import tardis


@pytest.fixture(scope="session")
Expand All @@ -18,6 +19,19 @@ def data_path():
return os.path.join(os.path.dirname(os.path.realpath(__file__)), "w7")


@pytest.fixture(scope="session")
def base_plot_dir():
githash_short = tardis.__githash__[0:7]
base_plot_dir = os.path.join("/tmp", "plots", githash_short)

# Remove plots generated from previous runs on same githash.
if os.path.exists(base_plot_dir):
os.rmdir(base_plot_dir)

os.makedirs(base_plot_dir)
return base_plot_dir


@pytest.fixture(scope="session")
def reference(request, slow_tests_datadir):
"""
Expand Down
10 changes: 8 additions & 2 deletions tardis/tests/tests_slow/test_w7.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TestW7(object):
@classmethod
@pytest.fixture(scope="class", autouse=True)
def setup(self, request, reference, data_path, atomic_data_fname,
slow_tests_datadir):
slow_tests_datadir, base_plot_dir):
"""
This method does initial setup of creating configuration and performing
a single run of integration test.
Expand Down Expand Up @@ -58,6 +58,12 @@ def setup(self, request, reference, data_path, atomic_data_fname,
# Get the reference data through the fixture.
self.reference = reference

# Form a base directory to save plots for `W7` setup.
# TODO: Rough prototyping, parametrize this as more setups are added.
self.name = "w7"
self.base_plot_dir = os.path.join(base_plot_dir, self.name)
os.makedirs(self.base_plot_dir)

def test_j_estimators(self):
assert_allclose(
self.reference['j_estimators'],
Expand Down Expand Up @@ -152,7 +158,7 @@ def plot_spectrum(self, passed):

# Figure is saved in `tmp` directory right now, till a suitable way of
# saving them is decided.
plt.savefig(os.path.join(self.plot_savedir, "spectrum.png"))
plt.savefig(os.path.join(self.base_plot_dir, "spectrum.png"))

def test_montecarlo_properties(self):
assert_quantity_allclose(
Expand Down

0 comments on commit fa303e6

Please sign in to comment.